reddit / emacs

Weekly Tips, Tricks, &c. Thread

AutoModerator · 2022-10-26 08:15
This is a thread for smaller, miscellaneous items that might not warrant a full post on their own. [See this search for previous "Weekly Tips, Tricks, &c." Threads.](https://www.reddit.com/r/emacs/search?q=Weekly+tips&restrict_sr=on&sort=new&t=all) Don't feel constrained in regards to what you post, just keep your post vaguely, generally on the topic of emacs.
pedzsanReddit · 2022-10-26 19:28
I spent the past week cleaning up my Emacs init files and I bumped into this little gem. I call it "ZSH man page search mode" because it was the place that I first needed it. I do `M-x man zshall(1)` fairly frequently (and don't forget to `widen` so you can see all of the pages). Then I would start searching for what I was looking for. The man page is nicely structured so if I wanted to find "foo", search for "foo" had too many hits. What I wanted to find was the place where "foo" is described. This little search does the trick. It is probably useful for other man pages and perhaps even other places but for now... I call it "ZSH man page search" Enjoy! ```lisp (defun zsh-manpage-search-regexp (string &optional lax) "Returns a string to search for entries in the zshall man page" (format "\n[A-Z ]*\n \\{7\\}%s%s" string (if lax "" "\\_>"))) (isearch-define-mode-toggle zsh-manpage "z" zsh-manpage-search-regexp "\ Searching zshall man page for where a concept is described") ```
meedstrom · 2022-10-26 21:10
I had the [defrepeater](https://github.com/alphapapa/defrepeater.el) package for a while, but didn't realize you could use it this elegantly! (global-set-key [remap transpose-lines] (defrepeater #'transpose-lines)) Something similar is actually in the readme, but I guess I glossed over it back then.
tryptych · 2022-10-26 23:35
I recently switched from Selectrum to Vertico (prompted by a deprecation warning from Consult). Before *that* I was using Helm, where I became used to the 50% window height behaviour. I could emulate that in Selectrum by ```lisp (setq selectrum-max-window-height nil max-mini-window-height 0.5) ``` however Vertico only uses `vertico-count`. I work around this by hooking into the window-resize (I thought there was a frame-resize, but I couldn't find it) and calculating it on the fly: ```lisp (defun frame-resized-set-vertico-height (frame) (if (framep frame) (setq vertico-count (floor (/ (frame-total-lines frame) 2))))) (add-hook 'window-size-change-functions #'frame-resized-set-vertico-height) ```
dakra · 2022-10-27 22:06
jfyi, if you use Emacs 28 or newer there is now `repeat-mode` built-in which does something similar. There was a blog post here on reddit about it: https://karthinks.com/software/it-bears-repeating/
__rompy · 2022-10-28 07:54
lsp with tramp mode in docker/podman containers doesn't work so well. There is a PR but it's 1 year old and the solution there still doesn't work on my machine. This was frustrating because in eglot it just worked. So I spent a few time to see what exactly is wrong and found this solution which works. I just took the `lsp-tramp-connection` from the PR and added the `stty raw > /dev/null;` (that eglot does too). Without it the 1 jsonrpc command will arrive as 3 separated reads. `strace -p $(pidof clangd))` will show multiple read for 1 command, eg: `read(...) => Content-Length: 1313\r\n` + `read(...) => \r\n` + `read(...) => actual json`. (defun lsp-tramp-connection (local-command &optional generate-error-file-fn) (list :connect (lambda (filter sentinel name environment-fn) (let* ((final-command (list "sh" "-c" (string-join (append (cons "stty raw > /dev/null;" (lsp-resolve-final-function local-command)) (list (concat "2>" (or (when generate-error-file-fn (funcall generate-error-file-fn "name")) (format "/tmp/%s-%s-stderr" "name" (cl-incf lsp--stderr-index)))))) " "))) (process-name (generate-new-buffer-name name)) ;; (stderr-buf (stderr-buf (format "*%s::stderr*" process-name))) (process-environment (lsp--compute-process-environment environment-fn)) (proc (make-process :name process-name :buffer (format "*%s*" process-name) :command (lsp-resolve-final-function final-command) :connection-type 'pipe :coding 'utf-8-emacs-unix :noquery t :filter filter :sentinel sentinel :file-handler t))) (cons proc proc))) :test? (lambda () (-> local-command lsp-resolve-final-function lsp-server-present?)))) (lsp-register-client (make-lsp-client :new-connection (lsp-tramp-connection "clangd") :major-modes '(c-mode c++-mode) :remote? t :server-id 'clangd-remote))) I'll still stay with eglot since it satisfies all my needs, but it's good to have an alternative in case sometime goes wrong.
meedstrom · 2022-10-29 00:09
Aye, but defrepeater's niche is for single commands only -- essentially for people who won't remember the `repeat` command or haven't found a good key for it.
donio · 2022-10-29 02:08
The zsh manual is also available in the info format. This has the advantage of more granular sections with a TOC and navigation and an index. For example `m Parameter Expansion RET` or `i array assignment RET` (with the help of your favorite completion style to reduce typing).
pedzsanReddit · 2022-10-29 14:12
I need to use info more. Reading Stack Exchange problems and answers I learned about `elisp-index-search` and there is also `emacs-index-search`. I use helm... with a bit of work, these as well as a `zsh-index-search` could be hooked up and by sure convenient. Sounds like a worthy weekend project.
nullmove · 2022-10-30 20:09
This was added to `etc/NEWS` earlier today: ** The implementation of overlays has changed. Emacs now uses an implementation of overlays that is much more efficient than the original one, and should speed up all the operations that involve overlays, especially when there are lots of them in a buffer. However, no changes in behavior of overlays should be visible on the Lisp or user level, with the exception of better performance. That sounds amazing. Looks like a huge work too: https://github.com/emacs-mirror/emacs/commit/71589b101ccbec67fa2741856ee0add5752dea72