Skip to content

Commit

Permalink
fix: newline get called multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed May 22, 2024
1 parent 368f50c commit 10fd369
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions vs-edit-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -187,19 +187,19 @@
(defun vs-edit-newline (func &rest args)
"Advice for function `newline' (FUNC and ARGS)."
(cond (vs-edit-mode
;; XXX: Make sure indent on the empty line.
(when (vs-edit--current-line-totally-empty-p) (indent-for-tab-command))
;; XXX: Maintain same indentation for the previous line.
(let ((ln-cur (buffer-substring (line-beginning-position) (point))))
(apply func args)
(save-excursion
(forward-line -1)
(when (vs-edit--current-line-totally-empty-p) (insert ln-cur))))
;; XXX: Make sure brackets on newline!
(when (or (string= "}" (string-trim (thing-at-point 'line)))
(and (derived-mode-p 'sgml-mode)
(vs-edit--tag-on-line-p)))
(let (vs-edit-mode)
(let (vs-edit-mode)
;; XXX: Make sure indent on the empty line.
(when (vs-edit--current-line-totally-empty-p) (indent-for-tab-command))
;; XXX: Maintain same indentation for the previous line.
(let ((ln-cur (buffer-substring (line-beginning-position) (point))))
(apply func args)
(save-excursion
(forward-line -1)
(when (vs-edit--current-line-totally-empty-p) (insert ln-cur))))
;; XXX: Make sure brackets on newline!
(when (or (string= "}" (string-trim (thing-at-point 'line)))
(and (derived-mode-p 'sgml-mode)
(vs-edit--tag-on-line-p)))
(save-excursion (newline-and-indent)))))
(t (apply func args))))

Expand Down

0 comments on commit 10fd369

Please sign in to comment.