AutoModerator · 2022-12-07 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.
suliveevil · 2022-12-07 10:19
I love the idea of toggle or using one keybinding/keyboard shortcut to do two things.
So here it is: use one keybinding sequentially to diff two regions:
Select one region, press the keybinding;
select next region, press the keybinding;
Done!
​
\`\`\`emacs-lisp
(defvar diff-lisp-set-a-and-b nil)
(defun diff-lisp-set-a-and-b ()
(interactive)
(if (eq diff-lisp-set-a-and-b nil)
(progn
(diff-lisp-mark-selected-text-as-a)
(setq diff-lisp-set-a-and-b t))
(progn
(diff-lisp-diff-a-and-b)
(setq diff-lisp-set-a-and-b nil))))
(keymap-global-set "s-/" #'diff-lisp-set-a-and-b)
\`\`\`
package required:
[https://github.com/redguardtoo/diff-lisp](https://github.com/redguardtoo/diff-lisp)
hkjels · 2022-12-07 14:00
I quite like that idea as well. Could be useful for swapping two text-regions as well.
keepitsalty · 2022-12-07 22:13
Why are there different commands for closing emacs vs. closing an emacs client?
When using normal emacs you can do `C-x C-c`
But when using emacs client it tells you to do `C-x 5 0`
oantolin · 2022-12-07 23:13
I think the user interface of the built-in transpose-regions is pretty good too. What you do if you want to swap the region from location A to B with the region location C to D is this: mark A, mark B, mark C, put point at D, call transpose-regions
oantolin · 2022-12-07 23:15
They do different things. C-x C-c shuts down the whole Emacs process, server and all, C-x 5 0 closes just the client frame.
[deleted] · 2022-12-09 22:38
[deleted]
terminal_cope · 2022-12-09 23:28
Yeah, since `C-x C-c` was totally ingrained in me to close the window, when I switched to daemon usage I made it do `(save-buffers-kill-terminal)` and only kill the instance if I give a prefix arg:
(defun my/shutdown (arg)
"Shut down. Without ARG, for daemon, just close window."
(interactive "P")
(if (or arg (not (daemonp)))
(save-buffers-kill-emacs)
(save-buffers-kill-terminal)))
(global-set-key (kbd "C-x C-c") 'my/shutdown)
cryptobadger_ · 2022-12-10 16:54
I am developing a `hydra` / `transient.el` / (?) extension to the `consult-ripgrep` interface.
The idea is to provide means to a) modify the ripgrep parameters b) switch to other search modes c) spawn a `deadgrep` (https://github.com/Wilfred/deadgrep) instance with the current set of parameters.
Right now i work on c) and while i manage to spawn the `deadgrep` buffer i am not able to close the minibuffer containing the consult ripgrep request. i tried `abort-minibuffers` and `exit-minibuffer` but either both buffers (`consult-ripgrep` and `deadgrep`) are visible or none. Can someone help getting rid of the `consult-ripgrep-minibuffer` while keeping the `deadgrep` buffer?
Current implementation is below. In an earlier implementation i updated the `consult-ripgrep-args` variable to modify the search request but i did not find a way to update the minibuffer (happened only on next keypress) so I resorted to use the possibility to append commandline args after `--`
I’d appreciate comments on code style and also concerning the emacs submenu struggle - `embark~/~transient.el~/~hydra~/~which-key`; what is the right way to implement “submenus” and what would you prefer for the given implementation?
(defun fkr//rg-update-inline-context-args (in char operator)
(let ((argr (progn (string-match " -- \\(.*\\)" in)(match-string 1 in))))
(if argr
(progn
(let* ((m (concat "-" char "\\([0-9]+\\)?"))
(x (string-match m argr))
(old-val (and x (string-to-number (match-string 1 argr))))
(new-val (and old-val (apply operator (list old-val 1))))
(new-str (and new-val
(if (> new-val 0)
(concat "-" char (int-to-string new-val))
""))))
(if new-val (string-replace (concat "-" char (int-to-string old-val)) new-str in)
(if (eq operator '+) (concat in " -" char "1") in))))
(if (eq operator '+) (concat in " -- -" char "1") in))))
(defun fkr//rg-update-context (char operator)
(let* ((char-pos (point))
(content (minibuffer-contents-no-properties)))
(delete-minibuffer-contents)
(insert (fkr//rg-update-inline-context-args content char operator))
(goto-char char-pos)))
(defhydra fkr/rg-hydra ()
"
PrintEnv: _A_fter+1 _a_fter-1 _B_efore+1 _b_efore-1
Skip: _r_egular _s_earch-all
Misc: _y_ank-frog _f_d-find-from-match _d_:spawn deadgrep
Open match: _O_pen-in-new-frame-without-exit _o_pen-new-frame-with-exit
"
("A" (fkr//rg-update-context "A" '+))
("a" (fkr//rg-update-context "A" '-))
("B" (fkr//rg-update-context "B" '+))
("b" (fkr//rg-update-context "B" '-))
("s" (fkr//rg-localedit 'find-all t))
("r" (fkr//rg-localedit 'find-all nil))
("y" (message"not implemented."))
("d" (let ((x (minibuffer-contents-no-properties)))
(deadgrep x)
(abort-minibuffers)))
("f" (message "not implemented."))
("O" (message"not implemented."))
("o" (message "not implemented."))
("q" nil))