Add +default-want-RET-continue-comments option
For disabling comment continuation on RET.
This commit is contained in:
parent
a634e2c812
commit
798b5bdaea
2 changed files with 25 additions and 17 deletions
|
@ -50,21 +50,6 @@ If `buffer-file-name' isn't set, uses `default-directory'."
|
||||||
(abbreviate-file-name path)
|
(abbreviate-file-name path)
|
||||||
(file-name-nondirectory path)))))
|
(file-name-nondirectory path)))))
|
||||||
|
|
||||||
;;;###autoload
|
|
||||||
(defun +default--newline-indent-and-continue-comments-a ()
|
|
||||||
"A replacement for `newline-and-indent'.
|
|
||||||
|
|
||||||
Continues comments if executed from a commented line, with special support for
|
|
||||||
languages with weak native comment continuation support (like C-family
|
|
||||||
languages)."
|
|
||||||
(interactive)
|
|
||||||
(if (and (sp-point-in-comment)
|
|
||||||
comment-line-break-function)
|
|
||||||
(funcall comment-line-break-function nil)
|
|
||||||
(delete-horizontal-space t)
|
|
||||||
(newline nil t)
|
|
||||||
(indent-according-to-mode)))
|
|
||||||
|
|
||||||
|
|
||||||
(defun doom--backward-delete-whitespace-to-column ()
|
(defun doom--backward-delete-whitespace-to-column ()
|
||||||
"Delete back to the previous column of whitespace, or as much whitespace as
|
"Delete back to the previous column of whitespace, or as much whitespace as
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
;;; config/default/config.el -*- lexical-binding: t; -*-
|
;;; config/default/config.el -*- lexical-binding: t; -*-
|
||||||
|
|
||||||
|
(defvar +default-want-RET-continue-comments t
|
||||||
|
"If non-nil, RET will continue commented lines.")
|
||||||
|
|
||||||
(defvar +default-minibuffer-maps
|
(defvar +default-minibuffer-maps
|
||||||
(append '(minibuffer-local-map
|
(append '(minibuffer-local-map
|
||||||
minibuffer-local-ns-map
|
minibuffer-local-ns-map
|
||||||
|
@ -220,8 +223,28 @@
|
||||||
;; f) do none of this when inside a string
|
;; f) do none of this when inside a string
|
||||||
(advice-add #'delete-backward-char :override #'+default--delete-backward-char-a))
|
(advice-add #'delete-backward-char :override #'+default--delete-backward-char-a))
|
||||||
|
|
||||||
;; Makes `newline-and-indent' continue comments (and more reliably)
|
;; HACK Makes `newline-and-indent' continue comments (and more reliably).
|
||||||
(advice-add #'newline-and-indent :override #'+default--newline-indent-and-continue-comments-a))
|
;; Consults `doom-point-in-comment-functions' to detect a commented
|
||||||
|
;; region and uses that mode's `comment-line-break-function' to continue
|
||||||
|
;; comments. If neither exists, it will fall back to the normal behavior
|
||||||
|
;; of `newline-and-indent'.
|
||||||
|
;;
|
||||||
|
;; We use an advice here instead of a remapping because many modes define
|
||||||
|
;; and remap to their own newline-and-indent commands, and tackling all
|
||||||
|
;; those cases was judged to be more work than dealing with the edge
|
||||||
|
;; cases on a case by case basis.
|
||||||
|
(defadvice! +default--newline-indent-and-continue-comments-a (&rest _)
|
||||||
|
"A replacement for `newline-and-indent'.
|
||||||
|
|
||||||
|
Continues comments if executed from a commented line. Consults
|
||||||
|
`doom-point-in-comment-functions' to determine if in a comment."
|
||||||
|
:before-until #'newline-and-indent
|
||||||
|
(interactive "*")
|
||||||
|
(when (and +default-want-RET-continue-comments
|
||||||
|
(doom-point-in-comment-p)
|
||||||
|
(fboundp comment-line-break-function))
|
||||||
|
(funcall comment-line-break-function nil)
|
||||||
|
t)))
|
||||||
|
|
||||||
|
|
||||||
;;
|
;;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue