feature/evil: fix evil-change recommenting line
Due to a bug crossing over from +evil-want-o/O-continue-comments functionality. It has also been refactored for performance. This also fixes an issue where smartparens functions could be called before smartparens was loaded, making o/O inoperable.
This commit is contained in:
parent
0f901b560f
commit
c0ff5b030a
1 changed files with 52 additions and 50 deletions
|
@ -139,15 +139,16 @@ line with a linewise comment.")
|
|||
|
||||
;; Make o/O continue comments
|
||||
(defun +evil*insert-newline-above-and-respect-comments (orig-fn count)
|
||||
(cl-letf* ((old-insert-newline-above (symbol-function 'evil-insert-newline-above))
|
||||
((symbol-function 'evil-insert-newline-above)
|
||||
(lambda ()
|
||||
(if (or (not +evil-want-o/O-to-continue-comments)
|
||||
(not (eq this-command 'evil-open-above))
|
||||
(evil-insert-state-p))
|
||||
(funcall old-insert-newline-above)
|
||||
(funcall orig-fn count)
|
||||
(cl-letf (((symbol-function 'evil-insert-newline-above)
|
||||
(lambda ()
|
||||
(let ((pos (save-excursion (beginning-of-line-text) (point))))
|
||||
(evil-narrow-to-field
|
||||
(if (save-excursion (nth 4 (syntax-ppss pos)))
|
||||
(require 'smartparens)
|
||||
(if (save-excursion (nth 4 (sp--syntax-ppss pos)))
|
||||
(evil-save-goal-column
|
||||
(setq evil-auto-indent nil)
|
||||
(goto-char pos)
|
||||
|
@ -167,21 +168,22 @@ line with a linewise comment.")
|
|||
(evil-move-beginning-of-line)
|
||||
(insert (if use-hard-newlines hard-newline "\n"))
|
||||
(forward-line -1)
|
||||
(back-to-indentation))))))))
|
||||
(back-to-indentation)))))))
|
||||
(let ((evil-auto-indent evil-auto-indent))
|
||||
(funcall orig-fn count))))
|
||||
(funcall orig-fn count)))))
|
||||
(advice-add #'evil-open-above :around #'+evil*insert-newline-above-and-respect-comments)
|
||||
|
||||
(defun +evil*insert-newline-below-and-respect-comments (orig-fn count)
|
||||
(cl-letf* ((old-insert-newline-below (symbol-function 'evil-insert-newline-below))
|
||||
((symbol-function 'evil-insert-newline-below)
|
||||
(lambda ()
|
||||
(if (or (not +evil-want-o/O-to-continue-comments)
|
||||
(not (eq this-command 'evil-open-below))
|
||||
(evil-insert-state-p))
|
||||
(funcall old-insert-newline-below)
|
||||
(funcall orig-fn count)
|
||||
(cl-letf (((symbol-function 'evil-insert-newline-below)
|
||||
(lambda ()
|
||||
(let ((pos (save-excursion (beginning-of-line-text) (point))))
|
||||
(evil-narrow-to-field
|
||||
(evil-move-end-of-line)
|
||||
(require 'smartparens)
|
||||
(cond ((sp-point-in-comment pos)
|
||||
(setq evil-auto-indent nil)
|
||||
(if comment-line-break-function
|
||||
|
@ -189,9 +191,9 @@ line with a linewise comment.")
|
|||
(comment-indent-new-line)))
|
||||
(t
|
||||
(insert (if use-hard-newlines hard-newline "\n"))
|
||||
(back-to-indentation)))))))))
|
||||
(back-to-indentation))))))))
|
||||
(let ((evil-auto-indent evil-auto-indent))
|
||||
(funcall orig-fn count))))
|
||||
(funcall orig-fn count)))))
|
||||
(advice-add #'evil-open-below :around #'+evil*insert-newline-below-and-respect-comments)
|
||||
|
||||
;; --- custom interactive codes -----------
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue