From 467690bb1ba4d18bb39e350f328ed3b53ebde23b Mon Sep 17 00:00:00 2001 From: Martin Stjernholm Date: Wed, 24 Apr 2002 00:50:29 +0000 Subject: [PATCH] (c-mask-comment): More fixes when used from `c-do-auto-fill' and point is at or near the limit of the comment. Fixed bug when the prefix from `c-guess-fill-prefix' is longer than the text on the first line of the comment when it's masked. --- lisp/ChangeLog | 8 ++++++++ lisp/progmodes/cc-cmds.el | 25 ++++++++++++++----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a051c4ad7bd..9e59081b598 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2002-04-24 Martin Stjernholm + + * progmodes/cc-cmds.el (c-mask-comment): More fixes when used + from `c-do-auto-fill' and point is at or near the limit of the + comment. Fixed bug when the prefix from `c-guess-fill-prefix' + is longer than the text on the first line of the comment when + it's masked. + 2002-04-24 Miles Bader * menu-bar.el (menu-bar-update-buffers-1): Make sure diff --git a/lisp/progmodes/cc-cmds.el b/lisp/progmodes/cc-cmds.el index 7c63b5fc7b4..96b72eb1754 100644 --- a/lisp/progmodes/cc-cmds.el +++ b/lisp/progmodes/cc-cmds.el @@ -2761,7 +2761,7 @@ command to conveniently insert and align the necessary backslashes." '("" . 0)))))) )) -(defun c-mask-comment (fill-include-ender apply-outside-literal fun &rest args) +(defun c-mask-comment (fill-mode apply-outside-literal fun &rest args) ;; Calls FUN with ARGS ar arguments. If point is inside a comment, ;; the comment starter and ender are masked and the buffer is ;; narrowed to make it look like a normal paragraph during the call. @@ -2790,7 +2790,7 @@ command to conveniently insert and align the necessary backslashes." ;; Widen to catch comment limits correctly. (widen) (unless c-lit-limits - (setq c-lit-limits (c-literal-limits nil t))) + (setq c-lit-limits (c-literal-limits nil fill-mode))) (setq c-lit-limits (c-collect-line-comments c-lit-limits)) (unless c-lit-type (setq c-lit-type (c-literal-type c-lit-limits)))) @@ -2840,8 +2840,8 @@ command to conveniently insert and align the necessary backslashes." "\\)\\*/")) (eq (cdr c-lit-limits) (match-end 0)) ;; Leave the comment ender on its own line. - (set-marker end (point)))) - (when fill-include-ender + (set-marker end (max (point) here)))) + (when fill-mode ;; The comment ender should hang. Replace all cruft ;; between it and the last word with one or two 'x' ;; and include it in the region. We'll change them @@ -2900,12 +2900,13 @@ command to conveniently insert and align the necessary backslashes." ;; The region includes the comment starter. (save-excursion (goto-char (car c-lit-limits)) - (if (and (looking-at (concat "\\(" comment-start-skip "\\)$")) - (> here (match-end 0))) - ;; Begin with the next line. - (setq beg (c-point 'bonl)) - ;; Fake the fill prefix in the first line. - (setq tmp-pre t))))) + (when (and (looking-at comment-start-skip) + (> here (match-end 0))) + (if (eq (match-end 0) (c-point 'eol)) + ;; Begin with the next line. + (setq beg (c-point 'bonl)) + ;; Fake the fill prefix in the first line. + (setq tmp-pre t)))))) ((eq c-lit-type 'string) ; String. (save-excursion (when (>= end (cdr c-lit-limits)) @@ -2951,7 +2952,9 @@ Warning: Regexp from `c-comment-prefix-regexp' doesn't match the comment prefix (goto-char (match-end 0)) (forward-char 2) (skip-chars-forward " \t")) - (while (< (current-column) (cdr fill)) (forward-char 1)) + (while (and (< (current-column) (cdr fill)) + (not (eolp))) + (forward-char 1)) (let ((col (current-column))) (setq beg (1+ (point)) tmp-pre (list (point))) -- 2.39.2