diff --git a/modules/editor/evil/autoload/advice.el b/modules/editor/evil/autoload/advice.el index bdf2ce8f9..51d0d3a9f 100644 --- a/modules/editor/evil/autoload/advice.el +++ b/modules/editor/evil/autoload/advice.el @@ -176,6 +176,29 @@ more information on modifiers." (balance-windows (window-parent))) (if file (evil-edit file))) +;;;###autoload (autoload '+evil-join-a "editor/evil/autoload/advice" nil nil) +(evil-define-operator +evil-join-a (beg end) + "Join the selected lines. + +This advice improves on `evil-join' by removing comment delimiters when joining +commented lines, by using `fill-region-as-paragraph'. + +From https://github.com/emacs-evil/evil/issues/606" + :motion evil-line + (let* ((count (count-lines beg end)) + (count (if (> count 1) (1- count) count)) + (fixup-mark (make-marker))) + (dotimes (var count) + (if (and (bolp) (eolp)) + (join-line 1) + (let* ((end (line-beginning-position 3)) + (fill-column (1+ (- end beg)))) + (set-marker fixup-mark (line-end-position)) + (fill-region-as-paragraph beg end nil t) + (goto-char fixup-mark) + (fixup-whitespace)))) + (set-marker fixup-mark nil))) + ;;;###autoload (defun +evil--fix-dabbrev-in-minibuffer-h () "Make `try-expand-dabbrev' from `hippie-expand' work in minibuffer. See diff --git a/modules/editor/evil/config.el b/modules/editor/evil/config.el index 836380bff..229801bee 100644 --- a/modules/editor/evil/config.el +++ b/modules/editor/evil/config.el @@ -155,6 +155,9 @@ directives. By default, this only recognizes C directives.") (run-at-time 0.1 nil #'helpful-key key-sequence) (abort-recursive-edit))) + ;; Make J (evil-join) remove comment delimiters when joining lines. + (advice-add #'evil-join :override #'+evil-join-a) + ;; Make ESC (from normal mode) the universal escaper. See `doom-escape-hook'. (advice-add #'evil-force-normal-state :after #'+evil-escape-a)