reddit / emacs

Weekly Tips, Tricks, &c. Thread

AutoModerator · 2022-04-20 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.
thisadamis · 2022-04-20 10:44
I had a question. Every time I make a org capture and then go to the file I captured it to It's not there? I have to quit emacs and than go back to the file and it's there..... Any idea why?
T_Verron · 2022-04-20 11:39
My guess would be that turning `auto-revert-mode` on would fix it. Or calling `M-x revert-buffer` instead of restarting emacs.
[deleted] · 2022-04-20 12:51
[deleted]
thisadamis · 2022-04-20 14:22
Awesome I’ll try it and report back. 👍
thisadamis · 2022-04-20 16:12
Thank you so much that fixed it!
jumpUpHigh · 2022-04-20 17:58
Are there any packages that can help define project templates in orgmode. I would like to define templates that can be reused when I need. I understand org-capture templates can help, but is there any other way? Examples Weekend Trip 1. Prepare car 2. Pack bags 3. Finalize route and halts Check fire readiness: 1. Test fire alarm in Kitchen 2. Test fire alarm in Bedroom-1, Bedroom-2. 3. Practice evacuation.
Visual_Bumblebee_555 · 2022-04-20 18:42
I think `org-capture-goto-last-stored` might show it even if auto-revert-mode is not enabled.
BunnyLushington · 2022-04-20 19:23
When I hear "template" I think [Tempo Mode](https://www.emacswiki.org/emacs/TempoMode). It's always served me well. (I'm not particularly conversant with org-mode, so maybe I'm wildly off base.)
Phil-Hudson · 2022-04-20 22:02
Any reason not to use Org?
gnuvince · 2022-04-21 00:17
I'm not the biggest fan of syntax highlighting, but I'm also not happy with no highlighting. I want some tokens to be colored to catch my attention (function names, string/character literals, comments) and the rest to be the default color. The snippet below makes a bunch of tokens be the default color for a much less busy look. (use-package font-lock :custom-face (font-lock-keyword-face ((t (:foreground nil)))) (font-lock-type-face ((t (:foreground nil)))) (font-lock-variable-name-face ((t (:foreground nil)))) (font-lock-constant-face ((t (:foreground nil)))) (font-lock-doc-face ((t (:foreground nil :inherit 'font-lock-comment-face)))) (font-lock-preprocessor-face ((t (:foreground nil)))) (font-lock-builtin-face ((t (:foreground nil)))))
nicholas_hubbard · 2022-04-21 02:24
I wrote a function that allows you to easily run a `sed -i` command on the current buffer. I am thinking about extending this into a full blown package for using sed in emacs. Would you be interested in such a package? (defun my/sed-edit (sed-function) "Run a sed command on the current buffer." (interactive (list (read-string "sed -Ei "))) (if (not (file-writable-p buffer-file-name)) (user-error "Can't run sed on this buffer") (save-buffer) (let ((shell-file-name "/bin/sh") (shell-command-switch "-c")) (shell-command (string-join (list "sed" "-Ei''" (concat "'" sed-function "'") buffer-file-name) " ")))) (revert-buffer nil t))
jumpUpHigh · 2022-04-21 06:18
I am looking for a solution that works in orgmode.
Rotatop · 2022-04-21 11:36
I don't understand the use of sed inside emacs. Personaly I use 'evil' and I do : :%s/search/replace/g And for complexe use, still with evil : :g/search/norm command
T_Verron · 2022-04-21 12:08
Why do you prefer to use it over emacs' implementation of search and replace (interactive or not)?
Phil-Hudson · 2022-04-21 12:41
Sorry, I meant any reason not to use Org capture?
_viz_ · 2022-04-21 13:38
There's an entire section dedicated to autotype in info dir. Maybe check if those are feasible?
_viz_ · 2022-04-21 13:40
There's ed-mode. Butif you are feeling adventurous, there's also sam-mode.
zuma0 · 2022-04-21 16:20
There is also [Tempel](https://github.com/minad/tempel) which bills itself as a modern Tempo mode. It's by the same author as Vertico, Consult, etc.
nicholas_hubbard · 2022-04-21 16:40
Its useful if you don't use evil.
nicholas_hubbard · 2022-04-21 16:42
Because sed can do more than just search and replace and I know it well.
nicholas_hubbard · 2022-04-21 16:44
Ill check out ed-mode. I have wanted something like vim's ex-mode but I don't use evil. Maybe ed-mode can fill that role for me.
kovrik · 2022-04-21 23:53
In Intellij there is a Search Everywhere function (Shift-Shift): [https://www.jetbrains.com/help/idea/searching-everywhere.html](https://www.jetbrains.com/help/idea/searching-everywhere.html)). Is there a similar function in Emacs? Basically, I'd like to have a mini-buffer or a pop-up where I could type in my search and it would search everywhere: buffers, symbols, actions/commands, docs, files etc. If there is no such a function built-in, what would be the best way to create one (or maybe there's a package for that)?
eli-zaretskii · 2022-04-22 08:50
Try `M-x rgrep` or `M-x multi-isearch-files`. Another possibility is the `Q` command in Dired. (It's hard for me to tell which one is best for you, because you didn't say enough about your needs, and referring to IntelliJ doesn't help because Emacs uses different paradigms.)
hairlesscaveman · 2022-04-22 08:59
**Question:** When I call `browse-url-of-region` my default browser (Safari on macOS) doesn't open the URL but instead opens a local file, with a path like `file:///private/var/folders/3y/c9bj6v0x2cs2dk39v8jc1ksw0000gn/T/burlwHvOGz.html`, and this html contains the URL I'd like to visit. Is there a way I can get this set up to actually open the URL? I'd like to avoid specifying Safari if I can, since I use a tool called Choosy which asks me which browser I want to open when I click on any URL outside of a browser – handy for opening Chrome for Google Meet links, for example.
alanthird · 2022-04-22 15:00
Does plain old `browse-url` not do what want?
kovrik · 2022-04-22 18:57
Thanks! Wouldn’t those just search across multiple files? What I meant was (sorry, typing on my mobile, don’t remember exactly certain commands; also, I use swiper/ivy/counsel, but it shouldn’t really matter): - M-x: shows a list of commands available. And I use swiper/ivy/counsel for the search there [commands] - ivy-switch-buffer: opens a mini-buffer with a list of buffers where I can search (again, using ivy) [buffers] - counsel-find-file: to find a file [files] - then there’s one to search for key bindings [key bindings] - one to search for symbols (variables, functions etc) [symbols] - and so on Now, I want to have a single ’search-everywhere’ command: opens a mini-buffer, I type in, and it searches across all above: buffers, commands, files, symbols, bindings etc. Hope now it makes more sense. How do I do that? Would be nice if it would be extensible (like I can add/remove certain items from that search/index).
Null-A · 2022-04-22 21:31
Pulsing cursor mode - UI tweak to animate cursor to fade in & out. https://www.reddit.com/r/emacs/comments/u9omcp/pulsingcursormode\_ui\_tweak\_cursor\_animation\_fades/
oantolin · 2022-04-23 08:31
You could easily make this with Helm, just chuck together all the Helm sources you want.
oantolin · 2022-04-23 08:34
You don't even need evil for that. The builtin in viper package does that too. You don't even have to use viper mode to run ex commands, you could just use viper-ex without activating viper-mode.
oantolin · 2022-04-23 08:35
Try the builtin command viper-ex to run ex commands. I think you can even use it without turning on viper mode!
Rotatop · 2022-04-23 08:38
Yep, I must take time to learn the internals. Thanks.
eli-zaretskii · 2022-04-23 08:44
Maybe it's me, but it makes little sense to me to search both buffers, commands, files, symbols, bindings, etc. What would be the purpose of that? In a typical Emacs session, you will have thousands of potentially matching items from different categories, so you will just drown. Emacs provides commands to search commands, variables, and other symbols, the most general one is `M-x apropos`. Emacs also provides commands to search files, which is what I mentioned in the previous post. There are also commands to search buffers: `M-x multi-occur`. So depending on what you need, you can invoke one of those.
kovrik · 2022-04-24 04:18
It’s just that in case of Intellij I need to remember about four-five key bindings (those that I use most often): - M-<f1>: locate current file, show it in the file browser pane. Useful to see where current file is located, which package etc. - C-S-f: find text everywhere. I can choose whether I want it to be case sensitive or not, use regex or not etc. - C-S-<f10>: run thing at point. Can be anything: current Unit test, current Unit test suite, current file, current script etc. - And finally, Shift-Shift: search everywhere (classes, commands, symbols, files etc.). - Why would I want that? Because I don’t have time nor desire to remember dozens of different key bindings. I remember four-five that I use most often. And for everything else I use that Search Everywhere. If I want to open settings, I press Shift-Shift and type ‘settings’, then Enter. If I want to stop currently running process I press Shift-Shift, type ‘stop’, select action and press enter. If I want Intellij to generate getters/setters/whatever, I hit Shift-Shift, type ‘getter setter’, then enter. And so on. I want similar behaviour in Emacs. Because there are way too many commands and packages out there, I can’t remember a key binding to eval current buffer in cider-mode, then similar key binding in racket-mode, similar in slime-mode, elisp-mode etc. So I am trying to unify my key bindings across all modes so that I could remember four-five and be done with it. And for everything else I’d just use that Search Everywhere functionality. Hence the question.
[deleted] · 2022-04-24 05:18
[deleted]
kovrik · 2022-04-24 08:46
Yup, thanks! I will give it a go. I decided to come back to Emacs (after 3 years of not using it) and now trying to tweak my config to match Intellij in _some_ ways (muscle memory). I also see that there are many new packages out there: Selectrum, Vertico, Marginalia etc. that kind of replace Helm and/or Swiper/Ivy/Counsel. But I have not tried them (not really sure if I want to; too lazy to switch).
Desmesura · 2022-04-24 16:29
I've set `(setq tab-bar-select-tab-modifiers '(meta))` and `M-<n>` still does `C-u <n>` instead of changing tabs. Everything else from tab-bar-mode works perfectly. What am I missing? I've also tried with setting it to `'(alt)`, still the same. Thanks a lot in advance.
condor2000 · 2022-04-25 07:26
Just upgraded to 28.1 Now the common prefix completion (M-x , C-h v, etc) is unreadable: white on yellow or something (i am using tango-dark) The background is the highlight face. I cannot find the face for the foreground. I guess it should be in icomplete.el?
condor2000 · 2022-04-25 07:35
Found it! completions-common-part
hairlesscaveman · 2022-04-25 08:30
Embark provides `browse-url-of-region` as a completion when a region is selected, and it looks like `browse-url-of-region` calls `browse-url` anyway, so it seems like the problem is a little more fundamental.
alanthird · 2022-04-25 08:49
Well, on my Emacs browse-url-of-region does what you describe, but browse-url just opens the URL. You don't even need to use the region as long as the URL is under the point. Give it a try! :)
_noctuid · 2022-04-26 00:47
> Because I don’t have time nor desire to remember dozens of different key bindings Why not bind specific commands on a common prefix then and use which-key (or hydra or hercules)? I think you'll save time narrowing it down to what you actually want to do rather than just throwing everything together into a "search everywhere."
kovrik · 2022-04-26 00:58
Yeah, that's why I am trying to do.
0lMon · 2022-04-26 08:32
Hej hej, Were do you set this setting? If I am not mistaken you have to do it before the package is loaded. This would mean in the :init section of use package or before activating tab-bar-mode. Cheers!
Desmesura · 2022-04-26 08:44
Thank you so much, that was it!