reddit / emacs
Weekly Tips, Tricks, &c. Thread
AutoModerator · 2022-08-24 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.
CraniumTheFirst · 2022-08-24 13:47
I wanted to query org files from my terminal and jump to the heading I wanted in one go. It took me a long time but I figured how to use `org-ql` (and lisp :D) but I finally have a usable bash script:
# Usage: orgql-open '(todo "TODO")'
# See sexp query format here: https://github.com/alphapapa/org-ql#non-sexp-query-syntax
function orgql-open() {
query=$@
emacsclient -e "(json-encode (org-ql-query :select '(list (cons \"header\" (substring-no-properties (org-get-heading t t))) (cons \"link\" (substring-no-properties (org-store-link nil nil) 0)) (cons \"content\" (substring-no-properties (org-get-entry) 0))) :from (org-agenda-files) :where '$query))"\
| xargs -I % -0 python -c "print(%)" \
| jq -r '.[] | (.link + "\t" + .header + "\t" + (.content|@json))' \
| fzf -d"\t" --with-nth=2 --preview 'cat <(echo {+2}) <(printf {+3} | sed -e "s/^\"//g" -e "s/\"$//g")' \
| cut -z -f1 \
| xargs -0 -I % emacsclient -nc -F '((width . 120) (height . 40))' -e "(progn (org-open-link-from-string \"%\") (recenter-top-bottom 2))"
}
You'll need `org-ql` in Emacs and `fzf`/`jq`. I had to fight with formatting issues but it should work nicely despite that.
**EDIT: The function is fixed.** Everything was converted to lowercase when I pasted (I suspect an Evil `gu` lurking around)
HM0880 · 2022-08-24 15:40
In Org Mode, what is the reason to use `~` for in-line code vs. `=` for monospace text? I use `=` for both code and monospace since (afaict) Org renders both code and monospace the same way in LaTeX PDF and HTML output, and `=` does not require using shift (unlike `~`).
_viz_ · 2022-08-24 15:45
Apologies for asking something potentially obvious: why not do the massaging of the data in Elisp?
[deleted] · 2022-08-24 16:56
[deleted]
Jack-o-tall-tales · 2022-08-24 17:45
I added this to `org-metareturn-hook` today. It lets you capture to the node linked at point in org-roam buffers.
(defun my/org-roam-capture-to-link ()
"In org-roam files, capture to node linked at point."
(when-let ((_ (org-roam-file-p)) ;; Only act in org-roam files
(link-start (car (org-in-regexp org-link-bracket-re)))
(link (save-excursion
(goto-char link-start)
(org-element-link-parser)))
(id (plist-get (cadr link) :path))
;; This will fail if there is no node
(node (org-roam-node-from-id id)))
;; If there /is/ a node, capture to it.
(org-roam-capture- :node node)))
[deleted] · 2022-08-25 00:31
[deleted]
meain · 2022-08-25 03:41
I use the following snippet to change background color of compilation buffer to a light red if the compilation failed. I use compilation buffer to run tests on a second monitor and this is pretty useful.
(defun meain/compilation-colorcode (_buffer string)
"Change background color of compilation `_BUFFER' to red on failure."
(unless (string-prefix-p "finished" string) ; Having color for success was distracting
(face-remap-add-relative 'default 'diff-hl-delete)))
(add-to-list 'compilation-finish-functions 'meain/compilation-colorcode)
CraniumTheFirst · 2022-08-25 07:25
Good question, it's actually due to the back and forth with `fzf`: only the `jq` could be omitted and maybe the `sed`. But I don't know how to do that in elisp yet. One thing that could be cool is to have an helm session (in the terminal) replacing fzf and all this piping entirely.
slinchisl · 2022-08-26 06:11
Frankly, `=` is just a bad choice for code (even though it's officially a "verbatim" env, I've almost exclusively seen it used for code) and I wish we could just use \` like markdown does. The equals sign is used quite a lot in code and sometimes Org simply gets confused and does the wrong thing. For example, `=exiftool -all= image.jpg=` will not render correctly because Org thinks the `=exiftool -all=` part is the code and anything after that isn't. This is irreparable, as far as I can see (`-all =` and `-all` are _not_ the same as `-all=`) and for that `~` is the only solution
HM0880 · 2022-08-26 23:31
Good points. I looked into using backtick instead of `=` or `~`, but it seemed that = and ~ were really baked into the Org core and not easy to modify to allow backtick.
The other good thing about backtick is that it is understandable without Org syntax highlighting; = and ~ as surrounding characters lack that clarity.
What are your thoughts on using `=` if possible and `~` for special cases like your exiftool example?
Edit: Change ` to the word "backtick."
slinchisl · 2022-08-27 04:31
> What are your thoughts on using `=` if possible and `~` for special cases like your exiftool example?
Personally, at this point I just use `~` almost exclusively. A few themes use a different colour for the `org-verbatim` and `org-code` faces, so mixing them looks a bit weird in my opinion. Plus, `~` is on the home-row for me (on a different layer, so I can press it via `<Alt_R>-g`), so it's not actually harder to reach than `=`.
HM0880 · 2022-08-27 11:17
Makes sense. (I haven't used a theme where = and ~ are different.)
What keyboard/layout do you use? I use a two-layer version of the Atreus.
HM0880 · 2022-08-27 11:19
Here's a DIY barebones version of fzf in Emacs:
https://www.masteringemacs.org/article/fuzzy-finding-emacs-instead-of-fzf
slinchisl · 2022-08-27 12:51
At home I use a WhiteFox, but most of my work is actually done on my X220 laptop keyboard. I get proper functionality out of this via [kmonad](https://github.com/kmonad/kmonad), which is essentially QMK but in software instead of firmware, meaning every keybard is supported! For the layout I use a custom-ish colemak-dh layout ([here](https://gitlab.com/slotThe/dotfiles/-/blob/master/kmonad/.config/kmonad/x220-slot-us-colemak-dh-z.kbd))
fast-90 · 2022-08-27 16:35
I just got mu4e with mbsync working and I love it! One question for those who use a similar setup: how do you store your passwords for mu4e? I currently have it stored using `pass`, and use the corresponding `pass` command in my `.mbsyncrc` file (with the PassCmd argument). This works fine in general, however whenever I start a new emacs session with mu4e (e.g. when I start the day), I need to enter my master passphrase before `mbsync` can synchronize. Unfortunately I can't seem to enter it whilst it prompts it in mu4e. I need to manually run `mbsync -a` (e.g. in vterm) to enter my master passphrase.
How are others doing this? Do you store your password using `pass`? If so, how/when do you enter your master passphrase when you startup emacs? If not, what method do you use, and what is your workflow for starting up mu4e?
WorldsEndless · 2022-08-27 18:25
Is there a good way to have my system share a kill ring with emacs? There is cognitive dissonance in going to emacs, where I can cut multiple things and then yank the one that I want right here, to my browser, where I have to make sure the thing I want to paste is the most recent thing I copied/cut.
justanothercsperson · 2022-08-27 19:48
Due to all the strain my pinky gets I thought to try out mapping ctrl to the right super key on the keyboard.
Previously I was using capslock.
After a bit of use I'm wondering why this isn't the default recommendation.
[deleted] · 2022-08-27 20:14
[deleted]
HM0880 · 2022-08-28 12:27
Similar to you, I map ctrl to the right alt key so I can use my thumb for ctrl. I have never understood why caps lock is so popular since caps lock is a pinky command too.
eleven_cupfuls · 2022-08-28 19:25
What is your OS?
Extension_Try_6870 · 2022-08-28 21:39
I have the same setup as you. Whenever I need to enter a passphrase, a graphical input automatically pops up. I think it's called pinentry-gtk.
b3n · 2022-08-29 01:36
You can set `save-interprogram-paste-before-kill` to `t`
_viz_ · 2022-08-29 01:56
Indeed. It took me just 5 seconds to realise the control-capslock recommendation would make my pinky hurt even more.
_viz_ · 2022-08-29 01:58
I don't understand jq language, but org-ql seems to return a regular alist so the standard list and assoc list functions should help you eliminate jq.
hairlesscaveman · 2022-08-29 06:27
Is there a way I can tell Embark to execute a command with "other-window"? For example, I use Embark to trigger `xref-find-definitions` a lot, and it would be great if I could then tell Embark which window to use (as a general use-case), or at least switch the command to `xref-find-definitions-other-window` (for this specific case).
[deleted] · 2022-08-29 14:15
There are programs that have kill-ring-esque functionality for the desktop and will save clip history(e.g. klipper for kde) but it would be likely that accessing each one would require using its own communications functionality(if it even has one).
WorldsEndless · 2022-09-02 18:23
Linux (using exwm, though that doesn't deal much with kill ring I think)
WorldsEndless · 2022-09-02 18:23
This allows the most recent one thing to go back and forth from emacs, but not the whole ring, I think