reddit / emacs

Weekly Tips, Tricks, &c. Thread

AutoModerator · 2022-03-30 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.
80286 · 2022-03-30 08:35
M-x find-name-dired / M-x find-dired Asks for directory and then a glob (find-name-dired) or a regex (find-dired) and runs find recursively. Incredibly useful. Neither by default bound to any keys, which I find strange. As I prefer globbing over regex, I have find-name-dired bound to '\* f' in dired. Using it all the time.
00-11 · 2022-03-30 15:28
Yup. You might also be interested in the enhancements provided in [`find-dired+.el`](https://www.emacswiki.org/emacs/download/find-dired%2b.el). It adds command `find-time-dired`, adds a `find` submenu to Dired's menu bar, and improves most of the `find-*` commands a bit. > `find-time-dired` is an interactive Lisp function in [`find-dired+.el`](https://www.emacswiki.org/emacs/download/find-dired%2b.el). > > `(find-time-dired DIR MIN-TIME MAX-TIME > &optional DEPTH-LIMITS EXCLUDED-PATHS)` > > **Find files in directory `DIR` newer or older than a timestamp.** > > The output is shown in a Dired buffer. > > * `MIN-TIME` is a format-time string parsable by `parse-time-string`, such as `"2014-12-25 23:59:00"`. Only files newer than this are shown. If `MIN-TIME` is `nil` or a string matching regexp `"^\s-*$"`, there is no lower time limit. > > * `MAX-TIME` is also a format-time string parsable by `parse-time-string`. Only files older than this time are shown. If `MAX-TIME` is `nil` or a string matching regexp `"^\s-*$"`, the upper time limit is the current system time. > > * Optional arg `DEPTH-LIMITS` is a list `(MIN-DEPTH MAX-DEPTH)` of the minimum and maximum depths. If `nil`, search directory tree under `DIR`. > > * Optional arg `EXCLUDED-PATHS` is a list of strings that match paths to exclude from the search. If `nil`, search all directories. > > * If args `DEPTH-LIMITS` and `EXCLUDED-PATHS` are both non-`nil` then the command run is essentially the following: > > `find . -mindepth MIN-DEPTH -maxdepth MAX-DEPTH` > > ` \( -path EXCLUDE1 -o -path EXCLUDE2 ... \)` > > ` -prune -o \( -TIME-SWITCH -SINCE-MIN -TIME-SWITCH +SINCE-MAX \)` > > ` LS-SWITCHES` > > where: > > * `EXCLUDE1`, `EXCLUDE2`... are the `EXCLUDED-PATHS`, but shell-quoted. > * `TIME-SWITCH` is `find-diredp-time-prefix` concatenated with `"min"`. > * `SINCE-MIN` is the elapsed time since `MIN-TIME` in minutes. > * `SINCE-MAX` is the elapsed time since `MAX-TIME` in minutes. > * `LS-SWITCHES` is `(car find-ls-option)`.
bcardoso · 2022-03-30 16:38
The thing that was holding me back from finally migrating from company to [corfu](https://github.com/minad/corfu) was the absence of something like [company-prescient](https://github.com/raxod502/prescient.el). As I currently don't have the skills to write a "corfu-prescient" integration myself, I wrote this simple workaround by modifying a [cape](https://github.com/minad/cape) backend (cape-dict) into `cape-hist`, which returns matches from the history of the symbols completed by `corfu-insert`: ;; custom capfs with history (defvar corfu--hist-words (split-string (with-temp-buffer ;; start the history list with the words from my personal dictionary (insert-file-contents "~/.emacs.d/var/hunspell_personal.dic") (buffer-string)) "\n" 'omit-nulls)) (defun my/corfu-add-symbol-to-history () "Add completed symbol to `corfu--hist-words'." (interactive) (let ((symbol (thing-at-point 'filename t))) (when (not (string-match "/.*/" symbol)) ; ignore file paths (setq corfu--hist-words (delete symbol corfu--hist-words)) (push symbol corfu--hist-words)))) (advice-add 'corfu-insert :after #'my/corfu-add-symbol-to-history) (defvar cape--hist-properties (list :annotation-function (lambda (_) " Hist") :company-kind (lambda (_) 'text)) "Completion extra properties for `cape-hist'.") (defun cape--hist-words () "Return previoysly completed words." corfu--hist-words) (defun cape-hist (&optional interactive) "Complete word at point from `cape--hist-words'." (interactive (list t)) (if interactive (cape--interactive #'cape-hist) (let ((bounds (cape--bounds 'symbol))) `(,(car bounds) ,(cdr bounds) ,(cape--table-with-properties (cape--hist-words) :category 'cape-symbol) :exclusive no ,@cape--hist-properties)))) ;; define new capfs with history (fset #'cape-dabbrev-with-hist (cape-super-capf #'cape-hist #'cape-dabbrev)) (fset #'cape-symbol-with-hist (cape-super-capf #'cape-hist #'cape-symbol)) By merging the `cape-hist` with `cape-dabbrev` or `cape-symbol`, these custom capfs (`cape-dabbrev-with-hist` and `cape-symbol-with-hist`) behave in a (somewhat) similar way to company-prescient. I'm sure there are better ways of doing this (feedback is appreciated!), but I find it very useful to have the most recent completed symbols as the first candidates.
shitterwithaclitter · 2022-03-30 17:55
Is it possible to use emms's mpd backend along with other backends in the same playlist? Even when I add a file that `emms-player-mpd-playable-p` returns nil for, I stil sometimes get errors about mpd being unable to add the track. The non-mpd track plays just fine, but when the playlist gets back to an mpd track it gives me an error about failing to open the audio output then just skips the first 2 songs and pauses. From there on out, emms is always one song behind what mpd is actually playing. Is there a good way to fix this or should I just start using multiplaylists or something?
Sudo_Brew · 2022-03-30 18:06
In evil-mode, I can use `viw` to select the "inner word". This mostly behaves as I want, except in snake_case, in which it selects the entire snake_case symbol. For example if I have the cursor on the "n" in snake_case, it will select the entire "snake_case", when I just want to select "snake". In contrast, it already does what I want in kebab-case, selecting only a word as separated by hyphens. Interestingly, it _sometimes_ behaves as I want with snake_case, such as in a scratch buffer. But when it really counts, in something like python-mode, it goes for the whole symbol. How can I teach evil to split up snake_case and/or is there another command to use, or something happening I don't know about?
rucci99 · 2022-03-30 18:33
https://evil.readthedocs.io/en/latest/faq.html#underscore-is-not-a-word-character
Sudo_Brew · 2022-03-30 18:47
Thank you! Unfortunately I already have `(modify-syntax-entry ?_ "w")` in my config, but it doesn't seem to make a difference for some reason? Like I said, it does work in the scratch buffer, but not in several prog modes. Do you know of anything that could be overriding that behavior?
holgerschurig · 2022-03-30 19:19
Not at my computer currently, but I'm using vertico and that has history built in. I'm totally sure it has for it's M-x beefup, I'm just not sure if cape's completion via vertico uses it.
meain · 2022-03-30 19:28
Is it possible that you might have set `evil-symbol-word-search` ?
Sudo_Brew · 2022-03-30 21:22
Nope, looks like its `nil` :\
rucci99 · 2022-03-30 22:58
Try this: (defalias 'forward-evil-word 'forward-evil-symbol)
TeMPOraL_PL · 2022-03-31 08:35
Sometimes you know some of the files you have opened have changed externally, but you're not sure which one. I run into this problem frequently with my Org Mode TODO lists, which are synced across multiple machines. Here's how to quickly list such externally changed buffers with Ibuffer: The code below will add an ibuffer filter and register it under key `?`, so that you can activate it in ibuffer via `/ ?`. (require 'ibuf-ext) (define-ibuffer-filter externally-changed "Limit current view to buffers visiting files that were changed since being last visited or saved." (:description "changed externally" :reader nil) (not (verify-visited-file-modtime buf))) (define-key ibuffer--filter-map (kbd "?") 'ibuffer-filter-by-externally-changed) Or, the `use-package` + `straight` version I use at the moment: (use-package ibuffer :straight (:type built-in) :config (require 'ibuf-ext) (define-ibuffer-filter externally-changed "Limit current view to buffers visiting files that were changed since being last visited or saved." (:description "changed externally" :reader nil) (not (verify-visited-file-modtime buf))) ;; Use ibuffer instead of normal buffer switcher. :bind (("C-x C-b" . 'ibuffer) :map ibuffer--filter-map ("?" . ibuffer-filter-by-externally-changed))) After you've identified the files, you can also use `=` in ibuffer to quickly view the diff between the buffer and the underlying file and `V` to revert it. For finer-grained merging, just switch to the relevant buffer and run `M-x edif-current-file`.
tgrnh · 2022-03-31 10:57
Thanks for mentioning the menu bar. When I switched from vim to Emacs I had no clue that it would basically replace all my apps except from the browser. I thought I would just edit text files, and since I never missed a menu bar in vim I disabled it in Emacs. I just had a look at the menu bar in dired, very helpful, so thanks again.
Sudo_Brew · 2022-03-31 15:55
No change :(
yousufinternet · 2022-04-01 08:28
Adding this to my emacs config breaks the configuration, and running `emacs --debug-init` does not show any errors, but still all the configuration after this piece of code is not run, why is that? help is appreciated. (defun my-load-theme (theme) "reapply font configuration no matter the theme" (interactive) (load-theme theme t) (reapply-font) ) (setq default-theme 'modus-vivendi) (my-load-theme default-theme)
yousufinternet · 2022-04-01 08:38
Nevermind, I posted this after an hour of debugging but just after posting I tried running `emacs --debug-init --daemon` and got the error message, it was because it was trying to set font setting on the daemon process without any frames, I wrapped my `reapply-font` function with `(if (daemonp) )` and it is working ok now
MistakeNotDotDotDot · 2022-04-03 23:58
prescient is a combination of history and also most commonly used options. AFAIK there's no way to get that behavior with vertico. If you *just* want recents then yeah vertico and hist-save will get you there.
pathemata · 2022-04-04 09:23
I'm using `outline-minor-mode` in a python buffer so I can collapse some elements. However I'm having troubles with the python docstring been also collapsed in a weird way. Does anyone have a more robust `outline-regexp` for python?
pathemata · 2022-04-04 09:56
actually, the problem seems to be with function definitions in which the argument list spans more than one line.