Mercurial > emacs
comparison lisp/newcomment.el @ 50673:4b5928c8d588
(comment-normalize-vars): Fix regexp.
Prompt the user for the comment-start to use rather than signalling an error.
(uncomment-region): Don't leave half-removed comment markers.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Wed, 23 Apr 2003 14:55:19 +0000 |
parents | 8ec8f6706902 |
children | f9cbd74b1337 |
comparison
equal
deleted
inserted
replaced
50672:bc4caf3dd19d | 50673:4b5928c8d588 |
---|---|
209 "Return the mirror image of string S, without any trailing space." | 209 "Return the mirror image of string S, without any trailing space." |
210 (comment-string-strip (concat (nreverse (string-to-list s))) nil t)) | 210 (comment-string-strip (concat (nreverse (string-to-list s))) nil t)) |
211 | 211 |
212 ;;;###autoload | 212 ;;;###autoload |
213 (defun comment-normalize-vars (&optional noerror) | 213 (defun comment-normalize-vars (&optional noerror) |
214 (if (not comment-start) (or noerror (error "No comment syntax is defined")) | 214 (if (not comment-start) |
215 (unless noerror | |
216 (set (make-local-variable 'comment-start) | |
217 (read-string "No comment syntax is defined. Use: "))) | |
215 ;; comment-use-syntax | 218 ;; comment-use-syntax |
216 (when (eq comment-use-syntax 'undecided) | 219 (when (eq comment-use-syntax 'undecided) |
217 (set (make-local-variable 'comment-use-syntax) | 220 (set (make-local-variable 'comment-use-syntax) |
218 (let ((st (syntax-table)) | 221 (let ((st (syntax-table)) |
219 (cs comment-start) | 222 (cs comment-start) |
244 ;; comment-skip regexps | 247 ;; comment-skip regexps |
245 (unless (and comment-start-skip | 248 (unless (and comment-start-skip |
246 ;; In case comment-start has changed since last time. | 249 ;; In case comment-start has changed since last time. |
247 (string-match comment-start-skip comment-start)) | 250 (string-match comment-start-skip comment-start)) |
248 (set (make-local-variable 'comment-start-skip) | 251 (set (make-local-variable 'comment-start-skip) |
249 (concat "\\(\\(^\\|[^\\\\\n]\\)\\(\\\\\\\\\\)*\\)\\(\\s<+\\|" | 252 (concat "\\(\\(^\\|[^\\\n]\\)\\(\\\\\\\\\\)*\\)\\(\\s<+\\|" |
250 (regexp-quote (comment-string-strip comment-start t t)) | 253 (regexp-quote (comment-string-strip comment-start t t)) |
251 ;; Let's not allow any \s- but only [ \t] since \n | 254 ;; Let's not allow any \s- but only [ \t] since \n |
252 ;; might be both a comment-end marker and \s-. | 255 ;; might be both a comment-end marker and \s-. |
253 "+\\)[ \t]*"))) | 256 "+\\)[ \t]*"))) |
254 (unless (and comment-end-skip | 257 (unless (and comment-end-skip |
662 (goto-char (match-end 0))) | 665 (goto-char (match-end 0))) |
663 (when (and sre (looking-at (concat "\\s-*\n\\s-*" srei))) | 666 (when (and sre (looking-at (concat "\\s-*\n\\s-*" srei))) |
664 (goto-char (match-end 0))) | 667 (goto-char (match-end 0))) |
665 (if (null arg) (delete-region (point-min) (point)) | 668 (if (null arg) (delete-region (point-min) (point)) |
666 (skip-syntax-backward " ") | 669 (skip-syntax-backward " ") |
667 (delete-char (- numarg))) | 670 (delete-char (- numarg)) |
671 (unless (or (bobp) | |
672 (save-excursion (goto-char (point-min)) | |
673 (looking-at comment-start-skip))) | |
674 ;; If there's something left but it doesn't look like | |
675 ;; a comment-start any more, just remove it. | |
676 (delete-region (point-min) (point)))) | |
668 | 677 |
669 ;; Remove the end-comment (and leading padding and such). | 678 ;; Remove the end-comment (and leading padding and such). |
670 (goto-char (point-max)) (comment-enter-backward) | 679 (goto-char (point-max)) (comment-enter-backward) |
671 ;; Check for special `=' used sometimes in comment-box. | 680 ;; Check for special `=' used sometimes in comment-box. |
672 (when (and box-equal (not (eq (char-before (point-max)) ?\n))) | 681 (when (and box-equal (not (eq (char-before (point-max)) ?\n))) |
675 (when (> (skip-chars-backward "=") -7) (goto-char pos)))) | 684 (when (> (skip-chars-backward "=") -7) (goto-char pos)))) |
676 (unless (looking-at "\\(\n\\|\\s-\\)*\\'") | 685 (unless (looking-at "\\(\n\\|\\s-\\)*\\'") |
677 (when (and (bolp) (not (bobp))) (backward-char)) | 686 (when (and (bolp) (not (bobp))) (backward-char)) |
678 (if (null arg) (delete-region (point) (point-max)) | 687 (if (null arg) (delete-region (point) (point-max)) |
679 (skip-syntax-forward " ") | 688 (skip-syntax-forward " ") |
680 (delete-char numarg))) | 689 (delete-char numarg) |
690 (unless (or (eobp) (looking-at comment-end-skip)) | |
691 ;; If there's something left but it doesn't look like | |
692 ;; a comment-end any more, just remove it. | |
693 (delete-region (point) (point-max))))) | |
681 | 694 |
682 ;; Unquote any nested end-comment. | 695 ;; Unquote any nested end-comment. |
683 (comment-quote-nested comment-start comment-end t) | 696 (comment-quote-nested comment-start comment-end t) |
684 | 697 |
685 ;; Eliminate continuation markers as well. | 698 ;; Eliminate continuation markers as well. |