diff options
author | Lars Ingebrigtsen <larsi@gnus.org> | 2021-01-28 07:09:18 +0100 |
---|---|---|
committer | Lars Ingebrigtsen <larsi@gnus.org> | 2021-01-28 07:09:18 +0100 |
commit | 0870ebb3cbfcb097d85eea5eacaf992dd88ed204 (patch) | |
tree | da7970460e8e52b6335e54426fdcfbf26b220ffe | |
parent | e4c667079086528c6e0a9eead9c2d4d5f5b7c6e1 (diff) | |
download | emacs-0870ebb3cbfcb097d85eea5eacaf992dd88ed204.tar.gz |
Allow commenting out white space lines in latex-mode
* lisp/newcomment.el (comment-region-default-1): Allow commenting
out whitespace-only regions (bug#41793).
* lisp/textmodes/tex-mode.el (latex--comment-region): Use it.
(latex-mode): Set a comment style shim.
-rw-r--r-- | lisp/newcomment.el | 30 | ||||
-rw-r--r-- | lisp/textmodes/tex-mode.el | 7 |
2 files changed, 27 insertions, 10 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el index 5d0d1053f4b..4216fc1a397 100644 --- a/lisp/newcomment.el +++ b/lisp/newcomment.el @@ -1221,21 +1221,33 @@ changed with `comment-style'." ;; FIXME: maybe we should call uncomment depending on ARG. (funcall comment-region-function beg end arg))) -(defun comment-region-default-1 (beg end &optional arg) +(defun comment-region-default-1 (beg end &optional arg noadjust) + "Comment region between BEG and END. +See `comment-region' for ARG. If NOADJUST, do not skip past +leading/trailing space when determining the region to comment +out." (let* ((numarg (prefix-numeric-value arg)) (style (cdr (assoc comment-style comment-styles))) (lines (nth 2 style)) (block (nth 1 style)) (multi (nth 0 style))) - ;; We use `chars' instead of `syntax' because `\n' might be - ;; of end-comment syntax rather than of whitespace syntax. - ;; sanitize BEG and END - (goto-char beg) (skip-chars-forward " \t\n\r") (beginning-of-line) - (setq beg (max beg (point))) - (goto-char end) (skip-chars-backward " \t\n\r") (end-of-line) - (setq end (min end (point))) - (if (>= beg end) (error "Nothing to comment")) + (if noadjust + (when (bolp) + (setq end (1- end))) + ;; We use `chars' instead of `syntax' because `\n' might be + ;; of end-comment syntax rather than of whitespace syntax. + ;; sanitize BEG and END + (goto-char beg) + (skip-chars-forward " \t\n\r") + (beginning-of-line) + (setq beg (max beg (point))) + (goto-char end) + (skip-chars-backward " \t\n\r") + (end-of-line) + (setq end (min end (point))) + (when (>= beg end) + (error "Nothing to comment"))) ;; sanitize LINES (setq lines diff --git a/lisp/textmodes/tex-mode.el b/lisp/textmodes/tex-mode.el index c4e4864da17..ce665e61656 100644 --- a/lisp/textmodes/tex-mode.el +++ b/lisp/textmodes/tex-mode.el @@ -1169,7 +1169,12 @@ subshell is initiated, `tex-shell-hook' is run." (setq-local outline-regexp latex-outline-regexp) (setq-local outline-level #'latex-outline-level) (setq-local forward-sexp-function #'latex-forward-sexp) - (setq-local skeleton-end-hook nil)) + (setq-local skeleton-end-hook nil) + (setq-local comment-region-function #'latex--comment-region) + (setq-local comment-style 'plain)) + +(defun latex--comment-region (beg end &optional arg) + (comment-region-default-1 beg end arg t)) ;;;###autoload (define-derived-mode slitex-mode latex-mode "SliTeX" |