aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2001-10-11 01:46:37 +0000
committerStefan Monnier2001-10-11 01:46:37 +0000
commit7164ef13a82e9cf2a1a4db6d1966f9d047bef041 (patch)
tree29126ed336107ca7c770f3d49d13e30a6ad53f34
parent525742d91b3e0c430e80572bba287c0728b724eb (diff)
downloademacs-7164ef13a82e9cf2a1a4db6d1966f9d047bef041.tar.gz
emacs-7164ef13a82e9cf2a1a4db6d1966f9d047bef041.zip
(comment-indent): Be a little more robust in case
comment-indent-function does funny things. (comment-normalize-vars): Autoload. (comment-region-internal): Fiddle with the visibility spec. (comment-valid-prefix): New function. (comment-indent-new-line): Use it. Ignore adaptive-fill-prefixes that would turn comment-text into non-comment-text.
-rw-r--r--lisp/ChangeLog12
-rw-r--r--lisp/newcomment.el50
2 files changed, 50 insertions, 12 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index d15eb5392fd..aa598240275 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -6,6 +6,16 @@
6 6
72001-10-10 Stefan Monnier <monnier@cs.yale.edu> 72001-10-10 Stefan Monnier <monnier@cs.yale.edu>
8 8
9 * newcomment.el (comment-indent): Be a little more robust in case
10 comment-indent-function does funny things.
11 (comment-normalize-vars): Autoload.
12 (comment-region-internal): Fiddle with the visibility spec.
13 (comment-valid-prefix): New function.
14 (comment-indent-new-line): Use it. Ignore adaptive-fill-prefixes
15 that would turn comment-text into non-comment-text.
16
17 * emacs-lisp/syntax.el: New file.
18
9 * progmodes/tcl.el: Change maintainer to FSF and remove loads of 19 * progmodes/tcl.el: Change maintainer to FSF and remove loads of
10 compatibility cruft. 20 compatibility cruft.
11 (tcl-using-emacs-19, tcl-using-emacs-19-23, tcl-using-xemacs-19) 21 (tcl-using-emacs-19, tcl-using-emacs-19-23, tcl-using-xemacs-19)
@@ -421,7 +431,7 @@
4212001-10-04 Gerd Moellmann <gerd@gnu.org> 4312001-10-04 Gerd Moellmann <gerd@gnu.org>
422 432
423 * Branch for 21.1. 433 * Branch for 21.1.
424 434
4252001-10-03 Stefan Monnier <monnier@cs.yale.edu> 4352001-10-03 Stefan Monnier <monnier@cs.yale.edu>
426 436
427 * pcvs-util.el (cvs-prefix-define): Typo cons->concat. 437 * pcvs-util.el (cvs-prefix-define): Typo cons->concat.
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index 0ed7bb412a9..3a30285c904 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -5,7 +5,7 @@
5;; Author: code extracted from Emacs-20's simple.el 5;; Author: code extracted from Emacs-20's simple.el
6;; Maintainer: Stefan Monnier <monnier@cs.yale.edu> 6;; Maintainer: Stefan Monnier <monnier@cs.yale.edu>
7;; Keywords: comment uncomment 7;; Keywords: comment uncomment
8;; Revision: $Id: newcomment.el,v 1.34 2001/09/01 21:23:17 monnier Exp $ 8;; Revision: $Id: newcomment.el,v 1.35 2001/09/27 21:13:44 monnier Exp $
9 9
10;; This file is part of GNU Emacs. 10;; This file is part of GNU Emacs.
11 11
@@ -203,6 +203,7 @@ This is obsolete because you might as well use \\[newline-and-indent]."
203 "Return the mirror image of string S, without any trailing space." 203 "Return the mirror image of string S, without any trailing space."
204 (comment-string-strip (concat (nreverse (string-to-list s))) nil t)) 204 (comment-string-strip (concat (nreverse (string-to-list s))) nil t))
205 205
206;;;###autoload
206(defun comment-normalize-vars (&optional noerror) 207(defun comment-normalize-vars (&optional noerror)
207 (if (not comment-start) (or noerror (error "No comment syntax is defined")) 208 (if (not comment-start) (or noerror (error "No comment syntax is defined"))
208 ;; comment-use-syntax 209 ;; comment-use-syntax
@@ -228,7 +229,11 @@ This is obsolete because you might as well use \\[newline-and-indent]."
228 (unless (or comment-continue (string= comment-end "")) 229 (unless (or comment-continue (string= comment-end ""))
229 (set (make-local-variable 'comment-continue) 230 (set (make-local-variable 'comment-continue)
230 (concat (if (string-match "\\S-\\S-" comment-start) " " "|") 231 (concat (if (string-match "\\S-\\S-" comment-start) " " "|")
231 (substring comment-start 1)))) 232 (substring comment-start 1)))
233 ;; Hasn't been necessary yet.
234 ;; (unless (string-match comment-start-skip comment-continue)
235 ;; (kill-local-variable 'comment-continue))
236 )
232 ;; comment-skip regexps 237 ;; comment-skip regexps
233 (unless comment-start-skip 238 (unless comment-start-skip
234 (set (make-local-variable 'comment-start-skip) 239 (set (make-local-variable 'comment-start-skip)
@@ -466,11 +471,9 @@ If CONTINUE is non-nil, use the `comment-continue' markers if any."
466 (+ (current-column) 471 (+ (current-column)
467 (- fill-column 472 (- fill-column
468 (save-excursion (end-of-line) (current-column)))))) 473 (save-excursion (end-of-line) (current-column))))))
469 (if (= (current-column) indent) 474 (unless (= (current-column) indent)
470 (goto-char begpos)
471 ;; If that's different from current, change it. 475 ;; If that's different from current, change it.
472 (skip-chars-backward " \t") 476 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
473 (delete-region (point) begpos)
474 (indent-to (if (bolp) indent 477 (indent-to (if (bolp) indent
475 (max indent (1+ (current-column))))))) 478 (max indent (1+ (current-column)))))))
476 (goto-char cpos) 479 (goto-char cpos)
@@ -762,7 +765,14 @@ rather than at left margin."
762 (unless (or ce (eolp)) (insert "\n") (indent-according-to-mode)) 765 (unless (or ce (eolp)) (insert "\n") (indent-according-to-mode))
763 (comment-with-narrowing beg end 766 (comment-with-narrowing beg end
764 (let ((min-indent (point-max)) 767 (let ((min-indent (point-max))
765 (max-indent 0)) 768 (max-indent 0)
769 ;; We rebind the invisibility spec because move-to-column
770 ;; skips invisible text. Only reveal ellipses.
771 (buffer-invisibility-spec
772 (if (listp buffer-invisibility-spec)
773 (mapcar (lambda (x) (if (cdr-safe x) t x))
774 buffer-invisibility-spec)
775 buffer-invisibility-spec)))
766 (goto-char (point-min)) 776 (goto-char (point-min))
767 ;; Quote any nested comment marker 777 ;; Quote any nested comment marker
768 (comment-quote-nested comment-start comment-end nil) 778 (comment-quote-nested comment-start comment-end nil)
@@ -921,6 +931,14 @@ This has no effect in modes that do not define a comment syntax."
921 :type 'boolean 931 :type 'boolean
922 :group 'comment) 932 :group 'comment)
923 933
934(defun comment-valid-prefix (prefix compos)
935 (or
936 ;; Accept any prefix if the current comment is not EOL-terminated.
937 (save-excursion (goto-char compos) (comment-forward) (not (bolp)))
938 ;; Accept any prefix that starts with a comment-start marker.
939 (string-match (concat "\\`[ \t]*\\(?:" comment-start-skip "\\)")
940 fill-prefix)))
941
924;;;###autoload 942;;;###autoload
925(defun comment-indent-new-line (&optional soft) 943(defun comment-indent-new-line (&optional soft)
926 "Break line at point and indent, continuing comment if within one. 944 "Break line at point and indent, continuing comment if within one.
@@ -950,7 +968,8 @@ unless optional argument SOFT is non-nil."
950 ;; Now we know we should auto-fill. 968 ;; Now we know we should auto-fill.
951 (delete-horizontal-space) 969 (delete-horizontal-space)
952 (if soft (insert-and-inherit ?\n) (newline 1)) 970 (if soft (insert-and-inherit ?\n) (newline 1))
953 (if fill-prefix 971 (if (and fill-prefix (not adaptive-fill-mode))
972 ;; Blindly trust a non-adaptive fill-prefix.
954 (progn 973 (progn
955 (indent-to-left-margin) 974 (indent-to-left-margin)
956 (insert-and-inherit fill-prefix)) 975 (insert-and-inherit fill-prefix))
@@ -962,8 +981,17 @@ unless optional argument SOFT is non-nil."
962 (setq compos (comment-beginning)) 981 (setq compos (comment-beginning))
963 (setq comin (point)))) 982 (setq comin (point))))
964 983
965 ;; If we're not inside a comment, just try to indent. 984 (cond
966 (if (not compos) (indent-according-to-mode) 985 ;; If there's an adaptive prefix, use it unless we're inside
986 ;; a comment and the prefix is not a comment starter.
987 ((and fill-prefix
988 (or (not compos)
989 (comment-valid-prefix fill-prefix compos)))
990 (indent-to-left-margin)
991 (insert-and-inherit fill-prefix))
992 ;; If we're not inside a comment, just try to indent.
993 ((not compos) (indent-according-to-mode))
994 (t
967 (let* ((comment-column 995 (let* ((comment-column
968 ;; The continuation indentation should be somewhere between 996 ;; The continuation indentation should be somewhere between
969 ;; the current line's indentation (plus 2 for good measure) 997 ;; the current line's indentation (plus 2 for good measure)
@@ -1006,7 +1034,7 @@ unless optional argument SOFT is non-nil."
1006 (beginning-of-line) 1034 (beginning-of-line)
1007 (backward-char) 1035 (backward-char)
1008 (insert comend) 1036 (insert comend)
1009 (forward-char)))))))))) 1037 (forward-char)))))))))))
1010 1038
1011(provide 'newcomment) 1039(provide 'newcomment)
1012 1040