reddit / emacs

Weekly Tips, Tricks, &c. Thread

AutoModerator · 2022-06-15 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.
ainstr · 2022-06-15 18:30
The other day I discovered that you can access Spotify through dbus. Most of my use-case for spotify is hitting shuffle on ~20 of my playlists; not much searching, discovering, charts, etc. So, I didn't need any of the existing packages that require an auth token or extra local server. This basically wraps `completing-read` over the alist stored in spotify-playlists. You can probably translate the qdbus call to dbus-send or whatever. ;; Inspired by sp.sh: https://gist.github.com/wandernauta/6800547 ;; Could use https://codeberg.org/jao/espotify, but don't need all the functionalities ;; Potential Issues: https://community.spotify.com/t5/Desktop-Linux/DBus-OpenUri-issue/td-p/1376397 ;; Could just write a fn to extract the ID, and use that in spotify-playlists ;; Current way with full uri allows for playlist vs artist, etc. ;; but probably don't need flexiblity for my use case (defun spotify--clean-uri (raw-uri) "Clean RAW-URI into a dbus-acceptable uri." (let* ((url-fields (split-string raw-uri (rx (or "/" "?")))) (type (nth 3 url-fields)) (id (nth 4 url-fields))) (concat "spotify:" type ":" id))) (defvar spotify-playlists '(("Artist" . "https://open.spotify.com/playlist/1v4UqI9mEEB4ry3a3uaorO?si=bc675402c7384080")) "Alist of spotify playlists for spotify-playlists to select from. RAW-URI is from right-click on playlist > Share > Copy Link to Playlist.") (defun spotify--open-uri (raw-uri) "Open RAW-URI." (let ((prefix "qdbus org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player.OpenUri ") (uri (spotify--clean-uri raw-uri))) (shell-command (concat prefix uri)))) (defun spotify--open-playlist () "Prompt to select and play a playlist from spotify-playlists." (let* ((key (completing-read "Playlist: " spotify-playlists)) (raw-uri (cdr (assoc key spotify-playlists)))) (spotify--open-uri raw-uri) (message (format "Now Playing: %s" key)))) (defun spotify-open-playlist () "Wrapper around `spotify--open-playlist`, to check if spotify is running." (interactive) (pcase (shell-command "pgrep spotify") (1 (message "Spotify not running.")) (0 (spotify--open-playlist))))
DasEwigeLicht · 2022-06-16 17:56
Treemacs now has a git-commit-diff minor mode that shows you [how many commits ahead or behind your repo is vs its remote](https://raw.githubusercontent.com/Alexander-Miller/treemacs/master/screenshots/git-commit-diff.png).
_viz_ · 2022-06-17 04:03
For your occur needs when outline-minor-mode is enabled, (add-hook 'occur-mode-find-occurrence-hook (defun vz/outline-occur-reveal () "Reveal current body text after occur match." (when (or (eq major-mode 'outline-mode) outline-minor-mode) (outline-show-entry))))
0xMii · 2022-06-17 15:29
Does anyone know why my Sly REPL can’t spawn windows? I’ve been playing around with [cl-raylib](https://github.com/longlene/cl-raylib) and when I load my project directly with sbcl or even a REPL that I started from a normal terminal inside Emacs (vterm or eshell both), it works fine and starts up, but when I run any function that should open a window from Sly, it runs the function fine (debugger and stickers work) but no window pops up. Is there a setting I am missing? Here’s my Sly config: (use-package sly :pin melpa :commands (sly sly-connect) :init (setq sly-lisp-implementations ‘((sbcl (“sbcl”) :coding-system utf-8-unix) (roswell (“ros” “-Q” “run”) :coding-system utf-8-unix))) (setq inferior-lisp-program “sbcl”) (setq sly-default-lisp ‘roswell) (defun consult-sly-history () “Search through Sly REPL history.” (interactive) (when-let (history (consult—read (ring-elements comint-input-ring) :prompt “REPL History: “ :sort nil)) (insert history))) ;; Binding via hook because `sly-mrepl-mode-map’ is not defined before opening ;; the REPL for the first time. (add-hook ‘sly-mrepl-hook (lambda () (define-key sly-mrepl-mode-map (kbd “M-‘”) ‘consult-sly-history))) (defun sly-lint-file () “Lint current file with lisp-critic.” (interactive) (sly-eval-async ‘(ql:quickload :lisp-critic)) (sly-eval-async `(lisp-critic:critique-file ,(buffer-file-name))))) It works with neither an sbcl nor a roswell REPL. Thanks!
Acceptable-5521 · 2022-06-17 16:25
What is the difference between `company` and packages like `ivy`, `helm` or `vertico`? From their descriptions, I understood that `company` is an in-buffer text completion framework, whereas `vertico` and the other packages are general completion (narrowing) frameworks for lists of candidates (i.e. `M-x`, `find-file`). Can I use `vertico`, `ivy` or `helm` as a replacement for `company`, as in-buffer completion can somewhat be interpreted as narrowing from a list of candidates.
0xMii · 2022-06-17 18:03
I don’t think you can use either for completion at point. At least I’ve never seen it done and wouldn’t know how. But if you’re looking for an alternative to company, take a look at [Corfu](https://github.com/minad/corfu). It’s by minad, the same guy who makes vertico, and is basically a companion package that, much like vertico, works on top of what’s built into Emacs instead of coming with its own backend like company. It is not quite on par with features as of now but I have been using it for a few months now and I’m very happy with it. I should mention that unlike company it only works in GUI Emacs because it uses child frames. Edit: typo.
Stefan-Kangas · 2022-06-18 05:37
There was a security issue with enriched-mode in Emacs 21-25. If you are like me and don't use it, you could do this: ;;;; Disable enriched-mode permanently. (fmakunbound 'enriched-mode) (fmakunbound 'enriched-decode) (fmakunbound 'enriched-encode)
TeMPOraL_PL · 2022-06-18 08:39
Someone really needs to make a diagram of every package touching completions at point and in minibuffer. I've tried to make sense of it some five times already, and every time I *think* I get it, few weeks later I realize I still don't. So we have `company`, `helm`, `ivy`, `vertico`, `corfu`, `consult`, `cape`... sometimes I see `capf` being used as if it was a package, which I'm pretty sure it isn't. Seriously. There's a dependency graph here I feel only the developers of said packages fully understand.
knusprjg · 2022-06-18 19:45
Is there any clever way to apply/use *file* operations on a buffer, like copy the file or the file name (including path) associated with a buffer in the `switch-buffer` completion? I guess I could add the functions I need to the Embark list, but I'm asking myself if I'm missing something? Isn't there something out of the box? I would guess that this is a typical task for others as well to copy a file somewhere that was recently open.
b3n · 2022-06-19 10:24
Use EXWM? Use Chrome? Here's a few nice simulation keys (setq exwm-input-simulation-keys '(([?\C-y] . [C-S-v]) ; Paste without formatting ([?\C-s] . [C-f return]) ; Search current page ([?\s-b] . [C-S-a]) ; Search tabs ([?\C-x ?r ?m] . [C-d]) ; Bookmark page ([?\C-x ?\C-s] . [C-s]) ; Save page ([?\C-g] . [escape]))) You can now for example do `C-s`, type in a search term, and repeat presses of `C-s` will go to the next matches, just like isearch. :-)
a-c-d-w · 2022-06-19 12:32
I use consult + vertico for in-buffer (i.e., `completion-in-region`) completions: (setq completion-in-region-function #'consult-completion-in-region)
CountZukula · 2022-06-21 10:42
Getting started with emacs (doom, if that matters) and org-roam. I'm looking for a way to find a file, based on a set of keywords. E.g., if a file contains "foo" and "bar", in any order or on any line, it should be shown in the list. Any file in the project's folder (my org-roam directory) should be considered. I know of `consult-ripgrep`, which is promising, but only searches 1 word and single-line. `consult-buffer` seems to have narrowing capabilities, but not sure how to apply that here. Any tips and tricks to offer here? Surely there's a nice way to do this, but I'm not seeing the forest through the trees at this point :).
MBU604 · 2022-06-21 16:52
i'm playing around with vertico+consult; is there any way to have consult-mode-command behave similarly to Counsel-M-x when it comes to filtering commands? For example i'd like to search for "magit-pull". With counsel-m-x i can start typing "git pu" and it filters out all related strings, but with consult-mode-command i need to type the exact string "magit-pu" for it to appear. hopefully it is clear what i mean, not sure how this feature is called exactly.
0xMii · 2022-06-21 20:44
Check out [orderless](https://github.com/oantolin/orderless). It allows you to fine-tune the matching styles you want.
vjgoh · 2022-06-21 20:51
I'm using eglot and clangd, and I'm pretty happy with the setup. One question, though: when I have the cursor over a header file, I get the popup info showing me where the header file is--is there a way to jump to that file from there? find-file-at-point doesn't work.
vjgoh · 2022-06-21 21:06
Oh, never mind. xref-find-definitions does it. Though I'd tried that, but I guess not!
Deep-Fox6860 · 2022-06-22 05:47
Using Elfeed with (old) Reddit RSS feed? here's a code I use to extract tags corresponding to the subreddits from entries links: (add-hook 'elfeed-new-entry-hook (lambda (entry) (let* ((entry-link (elfeed-entry-link entry)) (reddit-tag (when (string-match "old\\.reddit\\.com/r/\\(.*?\\)/" entry-link) (match-string 1 entry-link)))) (when reddit-tag (elfeed-tag entry (make-symbol reddit-tag))))))
MBU604 · 2022-06-22 19:57
thank you that was what i was missing!
JDRiverRun · 2022-06-25 19:17
Here's a start: * **capf**: Not a package. Short for `completion-at-point-functions`: the established emacs standard interface for providing completions. Read about it: [https://www.gnu.org/software/emacs/manual/html\_node/elisp/Completion-in-Buffers.html](https://www.gnu.org/software/emacs/manual/html_node/elisp/Completion-in-Buffers.html). These function are provided by various modes; an example such function: `elisp-completion-at-point`. * **corfu**: in-buffer completion targeting standard CAPFs and using child frames. * **vertico**: in-minibuffer completion for the emacs-standard completing-read (e.g. what M-x prompts with). * **company**: A standalone featureful completion system with its own separate backend interface (not CAPF). Can also target standard capfs (which most modes, old and new, provide). * **cape**: A library of convenient CAPFs, like dabbrev, filename, etc. Also, a set of "tools" for customizing, enhancing, and compositing capfs, by wrapping around them. E.g. if you want dabbrev and emacs-lisp completions all together, cape can do that (and much more). Can also "adapt" company completions backends to make them pretend they are CAPFs. Leaving out capf, which is not a package, none of these depend on any of the others. You can run just **vertico** without any of the others, for example. Ivy and Helm also do not depend on these as I understand them (have not used).
desquared · 2022-07-13 23:10
If you're willing to keep going: what about ido? Can you expand on helm and ivy? I like the idea of using plain emacs stuff as much as possible. I don't think I need some huge, all-encompassing, do-everything framework. What's a good modern choice for that?
JDRiverRun · 2022-07-22 13:39
IDO is a simpler older narrowing completion in mini buffer that puts all candidates on a line. Vertical-flat replicates that. There’s also ido-vertical built in, which is more like vertico.