reddit / emacs
Weekly Tips, Tricks, &c. Thread
AutoModerator · 2022-08-10 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.
azhake · 2022-08-10 08:35
I don't like how `quit-windows` buries buffers instead of killing them, so I have this function that inverts the meaning of the prefix argument, such that pressing `q` kills the buffer and `C-u q` buries it, which is the reverse of the original `quit-windows`.
;; Quit window and kill its buffer
(defun aj8/quit-window ()
"Quit WINDOW and kill its buffer.
With a prefix argument, bury the buffer instead (this is the
inverse of the default behavior of the standard `quit-windows'
function)."
(interactive)
(if current-prefix-arg ; C-u
(quit-window) ; bury
(quit-window 1))) ; kill
Then remap `quit-windows` for modes of your choice, e.g. `info-mode`:
(with-eval-after-load "info"
(define-key Info-mode-map [remap quit-window] #'aj8/quit-window))
00-11 · 2022-08-10 16:00
I've used this for years (from [`misc-cmds.el`](https://www.emacswiki.org/emacs/download/misc-cmds.el):
(defun quit-window-delete (&optional kill window)
"Quit WINDOW, deleting it, and bury its buffer.
WINDOW must be a live window and defaults to the selected one.
With prefix argument KILL non-nil, kill the buffer instead of
burying it.
This is similar to the version of `quit-window' that Emacs had before
the introduction of `quit-restore-window'. It ignores the information
stored in WINDOW's `quit-restore' window parameter.
It deletes the WINDOW more often, rather than switching to another
buffer in it. If WINDOW is alone in its frame then the frame is
deleted or iconified, according to option `frame-auto-hide-function'."
(interactive "P")
(set-window-parameter window 'quit-restore `(frame frame nil ,(current-buffer)))
(quit-restore-window window (if kill 'kill 'bury)))
(define-key global-map [remap quit-window] 'quit-window-delete)
SlowValue · 2022-08-10 17:57
This is my solution, which I use since some years already:
It installs an advice and defines some exceptions, because sometimes the quit flag is set already, and for certain buffers killing is not wanted at all.
(defcustom my-quit-window-außnahmen-regex "^\\*\\(Messages\\)"
"Regexp, buffer names, where argument should not be inverted.
This ensures, the original behavior is used."
:group 'my-config)
(defcustom my-quit-window-known-wrappers '(magit-mode-bury-buffer Info-exit)
"list of commands, which call `quit-window' and where arg should be negated. "
:group 'my-config)
(defun my-quit-window (args)
"advice function, which modifies arf of `quit-window'."
(when (and (or (eq this-command 'quit-window)
(member this-command my-quit-window-known-wrappers))
(not (string-match-p my-quit-window-außnahmen-regex (buffer-name))))
(unless (consp args)
(setq args (list nil)))
(setf (car args) (not current-prefix-arg)))
args)
;; install advice
(advice-add 'quit-window :filter-args 'my-quit-window)
talismanick_ · 2022-08-11 07:16
I've switched from pdf-tools to Zathura as my viewer. I have one small problem: when I run `TeX-command-run-all` (C-c C-a), it pops up a new window, even though Zathura will already live-update the display when the PDF is modified. What should I change so it only opens Zathura the first time and silently recompiles beyond, short of binding my own with a hamfisted `(shell-command (concat "pgrep zathura " (make-regex-idk buffer-file-name)))` check or keeping a counter?
`TeX-command-run-all` does something weird with `(interactive "P")` and checking if the `car` of the argument is 4... I don't feel comfortable wrapping it, anyways.
fast-90 · 2022-08-11 19:48
Posted [here](https://www.reddit.com/r/orgmode/comments/wlz2yc/showing_org_document_title_in_orgclockreports/) already, but thought it's worth a shot asking here as well. Is there any way to show the org document title (i.e. the value of `#+title:`) instead of the file name in `org-clock-report`s?
hairlesscaveman · 2022-08-12 09:25
Is there a way I can keep the end of a compilation buffer in view as content is pushed to it?
Specifically, I'm using a package that executes tests which push the output to a named buffer, and I'd like to have the window scroll to the end of that buffer while the process continues to run. Once it has completed, I'd like to be able to scroll within the buffer as normal.
eleven_cupfuls · 2022-08-12 16:47
As simple as `(setq compilation-scroll-output t)`
https://www.gnu.org/software/emacs/manual/html_node/emacs/Compilation.html
chewy959 · 2022-08-12 17:08
Hello, I have been experiencing this behavior where my \\ symbols become Yen Symbols in my org-mode buffers. I've spent several hours trying to troubleshoot why and have changed fonts too.
Any ideas?
**Edit: It was Variable Pitch Mode causing issues with a default font.**
WorldsEndless · 2022-08-13 17:10
formulaic changes need to be made to some repeating content: 3 different options:
1. Replace [regexp] heavy lifting. Can perform actual functions on match groups.
2. Macros. Easiest: hit "record", do you thing in such a way as to be ready for the very next one, save/repeat. Can be saved as a function if you love it.
3. Multiple Cursors. One-off, but the quickest if you can see your targets on the screen and don't want to think about more steps.
hairlesscaveman · 2022-08-14 17:32
Amazing! Thank you so much!
eleven_cupfuls · 2022-08-14 17:50
2a. Don't forget (I always forget; this is as much a reminder to myself as anything) that keyboard macros can also have "query points" inserted into them! "Interactive Keyboard Macros" heading here: https://www.masteringemacs.org/article/keyboard-macros-are-misunderstood
WorldsEndless · 2022-08-14 18:41
Whoa! I had no idea!
BayesMind · 2022-08-14 21:07
> see your targets on the screen
Not a requirement! You can highlight all in the document, and even vist them with `C-v` `M-v` once highlighted.
MC tends to be my goto for all of the above, and I use it at least a dozen times per hour, vs macros that always seem a bit heavier. Macros take a while to get right (don't mess up!) and then half way through applying a macro, maybe you find an exceptional case that breaks it. With MC, you can just deal with things on the fly! Macros definitely have a place, but, I feel like MC needs more love and attention, it's definitely one of my most used libs!
WorldsEndless · 2022-08-15 00:10
Multiple Cursors is a great lib! Thanks for the keystroke!
chrchr · 2022-08-15 20:18
Question:
In repos for Java apps, for instance, they typically have a deeply nested structure like:
`org/company/package/program.java`
In the case where `org/company/package` is the only subdirectory in the tree, is there a configuration so that completion jumps to `org/company/package/` instead of requiring completion at each parent directory?
talismanick_ · 2022-08-16 01:11
It's a hack, but I'm writing a function to compile the PDF and open Zathura in a running process unless there's already one:
(defun nt/latex-compile-zathura ()
"Compile current LaTeX buffer and open in Zathura if not already opened."
(interactive)
(unless (eq major-mode 'latex-mode) (user-error "%s" "Not in a LaTeX mode buffer"))
(let* ((name (TeX-master-file "pdf" nil nil))
(bufname (concat "View " name)))
(TeX-command "LaTeX" #'TeX-master-file nil)
(unless (and (local-variable-if-set-p nt/latex--view-proc) (buffer-live-p nt/latex--view-proc))
(setq-local nt/latex--view-proc (start-process bufname bufname "zathura" name)))))
Unfortunately, I haven't found how to buffer-locally bind the process so I can check if there's already a running Zathura instance for a given buffer. Right now, it shares the problem with `C-c C-a` of reopening the viewer on every compilation.
HM0880 · 2022-08-16 20:16
`dired-collapse` doesn't do completion, but it does handle deeply nested directories with only one file as the leaf node:
https://github.com/Fuco1/dired-hacks#dired-collapse
(Not a real answer to your question, but if you are working with Java, `dired-collapse` could be useful.)
chrchr · 2022-08-16 20:32
That is the kinda thing I’m looking for. Thank you!
HM0880 · 2022-08-17 21:23
Happy to help!
poiu- · 2022-09-14 19:42
Look at the definition of something like org-dblock:org-clock-report.
fast-90 · 2022-09-15 20:57
Actually this has now been [implemented as an option](https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/etc/ORG-NEWS?id=2cc2d8f1f6265d12c92b734931f2e3e417276b05) in the latest version on git.