|
From: Alan M. <ac...@mu...> - 2006-05-04 07:29:32
|
Hi again, William!
Sorry that I hadn't properly tested the patch I sent you last week. Here
is a corrected version. I've tested applying it to the cc-cmds.el in CC
Mode 5.31.3.
On Wed, 19 Apr 2006, William Morris wrote:
>
>Entering a comment into a file header, emacs behaves as if the fill-column is
>set to something small (instead of 78 actual). The header looks like this:
>/*==========================================================================
> Alpha-numeric Text
> ================================
>
> Project Alpha-numeric Text
> Module BOOTLCDACT
> Language ANSI "C"
> Target CPU Alpha-numeric Text
>
> =====================================================================
>
> File lcdact.h
> Declaration of LCDACT main function
>
> =====================================================================
> Initial author : wmo
>
> History of this file ( most recent date on top )
> ------------------------------------------------
>
> Apr-06 wmo <---
> Apr-06 wmo Added action/behaviour definitions
> Feb-06 wmo initial issue
> ============================================================================*/
>
>If I add text to the line marked '<---' (these chars are not in actual
>buffer), the text wraps when a space is entered. If I put the cursor between
>the words "Added action" and enter a space, the space is inserted and the
>cursor moves on to the 'c' of "action" (ie I end up with "Added action" as
>expected, but the cursor has moved).
Here's the corrected patch:
#########################################################################
Log Message:
cc-cmds.el (c-mask-paragraph): Fix for C comments, when the comment ender
looks like "=========*/" and is alone on its line.
Index: cc-cmds.el
===================================================================
RCS file: /cvsroot/cc-mode/cc-mode/cc-cmds.el,v
retrieving revision 5.327.2.5
retrieving revision 5.327.2.6
diff -C2 -d -r5.327.2.5 -r5.327.2.6
*** cc-cmds.el 14 Apr 2006 10:52:00 -0000 5.327.2.5
--- cc-cmds.el 29 Apr 2006 09:39:14 -0000 5.327.2.6
***************
*** 3757,3763 ****
;; hidden inserts and deletes below that should be as transparent
;; as possible.
! (if (and buffer-undo-list (not (eq buffer-undo-list t)))
(setq buffer-undo-list (cons (point) buffer-undo-list)))
(c-save-buffer-state ()
(save-restriction
--- 3759,3768 ----
;; hidden inserts and deletes below that should be as transparent
;; as possible.
! (if (and buffer-undo-list (not (eq buffer-undo-list t)))
(setq buffer-undo-list (cons (point) buffer-undo-list)))
+ ;; Determine the limits and type of the containing literal (if any):
+ ;; C-LIT-LIMITS, C-LIT-TYPE; and the limits of the current paragraph:
+ ;; BEG and END.
(c-save-buffer-state ()
(save-restriction
***************
*** 3787,3790 ****
--- 3792,3802 ----
(unwind-protect
(progn
+ ;; For each of the possible types of text (string, C comment ...)
+ ;; determine BEG and END, the region we will narrow to. If we're in
+ ;; a literal, constrain BEG and END to the limits of this literal.
+ ;;
+ ;; For some of these text types, particularly a block comment, we
+ ;; may need to massage whitespace near literal delimiters, so that
+ ;; these don't get filled inappropriately.
(cond
***************
*** 3811,3829 ****
((eq c-lit-type 'c) ; Block comment.
(when (>= end (cdr c-lit-limits))
! ;; The region includes the comment ender which we might
! ;; want to keep together with the last word.
! (unless (save-excursion
! (goto-char (cdr c-lit-limits))
! (beginning-of-line)
! (and (looking-at (concat "[ \t]*\\("
! c-current-comment-prefix
! "\\)\\*/"))
! (eq (cdr c-lit-limits) (match-end 0))
! ;; The comment ender is on a line of its
! ;; own. Keep it that way.
! (set-marker end (point))))
! ;; The comment ender should hang. Replace all space between
! ;; it and the last word either by one or two 'x's (when
;; FILL-PARAGRAPH is non-nil), or a row of x's the same width
;; as the whitespace (when auto filling), and include it in
--- 3823,3847 ----
((eq c-lit-type 'c) ; Block comment.
(when (>= end (cdr c-lit-limits))
! ;; The region includes the comment ender. If it's on its own
! ;; line, it stays on its own line. If it's got company on the
! ;; line, it keeps (at least one word of) it. "=====*/" counts
! ;; as a comment ender here, but "===== */" doesn't and "foo*/"
! ;; doesn't.
! (unless
! (save-excursion
! (goto-char (cdr c-lit-limits))
! (beginning-of-line)
! (and (search-forward-regexp
! (concat "\\=[ \t]*\\(" c-current-comment-prefix "\\)")
! (- (cdr c-lit-limits) 2) t)
! (not (search-forward-regexp
! "\\(\\s \\|\\sw\\)"
! (- (cdr c-lit-limits) 2) 'limit))
! ;; The comment ender IS on its own line. Exclude
! ;; this line from the filling.
! (set-marker end (c-point 'bol))))
! ;; The comment ender is hanging. Replace all space between it
! ;; and the last word either by one or two 'x's (when
;; FILL-PARAGRAPH is non-nil), or a row of x's the same width
;; as the whitespace (when auto filling), and include it in
***************
*** 3842,3849 ****
--- 3860,3869 ----
(save-excursion
+ ;; Insert a CR after the "*/", adjust END
(goto-char (cdr c-lit-limits))
(setq tmp-post (point-marker))
(insert ?\n)
(set-marker end (point))
+
(forward-line -1) ; last line of the comment
(if (and (looking-at (concat "[ \t]*\\(\\("
***************
*** 3851,3857 ****
"\\)[ \t]*\\)"))
(eq ender-start (match-end 0)))
! ;; The comment ender is prefixed by nothing
! ;; but a comment line prefix. Remove it
! ;; along with surrounding ws.
(setq spaces (- (match-end 1) (match-end 2)))
(goto-char ender-start))
--- 3871,3877 ----
"\\)[ \t]*\\)"))
(eq ender-start (match-end 0)))
! ;; The comment ender is prefixed by nothing but a
! ;; comment line prefix. IS THIS POSSIBLE? (ACM,
! ;; 2006/4/28). Remove it along with surrounding ws.
(setq spaces (- (match-end 1) (match-end 2)))
(goto-char ender-start))
***************
*** 3859,3862 ****
--- 3879,3883 ----
; " \t"? "*/" is NOT alone on the line (ACM, 2005/8/18)
+ ;; What's being tested here? 2006/4/20. FIXME!!!
(if (/= (point) ender-start)
(progn
#########################################################################
--
Alan.
|