From a8bc85191b8a8f41f3570e49f550c34e5d4a77d7 Mon Sep 17 00:00:00 2001 From: Daniel Alejandro Tapia Date: Mon, 2 Dec 2024 00:51:39 -0500 Subject: [PATCH] change `move-over-)` to `move-over-)-or-wrap` so that if the mark is active, the region will be wrapped with parens and the point will be placed after the close paren, helpful if you don't need to add anything in the parens. could also be helpful if you use pareto mode. and the name is changed so that functionality is not hidden from the user an odd command, but one that seems like a logical counterpart to insert-()-or-wrap the difference between this patch and `insert-()-or-wrap` is that this one puts the point at the end, after the close paren. (when (point> end |current-point) (| is the point.) if we put the region around "current-point" and then execute this command, we will get "(when (point> end (current-point))" and then point will be to the right of the close paren. (when (point> end (current-point)|) (| is the point) and then we can execute this command (the region will not be active), and we will skip over the close paren and go to the next line. (when (point> end (current-point)) | (| is the point.) seems that it could be useful. --- src/ext/language-mode.lisp | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/ext/language-mode.lisp b/src/ext/language-mode.lisp index 027141e52..eb0cc56b4 100644 --- a/src/ext/language-mode.lisp +++ b/src/ext/language-mode.lisp @@ -93,7 +93,7 @@ (define-key *language-mode-keymap* "M-," 'pop-definition-stack) (define-key *language-mode-keymap* "C-M-i" 'complete-symbol) (define-key *global-keymap* "M-(" 'insert-\(\)-or-wrap) -(define-key *global-keymap* "M-)" 'move-over-\)) +(define-key *global-keymap* "M-)" 'move-over-\)-or-wrap) (defun beginning-of-defun-1 (n) (alexandria:when-let ((fn (variable-value 'beginning-of-defun-function :buffer))) @@ -505,16 +505,23 @@ (delete-character p) (character-offset p -1)))) -(define-command (move-over-\) (:advice-classes movable-advice editable-advice)) () () - (let ((rper (backward-search-rper))) - (if rper - (progn - (backward-delete-to-rper) - (scan-lists (current-point) 1 1 T) - (newline-and-indent 1)) - (progn - (scan-lists (current-point) 1 1 T) - (newline-and-indent 1))))) +(define-command (move-over-\)-or-wrap (:advice-classes movable-advice editable-advice)) () () + (if (mark-active-p (cursor-mark (current-point))) + (with-point ((start (cursor-region-beginning (current-point))) + (end (cursor-region-end (current-point)))) + (when (point> end (current-point)) + (exchange-point-mark)) + (insert-character end #\)) + (insert-character start #\()) + (let ((rper (backward-search-rper))) + (if rper + (progn + (backward-delete-to-rper) + (scan-lists (current-point) 1 1 T) + (newline-and-indent 1)) + (progn + (scan-lists (current-point) 1 1 T) + (newline-and-indent 1)))))) (defun match-pattern-p (pattern file) (etypecase pattern