reddit / emacs

Weekly Tips, Tricks, &c. Thread

AutoModerator · 2022-09-21 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.
slinchisl · 2022-09-21 10:48
TIL about `frame-inhibit-implied-resize`. An excerpt from its docs: > Whether frames should be resized implicitly. > > If this option is nil, setting font, menu bar, tool bar, tab bar, internal borders, fringes or scroll bars of a specific frame may resize the frame in order to preserve the number of columns or lines it displays. If this option is t, no such resizing is done. In my case, Emacs was attempting to resize the frame because I have a font that's slightly bigger than the standard one (i.e., the one `emacs -Q` has). Setting the variable to `t` will prevent this and makes changing the font a much cheaper operation. This is especially useful since any frame resizing Emacs tries to do is spurious anyways, as I use [XMonad](https://xmonad.org/) as my window manager. The upshot is that there's one less expensive operation to worry about during startup. `(setq frame-inhibit-implied-resize t)` cuts my startup time from ~1 second to about .8 seconds, which may not seem much but it's literally setting a single variable in my `early-init.el`. Pretty good value for money. I measured this with emacs --eval "(progn (princ (emacs-init-time) #'external-debugging-output) (kill-emacs))" which I realise might not be the most accurate thing in the world, but since we are measuring a difference anyways it might still count for something.
eleven_cupfuls · 2022-09-21 16:59
If you, like me, love `consult-ripgrep` but not so much the way it treats spaces as non-literal, here is a tiny helper minor mode to change that behavior: https://git.sr.ht/~woolsweater/uncongregate.el When activated, there will be no transformation of the grep command input, so you don't use Emacs regex syntax and spaces don't need to be escaped. If you try it out, please feel free to report any issues you encounter.
No-Command-791 · 2022-09-21 22:35
Get consistent margin sizes in `olivetti-mode` after changing the font scale: (defcustom olivetti-body-width-ratio 0.618 ;; or your ratio here "Text body width as a fraction of the total window width." :type 'float :group 'olivetti) (defun olivetti-text-scale (&rest _args) "Adjust `olivetti-body-width' for `text-scale-mode'." (setq olivetti-body-width (/ olivetti-body-width-ratio (expt text-scale-mode-step text-scale-mode-amount)))) (advice-add 'olivetti-mode :before 'olivetti-text-scale)
slinchisl · 2022-09-22 04:58
Here's a quick hack to mark the current Emacs frame as urgent: (defun slot/mark-emacs-urgent () "Mark the current frame as urgent." (let* ((WM-HINTS "WM_HINTS") (hints (seq--into-list ;; By default this returns a string/vector. (x-window-property WM-HINTS nil WM-HINTS nil nil t)))) ;; Urgency flag: (1L << 8) == 256 ;; Source (as always): https://tronche.com/gui/x/xlib/ICC/client-to-window-manager/wm-hints.html (setcar hints (logior (car hints) (lsh 1 8))) (x-change-window-property WM-HINTS hints nil WM-HINTS 32))) I needed this because I want ERC to mark itself as urgent when I get highlighted (in addition to the usual beep); now that is just an (defun slot/beep-on-match (match-type _nickuserhost _message) (let ((visible-bell nil)) (slot/mark-emacs-urgent) (erc-beep-on-match match-type _nickuserhost _message))) away!
FitPandaFu · 2022-09-22 05:05
(global-unset-key (kbd "M-c")) ; was capitalize word (global-unset-key (kbd "M-u")) ; was upcase word (global-unset-key (kbd "M-l")) ; was downcase word Welcome your new ergonomic(Meta is pressed with left or right thumb for me) key space for all your personal keybindings and rebindings.
Schievel1 · 2022-09-23 06:45
Before someone comes up with it, this is how you do the pasting without overwriting the "+ register when you hightlighted something in visual mode before. Like the Primagen suggested in his new Vim video to bind to some key: ``` (defun mystuff/evil-safe-paste-after () "Paste the evil + register but don't overwrite the register" (interactive) (setq paste-backup (evil-get-register ?+)) (set-text-properties 0 (length paste-backup) nil paste-backup) (evil-paste-after 1) (evil-set-register ?+ paste-backup)) ``` This works with the system clipboard as well. When you just bind a key to paste "0 (the register with what was last yanked in emacs), it does not. All this different terminology is really confusing. Yank, past, kill... I went with vims terminology here because it is about evil after all. You can also just use the kill-ring, like a normal person, though.
github-alphapapa · 2022-09-26 16:03
I use those bindings regularly, and miss them when I'm using other editors. I'd suggest `M-SPC` for your personal "leader key"-style map. To each his own, of course.
github-alphapapa · 2022-09-26 16:04
Thanks for sharing that. I think I will use it in https://github.com/alphapapa/ement.el Hmm, unfortunately it doesn't seem to have any effect on my system. The frame never gets marked as urgent. I found the solution at https://emacs.stackexchange.com/questions/56036/portable-way-of-setting-the-windows-urgent-hint: the call to `x-change-window-property` needs a final `t` argument.
FitPandaFu · 2022-09-26 16:56
I don't use them much so I just rebind them to something slightly less convenient, ex: `M-c C` for capitalize word. Also, having only one prefix key space vs three means one will have to create longer sequences of keys since you have to adjust everything to to one prefix space. Can't stand the Doom emacs stuff like `Space f i h s k` Another advantage for me is they are faster to type, ex: `M-c M-c` vs `M-spc c`
slinchisl · 2022-09-26 17:53
> Thanks for sharing that. I think I will use it in https://github.com/alphapapa/ement.el Sounds good! I've always wanted to try out `ement.el`, hoping there is finally a sane matrix client. Still haven't gotten around to setting up Pantalaimon for encryption. > Hmm, unfortunately it doesn't seem to have any effect on my system. The frame never gets marked as urgent. > I found the solution at https://emacs.stackexchange.com/questions/56036/portable-way-of-setting-the-windows-urgent-hint: the call to x-change-window-property needs a final t argument. Ah indeed; looking through the docs for `OUTER-P` I think this is due to XMonad being a non-reparenting window manager and most other WMs that people use are reparenting.
github-alphapapa · 2022-09-26 20:53
> Sounds good! I've always wanted to try out ement.el, hoping there is finally a sane matrix client. Still haven't gotten around to setting up Pantalaimon for encryption. I've tried to make it sane, yes. :) I don't use Pantalaimon yet either, but I still use Ement for all the public rooms I'm in.
0lMon · 2022-09-27 04:04
An other possible leader key I use is C-z. I don't suspend or minimize my emacs frame through emacs (I use my wm for that). With that I have C-c, C-x and C-z three leader keys side by side.
[deleted] · 2022-09-27 22:58
[deleted]
eleven_cupfuls · 2022-09-28 01:14
It seems that when I wrote the package I was on a very old version of Consult, and an internal function that I made use of had changed its signature. I have pushed a fix. If you tried this out and got an error, please try the update.