reddit / emacs
Weekly Tips, Tricks, &c. Thread
AutoModerator · 2022-11-16 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.
oantolin · 2022-11-16 12:14
Does anyone have a good mnemonic to remember which is which among tab-bar-mode and tab-line-mode? I keep getting the names mixed up.
_viz_ · 2022-11-16 13:31
Does not count as a mnemonic but: a bar is thicker than a line, tab-bar is "thicker" than tab-line in the sense that the former stores window configuration whereas the latter only stores the buffer visited. Since the entire frame content changes, seeing tab bar as thicker makes sense to me---it has a more substantial effect.
oantolin · 2022-11-16 14:02
Not bad! Thanks. I think I can remember this; let's see if someone else has something even better, but if not this will probably work.
trae · 2022-11-16 15:00
Every time I come back to emacs after a while (couple of hours maybe?) it hangs for a sec. Vigorous C-g usually solves it. How do I figure out what it's doing?
andyjda · 2022-11-16 17:37
Shot in the dark but emacs “hangs” are often caused by garbage collection.. do you have anything unusual in your setup? If not you could try this package:
https://github.com/emacsmirror/gcmh
And I would look into ways to profile memory allocation and garbage collection. One possible cause is that it’s accumulating a bunch of stuff it doesn’t really need while you’re away, and then when you come back it’s busy garbage collecting it… can you check what running processes you have?
trae · 2022-11-16 18:58
Thanks, I'll give it ago. Don't have experience with Emacs GC so this could very well be it!
I'll try profiling, but I expect it's going to be challenging since it'll pick up things I'm working on, normally?
andyjda · 2022-11-16 19:21
Yeah I don’t have much experience profiling for memory allocation, but I suspect the output can be quite messy and hard to parse through. But if you set it up during idle time, you might be able to figure out what it is that’s doing all the allocating/garbage collecting while you’re away
_viz_ · 2022-11-17 02:04
When Emacs is stuck, you can try sending USR2 to the process and that should hopefully produce a meaningful backtrace. If Emacs is still unresponsive, then hammering it with C-g might still end up producing a backtrace.
_viz_ · 2022-11-17 02:05
BTW, the trick that worked for me initially is to find what I need and completely forget about the other! Since tab bar stuff are under C-x t and I never needed tab line, it worked out in my favour.
oantolin · 2022-11-17 03:37
Oh, that's what I do too: I only use the tab bar commands and have memorized the C-x t prefix. But whenever I want to tell someone else about them I have to look up the name! That's what I'm hoping to change.
ilemming · 2022-11-17 04:23
> hammering it with C-g might still end up producing a backtrace
`pkill -SIGUSR2 emacs`, turns on `toggle-debug-on-quit`. That's why bashing `<C-g>` after running the command produces a stacktrace.
I would run both `toggle-debug-on-quit` and `toggle-debug-on-error` before leaving the laptop.
trae · 2022-11-17 16:46
I've never had C-g or USR2 produce a backtrace. I looked up the docs for C-g ([here](https://www.gnu.org/software/emacs/manual/html_node/elisp/Quitting.html)) and they don't mention a stack trace on quit. Is there a toggle I can set, do you know?
edit: just noticed /u/ilemming [answer](https://www.reddit.com/r/emacs/comments/ywnt6p/weekly_tips_tricks_c_thread/iwolfrm/)! it's all there.
terminal_cope · 2022-11-18 02:00
So on my Gnome, X11 desktop, my scrollbars have a border (?) that is themed by the GTK theme in use - a thin (1px?) line between the scroll bar and the gutter that changes color when I change GTK themes.
Does anyone know how I can choose its color to match my Emacs colors? I'm running a recent build off master, not built with pgtk though I think it's the same with pgtk.
tryptych · 2022-11-18 02:51
PSA -- there's an Emacs-focused Mastodon instance here: [https://emacs.ch/about](https://emacs.ch/about)
(I haven't seen it mentioned here)
CowboyBoats · 2022-11-18 14:38
I have a shell command that outputs the names of recently changed files, and I use it a lot for example to pick up where I left off.
I'm migrating my workflow to Doom emacs and I was wondering if there is a way to either run this command from Doom and open the files that it outputs in emacs buffers, OR run it from the CLI and pipe to my system clipboard (which I already am able to do) and paste the filenames into Doom and open them in buffers that way.
CowboyBoats · 2022-11-18 15:31
I've settled for `# my-script > names` and then opening `names` in Doom and opening its contents with `gf`.
pathemata · 2022-11-18 18:02
About org-mode source blocks:
Lets say you have a block with `:dir ~/Folder`, with `~/Folder` in machine A.
Then you go to machine B, and use TRAMP to access the org file.
The directory of the source blocks will be set to `~/Folder` on machine B.
Is there a way that the folder is related to the connect machine, without explicitly setting `:dir ssh:A:~/Folder`?
yes_I_still_use_helm · 2022-11-18 21:27
I wrote a function to paste each line of a rectangular-yank to a cursor in multiple-cursor mode. Useful if you yank some text in multiple-cursor mode, quit out then re-enter and want to paste that text according to the same relative cursor position that it was yanked.
(defun mc/yank-rectangle-for-cursor ()
(interactive)
(let ((rect-lines killed-rectangle))
(mc/for-each-cursor-ordered
(mc/execute-command-for-fake-cursor
#'(lambda ()
(interactive)
(let ((line (car rect-lines)))
(when line
(insert-for-yank line)
(setq rect-lines (cdr rect-lines)))))
cursor))))
andyjda · 2022-11-19 02:33
You can do that but it might be easier to just use [recentf-mode](https://stackoverflow.com/questions/50417/how-do-i-get-list-of-recent-files-in-gnu-emacs)
(works great with vanilla emacs; I don’t use Doom but I don’t see why it wouldn’t work)
gusbrs · 2022-11-19 19:16
Some weeks ago, u/paretoOptimalDev made an interesting post about using more `next-buffer` and `previous-buffer` instead of `switch-to-buffer` (https://redd.it/ybqp3m). I liked the post and had captured it for later and only now could process it properly.
The reasoning for using `next-buffer` and `previous-buffer` is good, but pretty much everyone complained about their default bindings.
It is worth noting that Emacs 28 has included `repeat-mode` and Emacs 29 has added `next-buffer` and `previous-buffer` to the repeat maps. So, if you're in Emacs 29, just enabling `repeat-mode` gets you a better behavior for this. You can start with `C-x <right>` and, after that, just the arrow keys get you to the next or previous buffer.
If you're still on Emacs 28, you can use:
(defvar buffer-navigation-repeat-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "<right>") 'next-buffer)
(define-key map (kbd "<left>") 'previous-buffer)
map)
"Keymap to repeat `next-buffer' and `previous-buffer'. Used in `repeat-mode'.")
(put 'next-buffer 'repeat-map 'buffer-navigation-repeat-map)
(put 'previous-buffer 'repeat-map 'buffer-navigation-repeat-map)
organic-bookworm · 2022-11-20 16:30
In terms of UI, for me `tab-line-mode` is associated with `mode-line` and `header-line`, which span single buffer, while `tab-bar-mode` reminds me of `tool-bar-mode` and `menu-bar-mode`, which are global.
oantolin · 2022-11-20 16:54
Oh, that's good too. Thanks!