Mercurial > emacs
comparison lisp/newcomment.el @ 47212:5ddbbad82052
(comment-make-extra-lines): Only use the
dummy `=' char when there's really nothing else.
Don't remove spaces if it leads to an incorrect comment.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Tue, 03 Sep 2002 01:45:18 +0000 |
parents | a5e3d40d6003 |
children | 408ecff0939b |
comparison
equal
deleted
inserted
replaced
47211:3a7c7e0c12f7 | 47212:5ddbbad82052 |
---|---|
27 | 27 |
28 ;; A replacement for simple.el's comment-related functions. | 28 ;; A replacement for simple.el's comment-related functions. |
29 | 29 |
30 ;;; Bugs: | 30 ;;; Bugs: |
31 | 31 |
32 ;; - boxed comments in Perl are not properly uncommented because they are | |
33 ;; uncommented one-line at a time. | |
32 ;; - nested comments in sgml-mode are not properly quoted. | 34 ;; - nested comments in sgml-mode are not properly quoted. |
33 ;; - single-char nestable comment-start can only do the "\\s<+" stuff | 35 ;; - single-char nestable comment-start can only do the "\\s<+" stuff |
34 ;; if the corresponding closing marker happens to be right. | 36 ;; if the corresponding closing marker happens to be right. |
35 ;; - comment-box in TeXinfo generate bogus comments @ccccc@ | 37 ;; - comment-box in TeXinfo generate bogus comments @ccccc@ |
36 ;; - uncomment-region with a numeric argument can render multichar | 38 ;; - uncomment-region with a numeric argument can render multichar |
41 ;; markers if there are more than just comment-start and comment-end. | 43 ;; markers if there are more than just comment-start and comment-end. |
42 ;; For example, in Pascal where {...*) and (*...} are possible. | 44 ;; For example, in Pascal where {...*) and (*...} are possible. |
43 | 45 |
44 ;;; Todo: | 46 ;;; Todo: |
45 | 47 |
46 ;; - quantized steps in comment-alignment | 48 ;; - rebox.el-style refill. |
47 ;; - try to align tail comments | 49 ;; - quantized steps in comment-alignment. |
48 ;; - check what c-comment-line-break-function has to say | 50 ;; - try to align tail comments. |
49 ;; - spill auto-fill of comments onto the end of the next line | 51 ;; - check what c-comment-line-break-function has to say. |
52 ;; - spill auto-fill of comments onto the end of the next line. | |
50 ;; - uncomment-region with a consp (for blocks) or somehow make the | 53 ;; - uncomment-region with a consp (for blocks) or somehow make the |
51 ;; deletion of continuation markers less dangerous | 54 ;; deletion of continuation markers less dangerous. |
52 ;; - drop block-comment-<foo> unless it's really used | 55 ;; - drop block-comment-<foo> unless it's really used. |
53 ;; - uncomment-region on a subpart of a comment | 56 ;; - uncomment-region on a subpart of a comment. |
54 ;; - support gnu-style "multi-line with space in continue" | 57 ;; - support gnu-style "multi-line with space in continue". |
55 ;; - somehow allow comment-dwim to use the region even if transient-mark-mode | 58 ;; - somehow allow comment-dwim to use the region even if transient-mark-mode |
56 ;; is not turned on. | 59 ;; is not turned on. |
57 | 60 |
58 ;; - when auto-filling a comment, try to move the comment to the left | 61 ;; - when auto-filling a comment, try to move the comment to the left |
59 ;; rather than break it (if possible). | 62 ;; rather than break it (if possible). |
704 ;; box comment | 707 ;; box comment |
705 (let* ((width (- max-indent min-indent)) | 708 (let* ((width (- max-indent min-indent)) |
706 (s (concat cs "a=m" cce)) | 709 (s (concat cs "a=m" cce)) |
707 (e (concat ccs "a=m" ce)) | 710 (e (concat ccs "a=m" ce)) |
708 (c (if (string-match ".*\\S-\\S-" cs) | 711 (c (if (string-match ".*\\S-\\S-" cs) |
709 (aref cs (1- (match-end 0))) ?=)) | 712 (aref cs (1- (match-end 0))) |
710 (_ (string-match "\\s-*a=m\\s-*" s)) | 713 (if (and (equal comment-end "") (string-match ".*\\S-" cs)) |
714 (aref cs (1- (match-end 0))) ?=))) | |
715 (re "\\s-*a=m\\s-*") | |
716 (_ (string-match re s)) | |
717 (lcs (length cs)) | |
711 (fill | 718 (fill |
712 (make-string (+ width (- (match-end 0) | 719 (make-string (+ width (- (match-end 0) |
713 (match-beginning 0) (length cs) 3)) c))) | 720 (match-beginning 0) lcs 3)) c))) |
714 (setq cs (replace-match fill t t s)) | 721 (setq cs (replace-match fill t t s)) |
715 (string-match "\\s-*a=m\\s-*" e) | 722 (when (and (not (string-match comment-start-skip cs)) |
723 (string-match "a=m" s)) | |
724 ;; The whitespace around CS cannot be ignored: put it back. | |
725 (setq re "a=m") | |
726 (setq fill (make-string (- width lcs) c)) | |
727 (setq cs (replace-match fill t t s))) | |
728 (string-match re e) | |
716 (setq ce (replace-match fill t t e)))) | 729 (setq ce (replace-match fill t t e)))) |
717 (cons (concat cs "\n" (make-string min-indent ? ) ccs) | 730 (cons (concat cs "\n" (make-string min-indent ? ) ccs) |
718 (concat cce "\n" (make-string (+ min-indent eindent) ? ) ce)))) | 731 (concat cce "\n" (make-string (+ min-indent eindent) ? ) ce)))) |
719 | 732 |
720 (def-edebug-spec comment-with-narrowing t) | 733 (def-edebug-spec comment-with-narrowing t) |
747 (delete-char n) | 760 (delete-char n) |
748 (setq ,bindent (- ,bindent n))))))))))) | 761 (setq ,bindent (- ,bindent n))))))))))) |
749 | 762 |
750 (defun comment-region-internal (beg end cs ce | 763 (defun comment-region-internal (beg end cs ce |
751 &optional ccs cce block lines indent) | 764 &optional ccs cce block lines indent) |
752 "Comment region BEG..END. | 765 "Comment region BEG .. END. |
753 CS and CE are the comment start resp end string. | 766 CS and CE are the comment start resp end string. |
754 CCS and CCE are the comment continuation strings for the start resp end | 767 CCS and CCE are the comment continuation strings for the start resp end |
755 of lines (default to CS and CE). | 768 of lines (default to CS and CE). |
756 BLOCK indicates that end of lines should be marked with either CCE, CE or CS | 769 BLOCK indicates that end of lines should be marked with either CCE, CE or CS |
757 \(if CE is empty) and that those markers should be aligned. | 770 \(if CE is empty) and that those markers should be aligned. |
826 (not (or (eobp) (progn (forward-line) nil)))))))))) | 839 (not (or (eobp) (progn (forward-line) nil)))))))))) |
827 | 840 |
828 ;;;###autoload | 841 ;;;###autoload |
829 (defun comment-region (beg end &optional arg) | 842 (defun comment-region (beg end &optional arg) |
830 "Comment or uncomment each line in the region. | 843 "Comment or uncomment each line in the region. |
831 With just \\[universal-argument] prefix arg, uncomment each line in region BEG..END. | 844 With just \\[universal-argument] prefix arg, uncomment each line in region BEG .. END. |
832 Numeric prefix arg ARG means use ARG comment characters. | 845 Numeric prefix arg ARG means use ARG comment characters. |
833 If ARG is negative, delete that many comment characters instead. | 846 If ARG is negative, delete that many comment characters instead. |
834 By default, comments start at the left margin, are terminated on each line, | 847 By default, comments start at the left margin, are terminated on each line, |
835 even for syntax in which newline does not end the comment and blank lines | 848 even for syntax in which newline does not end the comment and blank lines |
836 do not get comments. This can be changed with `comment-style'. | 849 do not get comments. This can be changed with `comment-style'. |
890 block | 903 block |
891 lines | 904 lines |
892 (nth 3 style)))))) | 905 (nth 3 style)))))) |
893 | 906 |
894 (defun comment-box (beg end &optional arg) | 907 (defun comment-box (beg end &optional arg) |
895 "Comment out the BEG..END region, putting it inside a box. | 908 "Comment out the BEG .. END region, putting it inside a box. |
896 The numeric prefix ARG specifies how many characters to add to begin- and | 909 The numeric prefix ARG specifies how many characters to add to begin- and |
897 end- comment markers additionally to what `comment-add' already specifies." | 910 end- comment markers additionally to what `comment-add' already specifies." |
898 (interactive "*r\np") | 911 (interactive "*r\np") |
899 (let ((comment-style (if (cadr (assoc comment-style comment-styles)) | 912 (let ((comment-style (if (cadr (assoc comment-style comment-styles)) |
900 'box-multi 'box))) | 913 'box-multi 'box))) |