feat: Emacs prefixing function

This commit is contained in:
Swarsel 2024-07-19 00:21:49 +02:00
parent 676f8b136e
commit 38b7687b5c
Signed by: swarsel
GPG key ID: 26A54C31F2A4FD84

View file

@ -7711,6 +7711,35 @@ The standard Emacs behaviour for the Python process shell is a bit annoying. Thi
#+end_src #+end_src
**** Nix common prefix bracketer
This function searches for common delimiters in region and removes them, summarizing all captured lines by it.
#+begin_src emacs-lisp
(defun swarsel/prefix-block (start end)
(interactive "r")
(save-excursion
(goto-char start)
(setq start (line-beginning-position))
(goto-char end)
(setq end (line-end-position))
(let ((common-prefix (save-excursion
(goto-char start)
(if (re-search-forward "^\\([^.\n]+\\)\\." end t)
(match-string 1)
(error "No common prefix found")))))
(save-excursion
(goto-char start)
(insert common-prefix " = {\n")
(goto-char (+ end (length common-prefix) 6))
(insert "};\n")
(goto-char start)
(while (re-search-forward (concat "^" (regexp-quote common-prefix) "\\.") end t)
(replace-match ""))))))
#+end_src
*** Custom Keybindings *** Custom Keybindings
:PROPERTIES: :PROPERTIES:
:CUSTOM_ID: h:2b827c27-0de7-45ed-9d9e-6c511e2c6bb5 :CUSTOM_ID: h:2b827c27-0de7-45ed-9d9e-6c511e2c6bb5