aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2021-01-28 07:09:18 +0100
committerLars Ingebrigtsen2021-01-28 07:09:18 +0100
commit0870ebb3cbfcb097d85eea5eacaf992dd88ed204 (patch)
treeda7970460e8e52b6335e54426fdcfbf26b220ffe
parente4c667079086528c6e0a9eead9c2d4d5f5b7c6e1 (diff)
downloademacs-0870ebb3cbfcb097d85eea5eacaf992dd88ed204.tar.gz
emacs-0870ebb3cbfcb097d85eea5eacaf992dd88ed204.zip
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.el30
-rw-r--r--lisp/textmodes/tex-mode.el7
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'."
1221 ;; FIXME: maybe we should call uncomment depending on ARG. 1221 ;; FIXME: maybe we should call uncomment depending on ARG.
1222 (funcall comment-region-function beg end arg))) 1222 (funcall comment-region-function beg end arg)))
1223 1223
1224(defun comment-region-default-1 (beg end &optional arg) 1224(defun comment-region-default-1 (beg end &optional arg noadjust)
1225 "Comment region between BEG and END.
1226See `comment-region' for ARG. If NOADJUST, do not skip past
1227leading/trailing space when determining the region to comment
1228out."
1225 (let* ((numarg (prefix-numeric-value arg)) 1229 (let* ((numarg (prefix-numeric-value arg))
1226 (style (cdr (assoc comment-style comment-styles))) 1230 (style (cdr (assoc comment-style comment-styles)))
1227 (lines (nth 2 style)) 1231 (lines (nth 2 style))
1228 (block (nth 1 style)) 1232 (block (nth 1 style))
1229 (multi (nth 0 style))) 1233 (multi (nth 0 style)))
1230 1234
1231 ;; We use `chars' instead of `syntax' because `\n' might be 1235 (if noadjust
1232 ;; of end-comment syntax rather than of whitespace syntax. 1236 (when (bolp)
1233 ;; sanitize BEG and END 1237 (setq end (1- end)))
1234 (goto-char beg) (skip-chars-forward " \t\n\r") (beginning-of-line) 1238 ;; We use `chars' instead of `syntax' because `\n' might be
1235 (setq beg (max beg (point))) 1239 ;; of end-comment syntax rather than of whitespace syntax.
1236 (goto-char end) (skip-chars-backward " \t\n\r") (end-of-line) 1240 ;; sanitize BEG and END
1237 (setq end (min end (point))) 1241 (goto-char beg)
1238 (if (>= beg end) (error "Nothing to comment")) 1242 (skip-chars-forward " \t\n\r")
1243 (beginning-of-line)
1244 (setq beg (max beg (point)))
1245 (goto-char end)
1246 (skip-chars-backward " \t\n\r")
1247 (end-of-line)
1248 (setq end (min end (point)))
1249 (when (>= beg end)
1250 (error "Nothing to comment")))
1239 1251
1240 ;; sanitize LINES 1252 ;; sanitize LINES
1241 (setq lines 1253 (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."
1169 (setq-local outline-regexp latex-outline-regexp) 1169 (setq-local outline-regexp latex-outline-regexp)
1170 (setq-local outline-level #'latex-outline-level) 1170 (setq-local outline-level #'latex-outline-level)
1171 (setq-local forward-sexp-function #'latex-forward-sexp) 1171 (setq-local forward-sexp-function #'latex-forward-sexp)
1172 (setq-local skeleton-end-hook nil)) 1172 (setq-local skeleton-end-hook nil)
1173 (setq-local comment-region-function #'latex--comment-region)
1174 (setq-local comment-style 'plain))
1175
1176(defun latex--comment-region (beg end &optional arg)
1177 (comment-region-default-1 beg end arg t))
1173 1178
1174;;;###autoload 1179;;;###autoload
1175(define-derived-mode slitex-mode latex-mode "SliTeX" 1180(define-derived-mode slitex-mode latex-mode "SliTeX"