reddit / emacs

Weekly Tips, Tricks, &c. Thread

AutoModerator · 2022-06-08 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.
E3D3redit · 2022-06-08 11:54
Interface for easy switching between (only) open Org mode buffers: `M-x org-switchb`
00-11 · 2022-06-08 21:36
**Dired snapshots: saving and restoring Dired listings --** Suppose you use a command such as `find-name-dired`, to generate a Dired buffer that lists files from various places. The search part of that operation might take a long time. And suppose you later want to get back to such a listing, even if that buffer no longer exists. In particular, maybe you want to get to it in another Emacs session. And suppose you don't want to pay the penalty of performing the `find` search again, and you're content with the set of file names found by the original search. That is, you don't care whether that set of names is still 100% up-to-date. In such a context you want, in effect, to create a Dired buffer snapshot of some sort -- you want to record the set of names that your search found, and later use them again in Dired. Library [Dired+](https://www.emacswiki.org/emacs/DiredPlus) gives you two ways to do this. Both involve first creating a Dired buffer that's produced from an *explicit set of file names* -- from anywhere, rather than one that's produced using `ls` or similar, and then saving those names for re-creating a Dired buffer later. 1. Use `C-M-*` (`diredp-marked-other-window') or `diredp-marked', to create a snapshot Dired buffer. Then bookmark that buffer. Just jump to the bookmark to restore the snapshot buffer. 2. Use command `diredp-define-snapshot-dired-commands`, to create two commands (for same-window and other-window) that will create a snapshot Dired buffer. Save the `defun`s of those commands to your init file, for persistent access. The saved set of files, whether embedded in a bookmark or in a special Dired command, is a *snapshot* of the files available at a particular time. When you later use Dired with that explicit set of file names, only those files are listed -- if a name no longer corresponds to an existing file then it's ignored. The resulting Dired buffer represents the current state of the file system, but only as far as the files it lists are concerned. I think the first approach is generally preferable, but you might prefer the second. If you use approach #1 then you also need library [Bookmark+](https://www.emacswiki.org/emacs/BookmarkPlus). (If you bookmark a Dired buffer without using Bookmark+ then the bookmark records only the Dired directory name. It doesn't record the snapshot information -- the explicit list of files to be restored. It also doesn't record the `ls` switches or which files were marked in the bookmarked snapshot listing, so you can't restore them.) Both approaches, #1 and #2, use the *marked* files and dirs as the set to snapshot. (More precisely, they use the Dired+ version of function `dired-get-marked-files`. That means you can use a prefix arg to get a different set of files to snapshot, instead of those that are explicitly marked. For example, prefix arg `C-u C-u C-u` ignores markings and gives you all of the listed files and dirs.) Note too that it's the full content of the original Dired buffer that's used to define the files to snapshot. In particular, inserted subdir listings are included. ---- Cf. https://emacs.stackexchange.com/q/71830/105
natarey · 2022-06-08 22:49
Question for anyone who's familiar with Doom -- I'm using `mu4e` for mail. On my old hand-rolled config, switching contexts reverted the buffer to show the new context's information as expected. On Doom, when I switch contexts, the previous context's information is still displayed (The Maildirs shortcuts, message counts, etc.). If I call `revert-buffer` manually, it updates to the new context. It'd be nice to get it to revert automatically after switching contexts, buuuuuut yeah. I'm using out-of-the-box Doom, and I'm not sure what I've done wrong. [**Edit:** More stuff I've tried: Adding `revert-buffer` to `mu4e-context-changed-hook`prevents `mu4e` from loading correctly, throwing an error complaining that the buffer doesn't exist. If I run `mu4e`, create the hook, and then switch contexts, it works as expected. Adding a `revert-buffer` advice to `mu4e~context-ask-user` updates the Maildirs shortcuts, but does *not* display the message counts. If I then revert the buffer manually, it shows the message counts. If I try to advise `mu4e~context-ask-user` to run `revert-buffer` twice, it still doesn't show the message counts. Even adding a `sit-for` doesn't do it. It's really, really weird. ]
talismanick_ · 2022-06-09 05:59
How can I tell Emacs to automatically open PDFs in [zathura](https://pwmt.org/projects/zathura/) with M-x `find-file`? (Ivy/Swiper/Counsel user) It'd have to be an entry in `auto-mode-alist`, right? I'd also prefer for it to immediately close the buffer and not start DocView's conversion process. Took a swing at the unify-opening package on MELPA; unfortunately, it didn't work.
ayman_pl · 2022-06-09 07:40
`(setq org-babel-min-lines-for-block-output 0)` So that `M-x org-babel-examplify-region` Will always wrap examples in a block (rather than prefix with ':')
ikdrinkspuitwater · 2022-06-09 08:13
How can I use a lisp variable in my `.dir-locals.el` file to setup my `projectile test command`? I tried: `((nil . ((projectile-project-test-cmd . (concat "make -C " (file-name-directory (file-relative-name buffer-file-name (projectile-project-root))))))))` but I get: `compilation-start: Wrong type argument: stringp, (concat "make -C " (file-name-directory (file-relative-name buffer-file-name (projectile-project-root))))`
_viz_ · 2022-06-09 09:44
Use the eval construct to set the variable.
ikdrinkspuitwater · 2022-06-09 09:57
How? I tried `((nil . ((projectile-project-test-cmd . (eval (concat "make -C " (file-name-directory (file-relative-name buffer-file-name (projectile-project-root)))))))))` But same error. Tried also this: ``` ((nil . ((projectile-project-test-cmd . ((eval . (setq-local mk-cmd (concat "make -C " (file-name-directory (file-relative-name buffer-file-name (projectile-project-root))))))))))) ``` but alas, also same error
_viz_ · 2022-06-10 05:09
You need something like, ((nil . ((eval . (setq project-project-test-cmd XXX)))))
ikdrinkspuitwater · 2022-06-10 07:24
Thanks, it works now. However it seems to have broken projectile. I get a `file-relative-name: Wrong type argument: stringp, nil` when opening a project with `projectile-switch-project`
snippins1987 · 2022-06-11 13:42
I've been using [docker-tramp](https://github.com/emacs-pe/docker-tramp.el) for quick edits in containers and encountered a bug in some apache image/containers where no files are listed in dired-mode, with no error. Setting tramp-verpose to 10 reveals the command tramp/dired use to list the files /bin/ls --color=never -al --sort=version /some/path/. 2>/dev/null A quick test reveals that the ls command in the container does not support the "--sort" switch, but it does support the short versions for sorting switches, another search on docker hub further shows that this is a busybox-based images. So I just hot-patch the part where the switch is introduced: (defun dired-quick-sort--format-switches () (format "%s%s %s %s %s" dired-listing-switches (cond ((string-equal "none" dired-quick-sort-sort-by-last) " ") ((string-equal "time" dired-quick-sort-sort-by-last) " -t") ((string-equal "size" dired-quick-sort-sort-by-last) " -S") ((string-equal "version" dired-quick-sort-sort-by-last) " -v") (t " ")) (if (char-equal dired-quick-sort-reverse-last ?y) "-r" "") (if (char-equal dired-quick-sort-group-directories-last ?y) "--group-directories-first" "") (if (not (string= dired-quick-sort-time-last "default")) (concat "--time=" dired-quick-sort-time-last) ""))) Voilà, now we can use docker-tramp with busybox-based docker images.
be-gay_do-crimes · 2022-06-11 22:08
I also have this issue, and I never got to the bottom of it. I ended up just doing ```emacs-lisp ;; Revert the buffer after switching context (defun jjh/mu4e-context-switch () "Switch betwen Mu4e contexts, and then flush the buffer to update metrics." (interactive) (mu4e-context-switch) (revert-buffer)) (evil-define-key '(normal emacs) mu4e-main-mode-map (kbd ";") 'jjh/mu4e-context-switch) ```
snubbyJspreaker · 2022-06-12 18:20
I found something recently that I use constantly now. Hitting *C-u* before *C-x d* allows you to set the dired listing switches. If you add an R so your listing switches looks like *-alR* then dired will recursively list all the directories under the directory you select to open. What I use the for is to mark all the files shown containing a match for a regexp with the *%g* key-combo.
b3n · 2022-06-14 09:56
Take a look at [OpenWith](https://github.com/garberw/openwith).
vifon · 2022-06-15 11:00
A yet another solution, not dependent on external packages, would be `M-x dired-virtual`. You can save the dired buffer as text (or for that matter: generate any output similar to `ls -l`) and open it with `dired-virtual` later. It's probably less robust than your solutions, but should be more lightweight.