aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2000-05-17 19:32:32 +0000
committerStefan Monnier2000-05-17 19:32:32 +0000
commit392f1ef546dfc7341999a2683ca63221f985de1c (patch)
treeb79c5b70422e9bb6767d2489b68e4d4b6a34c175
parented9df7049842d3e52a69a7488ad4e359a399e56d (diff)
downloademacs-392f1ef546dfc7341999a2683ca63221f985de1c.tar.gz
emacs-392f1ef546dfc7341999a2683ca63221f985de1c.zip
(comment-beginning): Handle unclosed comment.
(comment-auto-fill-only-comments): New var. (comment-indent-new-line): Obey comment-auto-fill-only-comments. Align with comment-column rather than previous comment if previous comment's indentation is greater than comment-column.
-rw-r--r--lisp/newcomment.el141
1 files changed, 85 insertions, 56 deletions
diff --git a/lisp/newcomment.el b/lisp/newcomment.el
index a5ff8b83e67..b08d2d2bebc 100644
--- a/lisp/newcomment.el
+++ b/lisp/newcomment.el
@@ -6,7 +6,7 @@
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;; Version: $Name: $ 8;; Version: $Name: $
9;; Revision: $Id: newcomment.el,v 1.8 2000/05/14 00:56:10 monnier Exp $ 9;; Revision: $Id: newcomment.el,v 1.9 2000/05/16 22:02:37 monnier Exp $
10 10
11;; This program is free software; you can redistribute it and/or modify 11;; This program is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by 12;; it under the terms of the GNU General Public License as published by
@@ -321,7 +321,9 @@ the same as `comment-search-forward'."
321 (let ((pt (point)) 321 (let ((pt (point))
322 (cs (comment-search-backward nil t))) 322 (cs (comment-search-backward nil t)))
323 (when cs 323 (when cs
324 (if (save-excursion (goto-char cs) (comment-forward 1) (> (point) pt)) 324 (if (save-excursion
325 (goto-char cs)
326 (if (comment-forward 1) (> (point) pt) (eobp)))
325 cs 327 cs
326 (goto-char pt) 328 (goto-char pt)
327 nil)))) 329 nil))))
@@ -822,6 +824,12 @@ Else, call `comment-indent'."
822 (insert (comment-padleft comment-end add))) 824 (insert (comment-padleft comment-end add)))
823 (indent-according-to-mode)))))) 825 (indent-according-to-mode))))))
824 826
827(defcustom comment-auto-fill-only-comments nil
828 "Non-nil means to only auto-fill inside comments.
829This has no effect in modes that do not define a comment syntax."
830 :type 'boolean
831 :group 'comment)
832
825(defalias 'indent-new-comment-line 'comment-indent-new-line) 833(defalias 'indent-new-comment-line 'comment-indent-new-line)
826(defun comment-indent-new-line (&optional soft) 834(defun comment-indent-new-line (&optional soft)
827 "Break line at point and indent, continuing comment if within one. 835 "Break line at point and indent, continuing comment if within one.
@@ -839,65 +847,86 @@ The inserted newline is marked hard if variable `use-hard-newlines' is true,
839unless optional argument SOFT is non-nil." 847unless optional argument SOFT is non-nil."
840 (interactive) 848 (interactive)
841 (comment-normalize-vars t) 849 (comment-normalize-vars t)
842 (let (comcol comstart compt) 850 (let (comcol comstart compt comin)
843 (delete-region (progn (skip-chars-backward " \t") (point)) 851 (unless (and comment-start
844 (progn (skip-chars-forward " \t") (point))) 852 comment-auto-fill-only-comments
845 (if soft (insert-and-inherit ?\n) (newline 1)) 853 (not (save-excursion
846 (if fill-prefix 854 (prog1 (setq compt (comment-beginning))
847 (progn 855 (setq comin (point))))))
848 (indent-to-left-margin) 856 (delete-region (progn (skip-chars-backward " \t") (point))
849 (insert-and-inherit fill-prefix)) 857 (progn (skip-chars-forward " \t") (point)))
850 (unless comment-multi-line 858 (if soft (insert-and-inherit ?\n) (newline 1))
851 (save-excursion 859 (if fill-prefix
852 (backward-char) 860 (progn
853 (when (and comment-start 861 (indent-to-left-margin)
854 (setq compt (comment-beginning))) 862 (insert-and-inherit fill-prefix))
855 ;; The old line has a comment and point was inside the comment. 863 (unless comment-multi-line
856 ;; Indent this line like what we found. 864 (save-excursion
857 (setq comstart (buffer-substring compt (point))) 865 (backward-char)
858 (goto-char compt) 866 (when (and comment-start
859 (setq comcol (current-column))))) 867 (if compt (goto-char comin)
860 (if compt 868 (setq compt (comment-beginning))))
861 (let* ((comment-column comcol) 869 ;; The old line has a comment and point was inside the comment.
862 (normal-comment 870 ;; Indent this line like what we found.
863 (string-match (regexp-quote (comment-string-strip 871 (setq comstart (buffer-substring compt (point)))
864 comment-start t t)) 872 (goto-char compt)
865 comstart)) 873 (setq comcol (current-column)))))
866 ;; Force comment-continue to be recreated from comment-start. 874 (if compt
867 (comment-continue nil) ;(if normal-comment comment-continue) 875 (let* ((comment-column (min comcol comment-column))
868 (comment-end 876 (normal-comment
869 (if normal-comment comment-end 877 (string-match (regexp-quote (comment-string-strip
870 ;; The comment starter is not the normal comment-start 878 comment-start t t))
871 ;; so we can't just use comment-end. 879 comstart))
872 (save-excursion 880 ;; Force comment-continue to be recreated from comment-start.
873 (goto-char compt) 881 (comment-continue nil) ;(if normal-comment comment-continue)
874 (if (not (comment-forward)) comment-end 882 (comment-end
875 (comment-string-strip 883 (if normal-comment comment-end
876 (buffer-substring 884 ;; The comment starter is not the normal comment-start
877 (save-excursion (comment-enter-backward) (point)) 885 ;; so we can't just use comment-end.
878 (point)) 886 (save-excursion
879 nil t))))) 887 (goto-char compt)
880 (comment-start comstart)) 888 (if (not (comment-forward)) comment-end
881 ;;(if (not (eolp)) (setq comment-end "")) 889 (comment-string-strip
882 (insert-and-inherit ?\n) 890 (buffer-substring
883 (forward-char -1) 891 (save-excursion (comment-enter-backward) (point))
884 (comment-indent (cadr (assoc comment-style comment-styles))) 892 (point))
885 (save-excursion 893 nil t)))))
886 (let ((pt (point))) 894 (comment-start comstart))
887 (end-of-line) 895 ;;(if (not (eolp)) (setq comment-end ""))
888 (let ((comend (buffer-substring pt (point)))) 896 (insert-and-inherit ?\n)
889 ;; The 1+ is to make sure we delete the \n inserted above. 897 (forward-char -1)
890 (delete-region pt (1+ (point))) 898 (comment-indent (cadr (assoc comment-style comment-styles)))
891 (beginning-of-line) 899 (save-excursion
892 (backward-char) 900 (let ((pt (point)))
893 (insert comend) 901 (end-of-line)
894 (forward-char))))) 902 (let ((comend (buffer-substring pt (point))))
895 (indent-according-to-mode))))) 903 ;; The 1+ is to make sure we delete the \n inserted above.
904 (delete-region pt (1+ (point)))
905 (beginning-of-line)
906 (backward-char)
907 (insert comend)
908 (forward-char)))))
909 (indent-according-to-mode))))))
896 910
897(provide 'newcomment) 911(provide 'newcomment)
898 912
899;;; Change Log: 913;;; Change Log:
900;; $Log: newcomment.el,v $ 914;; $Log: newcomment.el,v $
915;; Revision 1.9 2000/05/16 22:02:37 monnier
916;; (comment-string-strip): Strip terminating newlines.
917;; (comment-search-forward): Make LIMIT compulsory.
918;; If an unterminated string (rather than a comment) is found, try again,
919;; assuming that the region starts inside a string.
920;; (comment-beginning): Make sure we don't move if we find a comment but
921;; it's not the one we're in.
922;; (comment-enter-backward): Handle the case where comment-end-skip fails.
923;; (comment-indent): Normalize variables and use line-end-position.
924;; (comment-kill): Use line-end-position.
925;; (comment-spill): Remove.
926;; (comment-indent-new-line): Renamed from indent-new-comment-line.
927;; Cleaned up old commented-out code.
928;; Reset comment-continue and comment-end before calling comment-indent.
929;;
901;; Revision 1.8 2000/05/14 00:56:10 monnier 930;; Revision 1.8 2000/05/14 00:56:10 monnier
902;; (comment-start, comment-start-skip, comment-end): Made `defvar'. 931;; (comment-start, comment-start-skip, comment-end): Made `defvar'.
903;; (comment-style): Extract the choice out of comment-styles. 932;; (comment-style): Extract the choice out of comment-styles.