[Refactor] Refactor enclose-region
Now it doesn’t create unnecessary global variables.
This commit is contained in:
parent
aa6e8495de
commit
8320e5708a
@ -282,40 +282,38 @@ copied to the kill ring."
|
|||||||
*** Enclose region in a specific character
|
*** Enclose region in a specific character
|
||||||
|
|
||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(defun æ-enclose-region (character &optional start end)
|
(defun gpolonkai/enclose-region (character &optional start end)
|
||||||
"Enclose region in CHARACTER. If region is empty, simply inserts
|
"Enclose region between CHARACTER.
|
||||||
CHARACTER two times and moves point between them.
|
|
||||||
|
|
||||||
If character is present in `insert-pair-alist', this function
|
If region is empty and neither START nor END is set, simply inserts CHARACTER
|
||||||
will enclose region in the corresponding pair. In this case,
|
two times and moves point between them.
|
||||||
CHARACTER must be the opening member of the pair."
|
|
||||||
|
If character is present in `insert-pair-alist', this function will enclose
|
||||||
|
region in the corresponding pair. In this case, CHARACTER must be the opening
|
||||||
|
member of the pair."
|
||||||
|
|
||||||
(interactive "cWhat character? \nr")
|
(interactive "cWhat character? \nr")
|
||||||
|
|
||||||
(setq open character close character)
|
(let ((open character)
|
||||||
|
(close character)
|
||||||
(let ((pair (assq character insert-pair-alist)))
|
(pair (assq character insert-pair-alist)))
|
||||||
(if pair
|
(if pair
|
||||||
(if (nth 2 pair)
|
(if (nth 2 pair)
|
||||||
(setq open (nth 1 pair) close (nth 2 pair))
|
(setq open (nth 1 pair) close (nth 2 pair))
|
||||||
(setq open (nth 0 pair) close (nth 1 pair)))))
|
(setq open (nth 0 pair) close (nth 1 pair))))
|
||||||
|
(unless (and open close)
|
||||||
|
(setq open character
|
||||||
|
close character))
|
||||||
|
(unless (use-region-p)
|
||||||
|
(setq start (point) end (point)))
|
||||||
|
(save-excursion
|
||||||
|
(goto-char end)
|
||||||
|
(insert-char close)
|
||||||
|
|
||||||
(unless (and open close)
|
(goto-char start)
|
||||||
(setq open character)
|
(insert-char open))
|
||||||
(setq close character))
|
(unless (use-region-p)
|
||||||
|
(forward-char))))
|
||||||
(unless (use-region-p)
|
|
||||||
(setq start (point) end (point)))
|
|
||||||
|
|
||||||
(save-excursion
|
|
||||||
(goto-char end)
|
|
||||||
(insert-char close)
|
|
||||||
|
|
||||||
(goto-char start)
|
|
||||||
(insert-char open))
|
|
||||||
|
|
||||||
(unless (use-region-p)
|
|
||||||
(forward-char)))
|
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
*** Convert camelCase to snake_case
|
*** Convert camelCase to snake_case
|
||||||
@ -3246,7 +3244,7 @@ directory. It is available from [[http://plantuml.com/download][here]].
|
|||||||
#+BEGIN_SRC emacs-lisp
|
#+BEGIN_SRC emacs-lisp
|
||||||
(bind-keys
|
(bind-keys
|
||||||
:map global-map
|
:map global-map
|
||||||
("M-(" . æ-enclose-region)
|
("M-(" . gpolonkai/enclose-region)
|
||||||
("<C-return>" . open-line-below)
|
("<C-return>" . open-line-below)
|
||||||
("<C-S-return>" . open-line-above)
|
("<C-S-return>" . open-line-above)
|
||||||
("M-t" . nil) ;; Remove the old keybinding
|
("M-t" . nil) ;; Remove the old keybinding
|
||||||
|
Loading…
Reference in New Issue
Block a user