From 798b5bdaeaa2ddfe43c0ae7af3e9e2ae37815007 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 30 Apr 2020 16:29:12 -0400 Subject: [PATCH] Add +default-want-RET-continue-comments option For disabling comment continuation on RET. --- modules/config/default/autoload/text.el | 15 -------------- modules/config/default/config.el | 27 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/modules/config/default/autoload/text.el b/modules/config/default/autoload/text.el index 7c523817e..01141cc6e 100644 --- a/modules/config/default/autoload/text.el +++ b/modules/config/default/autoload/text.el @@ -50,21 +50,6 @@ If `buffer-file-name' isn't set, uses `default-directory'." (abbreviate-file-name 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 () "Delete back to the previous column of whitespace, or as much whitespace as diff --git a/modules/config/default/config.el b/modules/config/default/config.el index 8ed0cf535..bbfc1ade7 100644 --- a/modules/config/default/config.el +++ b/modules/config/default/config.el @@ -1,5 +1,8 @@ ;;; 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 (append '(minibuffer-local-map minibuffer-local-ns-map @@ -220,8 +223,28 @@ ;; f) do none of this when inside a string (advice-add #'delete-backward-char :override #'+default--delete-backward-char-a)) - ;; Makes `newline-and-indent' continue comments (and more reliably) - (advice-add #'newline-and-indent :override #'+default--newline-indent-and-continue-comments-a)) + ;; HACK Makes `newline-and-indent' continue comments (and more reliably). + ;; 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))) ;;