From 273448455d9fe53bff49153480eeffd24bc88521 Mon Sep 17 00:00:00 2001 From: Robert Burnett Date: Wed, 24 Jun 2026 19:21:51 -0500 Subject: [PATCH] refactor tab command --- src/ext/language-mode.lisp | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/ext/language-mode.lisp b/src/ext/language-mode.lisp index 573a6bd11..ccfecbf45 100644 --- a/src/ext/language-mode.lisp +++ b/src/ext/language-mode.lisp @@ -469,16 +469,26 @@ (lem/completion-mode:run-completion completion))) (define-command indent-line-and-complete-symbol () () - (if (variable-value 'calc-indent-function :buffer) - (let* ((p (current-point)) - (old (point-charpos p))) - (let ((charpos (point-charpos p))) - (handler-case (indent-line p) - (editor-condition () - (line-offset p 0 charpos)))) - (when (= old (point-charpos p)) - (complete-symbol))) - (complete-symbol))) + (cond + ;; If no ident function is defined then just complete-symbol + ((null (variable-value 'calc-indent-function :buffer)) + (complete-symbol)) + + ;; Else if there is a highlighted region indent the region + ((buffer-mark-p (current-buffer)) + (with-point ((start (region-beginning (current-buffer))) + (end (region-end (current-buffer)))) + (indent-points start end))) + + ;; Else indent the line and complete-symbol if the cursor doesn't move + (t (let* ((p (current-point)) + (old (point-charpos p)) + (charpos (point-charpos p))) + (handler-case (indent-line p) + (editor-condition () + (line-offset p 0 charpos))) + (when (= old (point-charpos p)) + (complete-symbol)))))) (define-command (insert-\(\)-or-wrap (:advice-classes editable-advice)) () () (if (mark-active-p (cursor-mark (current-point)))