fix(evil): evil-join fails to join commented lines

Fix #5558
This commit is contained in:
Henrik Lissner 2021-10-02 23:25:05 +02:00
parent 4903db036d
commit 45c759d7d7

View file

@ -183,27 +183,47 @@ more information on modifiers."
"Join the selected lines. "Join the selected lines.
This advice improves on `evil-join' by removing comment delimiters when joining This advice improves on `evil-join' by removing comment delimiters when joining
commented lines, by using `fill-region-as-paragraph'. commented lines, without `fill-region-as-paragraph'.
From https://github.com/emacs-evil/evil/issues/606" Adapted from https://github.com/emacs-evil/evil/issues/606"
;; But revert to the default we're not in a comment, where (if-let* (((not (= (line-end-position) (point-max))))
;; `fill-region-as-paragraph' is too greedy. (cend (save-excursion (goto-char end) (line-end-position)))
(if (not (doom-point-in-comment-p (min (max beg (1+ (point))) end))) (cbeg (save-excursion
(funcall fn beg end) (goto-char beg)
(and (doom-point-in-comment-p
(save-excursion
(goto-char (line-beginning-position 2))
(skip-syntax-forward " \t")
(point)))
(or (comment-search-backward (line-beginning-position) t)
(comment-search-forward (line-end-position) t)
(and (doom-point-in-comment-p beg)
(stringp comment-continue)
(or (search-forward comment-continue (line-end-position) t)
beg)))))))
(let* ((count (count-lines beg end)) (let* ((count (count-lines beg end))
(count (if (> count 1) (1- count) count)) (count (if (> count 1) (1- count) count))
(fixup-mark (make-marker))) (fixup-mark (make-marker)))
(uncomment-region (line-beginning-position 2)
(save-excursion
(goto-char cend)
(line-end-position 0)))
(unwind-protect (unwind-protect
(dotimes (var count) (dotimes (_ count)
(if (and (bolp) (eolp))
(join-line 1) (join-line 1)
(let* ((end (line-beginning-position 3)) (save-match-data
(fill-column (1+ (- end beg)))) (when (or (and comment-continue
(set-marker fixup-mark (line-end-position)) (not (string-empty-p comment-continue))
(fill-region-as-paragraph beg end nil t) (looking-at (concat "\\(\\s-*" (regexp-quote comment-continue) "\\) ")))
(goto-char fixup-mark) (and comment-start-skip
(fixup-whitespace)))) (not (string-empty-p comment-start-skip))
(set-marker fixup-mark nil))))) (looking-at (concat "\\(\\s-*" comment-start-skip "\\)"))))
(replace-match "" t nil nil 1)
(just-one-space))))
(set-marker fixup-mark nil)))
;; But revert to the default we're not in a comment, where
;; `fill-region-as-paragraph' is too greedy.
(funcall fn beg end)))
;;;###autoload ;;;###autoload
(defun +evil--fix-dabbrev-in-minibuffer-h () (defun +evil--fix-dabbrev-in-minibuffer-h ()