Skip to content

Commit

Permalink
style: Use cond instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jcs090218 committed May 22, 2024
1 parent 26b9c3b commit 368f50c
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions vs-edit-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -186,30 +186,30 @@

(defun vs-edit-newline (func &rest args)
"Advice for function `newline' (FUNC and ARGS)."
(if (not vs-edit-mode)
(apply func args)
;; 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)
(save-excursion (newline-and-indent))))))
(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)
(save-excursion (newline-and-indent)))))
(t (apply func args))))

(defun vs-edit-newline-and-indent (func &rest args)
"Advice for function `newline-and-indent' (FUNC and ARGS)."
(if (not vs-edit-mode)
(apply func args)
;; XXX: Don't delete previous line' trailing whitespaces!
(noflet ((delete-horizontal-space (&rest _))) ; see function `newline-and-indent' implementation
(apply func args))))
(cond (vs-edit-mode
;; XXX: Don't delete previous line' trailing whitespaces!
(noflet ((delete-horizontal-space (&rest _))) ; see function `newline-and-indent' implementation
(apply func args)))
(t (apply func args))))

(defun vs-edit-opening-curly-bracket-key ()
"For programming langauge that need `{`."
Expand Down

0 comments on commit 368f50c

Please sign in to comment.