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,59 +139,61 @@ line with a linewise comment.")
|
||||||
|
|
||||||
;; Make o/O continue comments
|
;; Make o/O continue comments
|
||||||
(defun +evil*insert-newline-above-and-respect-comments (orig-fn count)
|
(defun +evil*insert-newline-above-and-respect-comments (orig-fn count)
|
||||||
(cl-letf* ((old-insert-newline-above (symbol-function 'evil-insert-newline-above))
|
(if (or (not +evil-want-o/O-to-continue-comments)
|
||||||
((symbol-function 'evil-insert-newline-above)
|
(not (eq this-command 'evil-open-above))
|
||||||
(lambda ()
|
(evil-insert-state-p))
|
||||||
(if (or (not +evil-want-o/O-to-continue-comments)
|
(funcall orig-fn count)
|
||||||
(evil-insert-state-p))
|
(cl-letf (((symbol-function 'evil-insert-newline-above)
|
||||||
(funcall old-insert-newline-above)
|
(lambda ()
|
||||||
(let ((pos (save-excursion (beginning-of-line-text) (point))))
|
(let ((pos (save-excursion (beginning-of-line-text) (point))))
|
||||||
(evil-narrow-to-field
|
(evil-narrow-to-field
|
||||||
(if (save-excursion (nth 4 (syntax-ppss pos)))
|
(require 'smartparens)
|
||||||
(evil-save-goal-column
|
(if (save-excursion (nth 4 (sp--syntax-ppss pos)))
|
||||||
(setq evil-auto-indent nil)
|
(evil-save-goal-column
|
||||||
(goto-char pos)
|
(setq evil-auto-indent nil)
|
||||||
(let ((ws (abs (skip-chars-backward " \t"))))
|
(goto-char pos)
|
||||||
;; FIXME oh god why
|
(let ((ws (abs (skip-chars-backward " \t"))))
|
||||||
(save-excursion
|
;; FIXME oh god why
|
||||||
(if comment-line-break-function
|
(save-excursion
|
||||||
(funcall comment-line-break-function)
|
(if comment-line-break-function
|
||||||
(comment-indent-new-line))
|
(funcall comment-line-break-function)
|
||||||
(when (and (derived-mode-p 'c-mode 'c++-mode 'objc-mode 'java-mode 'js2-mode)
|
(comment-indent-new-line))
|
||||||
(eq (char-after) ?/))
|
(when (and (derived-mode-p 'c-mode 'c++-mode 'objc-mode 'java-mode 'js2-mode)
|
||||||
(insert "*"))
|
(eq (char-after) ?/))
|
||||||
(insert
|
(insert "*"))
|
||||||
(make-string (max 0 (+ ws (skip-chars-backward " \t")))
|
(insert
|
||||||
32)))
|
(make-string (max 0 (+ ws (skip-chars-backward " \t")))
|
||||||
(insert (make-string (max 1 ws) 32))))
|
32)))
|
||||||
(evil-move-beginning-of-line)
|
(insert (make-string (max 1 ws) 32))))
|
||||||
(insert (if use-hard-newlines hard-newline "\n"))
|
(evil-move-beginning-of-line)
|
||||||
(forward-line -1)
|
(insert (if use-hard-newlines hard-newline "\n"))
|
||||||
(back-to-indentation))))))))
|
(forward-line -1)
|
||||||
(let ((evil-auto-indent evil-auto-indent))
|
(back-to-indentation)))))))
|
||||||
(funcall orig-fn count))))
|
(let ((evil-auto-indent evil-auto-indent))
|
||||||
|
(funcall orig-fn count)))))
|
||||||
(advice-add #'evil-open-above :around #'+evil*insert-newline-above-and-respect-comments)
|
(advice-add #'evil-open-above :around #'+evil*insert-newline-above-and-respect-comments)
|
||||||
|
|
||||||
(defun +evil*insert-newline-below-and-respect-comments (orig-fn count)
|
(defun +evil*insert-newline-below-and-respect-comments (orig-fn count)
|
||||||
(cl-letf* ((old-insert-newline-below (symbol-function 'evil-insert-newline-below))
|
(if (or (not +evil-want-o/O-to-continue-comments)
|
||||||
((symbol-function 'evil-insert-newline-below)
|
(not (eq this-command 'evil-open-below))
|
||||||
(lambda ()
|
(evil-insert-state-p))
|
||||||
(if (or (not +evil-want-o/O-to-continue-comments)
|
(funcall orig-fn count)
|
||||||
(evil-insert-state-p))
|
(cl-letf (((symbol-function 'evil-insert-newline-below)
|
||||||
(funcall old-insert-newline-below)
|
(lambda ()
|
||||||
(let ((pos (save-excursion (beginning-of-line-text) (point))))
|
(let ((pos (save-excursion (beginning-of-line-text) (point))))
|
||||||
(evil-narrow-to-field
|
(evil-narrow-to-field
|
||||||
(evil-move-end-of-line)
|
(evil-move-end-of-line)
|
||||||
(cond ((sp-point-in-comment pos)
|
(require 'smartparens)
|
||||||
(setq evil-auto-indent nil)
|
(cond ((sp-point-in-comment pos)
|
||||||
(if comment-line-break-function
|
(setq evil-auto-indent nil)
|
||||||
(funcall comment-line-break-function)
|
(if comment-line-break-function
|
||||||
(comment-indent-new-line)))
|
(funcall comment-line-break-function)
|
||||||
(t
|
(comment-indent-new-line)))
|
||||||
(insert (if use-hard-newlines hard-newline "\n"))
|
(t
|
||||||
(back-to-indentation)))))))))
|
(insert (if use-hard-newlines hard-newline "\n"))
|
||||||
(let ((evil-auto-indent evil-auto-indent))
|
(back-to-indentation))))))))
|
||||||
(funcall orig-fn count))))
|
(let ((evil-auto-indent evil-auto-indent))
|
||||||
|
(funcall orig-fn count)))))
|
||||||
(advice-add #'evil-open-below :around #'+evil*insert-newline-below-and-respect-comments)
|
(advice-add #'evil-open-below :around #'+evil*insert-newline-below-and-respect-comments)
|
||||||
|
|
||||||
;; --- custom interactive codes -----------
|
;; --- custom interactive codes -----------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue