annotate lisp/modes/c-fill.el @ 131:869e1851236b xemacs-20-1p4

Import from CVS: tag xemacs-20-1p4
author cvs
date Mon, 13 Aug 2007 09:29:07 +0200
parents 376386a54a3c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; C comment mode - An auto-filled comment mode for gnu c-mode.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;;; Author: Robert Mecklenburg
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;;; Computer Science Dept.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;;; University of Utah
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;;; From: mecklen@utah-gr.UUCP (Robert Mecklenburg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;;; Also hartzell@Boulder.Colorado.EDU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;;; (c) 1986, University of Utah
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;;; Everyone is granted permission to copy, modify and redistribute
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;;; this file, provided the people they give it to can.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;;; Synched up with: Not in FSF.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;;; I have written a "global comment" minor-mode which performs auto-fill,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;;; fill-paragraph, and auto-indentation functions. This function only
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;;; works for comments which occupy an entire line (not comments to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;;; right of code). The mode has several options set through variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;;; If the variable c-comment-starting-blank is non-nil multi-line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 ;;; comments come out like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 ;;; /*
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25 ;;; * Your favorite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; * multi-line comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;;; otherwise they look like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;;; /* Your Favorite
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; * multi-line comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;;; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;; If the variable c-comment-hanging-indent is non-nil K&R style comments
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;;; are indented automatically like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;;; /* my_func - For multi-line comments with hanging indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;; * the text is lined up after the dash.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 ;;; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 ;;; otherwise the text "the text" (!) is lined up under my_func. If a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;; comment fits (as typed) on a single line it remains a single line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;;; comment even if c-comment-starting-blank is set. If
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;; c-comment-indenting is non-nil hitting carriage return resets the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 ;;; indentation for the next line to the current line's indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 ;;; (within the comment) like this:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 ;;; /* Typing along merrily....
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 ;;; * Now I indent with spaces, when I hit return
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 ;;; * the indentation is automatically set to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 ;;; * ^ here.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 ;;; */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ;;; Due to my lack of understanding of keymaps this permanently resets M-q
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 ;;; to my own fill function. I would like to have the comment mode
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 ;;; bindings only in comment mode but I can't seem to get that to work.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ;;; If some gnu guru can clue me in, I'd appreciate it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (defvar c-comment-starting-blank t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 "*Controls whether global comments have an initial blank line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (defvar c-comment-indenting t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "*If set global comments are indented to the level of the previous line.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (defvar c-comment-hanging-indent t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 "*If true, comments will be automatically indented to the dash.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (defvar c-hang-already-done t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 "If true we have performed the haning indent already for this comment.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 ;;; c-comment-map - This is a sparse keymap for comment mode which
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 ;;; gets inserted when c-comment is called.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (defvar c-comment-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 "Keymap used in C comment mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (if c-comment-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 (setq c-comment-mode-map (copy-keymap c-mode-map))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 (define-key c-comment-mode-map "\e\r" 'newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (define-key c-comment-mode-map "\eq" 'set-fill-and-fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (define-key c-comment-mode-map "\r" 'set-fill-and-return))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; c-comment - This is a filled comment mode which can format
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 ;;; indented text, do hanging indents, and symetric
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 ;;; placement of comment delimiters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (defun c-comment ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 "Edit a C comment with filling and indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 This performs hanging indentation, symmetric placement of delimiters,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 and Indented-Text mode style indentation. Type 'M-x apropos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 c-comment' for information on options."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 (let
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 ;; Save old state.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 ((auto-fill-function (if c-comment-indenting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 'do-indented-auto-fill 'do-auto-fill))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 ; (comment-start nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (comment-multi-line t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (comment-start-skip "/*\\*+[ ]*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (paragraph-start-ref paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 fill-prefix paragraph-start paragraph-separate opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 ;; Determine if we are inside a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (setq in-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (and (re-search-backward "/\\*\\|\\*/" 0 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (string= "/*" (buffer-substring (point) (+ (point) 2))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 ;; Indent the comment and set the fill prefix to comment continuation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ;; string. If we are already in a comment get the indentation on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;; the current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (setq c-hang-already-done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ;; Set the beginning of the comment and insert the blank line if needed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (use-local-map c-comment-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (if (not in-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (progn (c-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (insert "/* ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (setq fill-prefix (get-current-fill (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (recursive-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;; If the comment fits on one line, place the close
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 ;; comment at the end of the line. Otherwise, newline.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (if (and (save-excursion (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (search-forward "/*" opoint t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (<= (+ (current-column) 3) 79))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (insert " */")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (insert "\n*/"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (c-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (progn (setq fill-prefix (get-current-fill (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (recursive-edit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (search-forward "*/" (buffer-size) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (forward-line 1)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 ;; If starting blank enabled, insert a newline, etc., but only if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 ;; this comment requires multiple lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 (if c-comment-starting-blank
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (forward-line -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 (if (or (null (search-forward "/*" opoint t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (null (search-forward "*/" opoint t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (search-backward "/*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (re-search-forward comment-start-skip opoint t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (setq fill-prefix (get-current-fill (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (if (not (looking-at "\n"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (insert ?\n fill-prefix))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ; (indent-new-comment-line))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;; Move cursor to indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (c-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (use-local-map c-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;; set-fill-and-fill - Get the current fill for this line and fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 ;;; the paragraph.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (defun set-fill-and-fill (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 "Get the fill-prefix and fill the current paragraph."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (setq fill-prefix (get-current-fill (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (fill-paragraph arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;;; set-fill-and-return - Set the current fill prefix and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;;; indent-new-comment-line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (defun set-fill-and-return ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 "Set the current fill prefix and move to the next line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (if c-comment-indenting
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (setq fill-prefix (get-current-fill (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (insert ?\n fill-prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;;; do-indented-auto-fill - Perform the auto-fill function, but get
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;;; the fill-prefix first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (defun do-indented-auto-fill ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 "Perform auto-fill, but get fill-prefix first."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (let ((opoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 (move-to-column (1+ fill-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (skip-chars-backward "^ \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (if (bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (re-search-forward "[ \t]" opoint t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ;; If there is a space on the line before fill-point,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ;; and nonspaces precede it, break the line there.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (not (bolp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 ;; If we are wrapping to a new line, figure out the indentation on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 ;; the current line first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (setq fill-prefix (get-current-fill opoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (insert ?\n fill-prefix)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 ; (indent-new-comment-line)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 ;;; get-current-fill - Get the fill-prefix for the current line. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 ;;; assumes that the valid fill prefix is between
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;;; (beginning-of-line) and (point).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 (defun get-current-fill (pnt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 "Get the current fill prefix.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 A valid fill prefix must be between the beginning of the line and point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 (let ((opoint pnt) fill last-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (setq fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (re-search-forward comment-start-skip opoint t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 ;; Be sure there is trailing white space.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (setq last-char (substring fill (1- (length fill)) (length fill)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (if (and (not (string= " " last-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (not (string= " " last-char)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (setq fill (concat fill " ")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (setq fill (replace-letter fill "/" " "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 ;; Get the hanging indentation if we haven't already.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (if (and c-comment-hanging-indent (not c-hang-already-done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (let ((curr (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (opnt (progn (end-of-line) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (if (search-forward " - " opnt t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (setq fill (concat fill (make-string (- (point) curr) 32)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (setq c-hang-already-done t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 ;; Set the paragraph delimiters.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (setq paragraph-start (concat paragraph-start-ref
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 "\\|^"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (regexp-quote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (substring fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 0 (1- (length fill))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 "$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (setq paragraph-separate paragraph-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 ;;; replace-letter - Given a string, an old letter and a new letter,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 ;;; perform the substitution.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (defun replace-letter (str old-letter new-letter)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (let (new-str c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (sp 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (size (length str)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (while (< sp size)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (setq c (substring str sp (1+ sp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (setq new-str (concat new-str (if (string= c old-letter) new-letter c)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (setq sp (1+ sp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 new-str))