Mercurial > emacs
annotate lisp/progmodes/cplus-md.el @ 1717:aa7d6d57504b
* frame.h (struct frame): New fields `can_have_scrollbars' and
`has_vertical_scrollbars'.
(FRAME_CAN_HAVE_SCROLLBARS, FRAME_HAS_VERTICAL_SCROLLBARS): New
accessors, for both the MULTI_FRAME and non-MULTI_FRAME.
(VERTICAL_SCROLLBAR_WIDTH, WINDOW_VERTICAL_SCROLLBAR,
WINDOW_VERTICAL_SCROLLBAR_COLUMN,
WINDOW_VERTICAL_SCROLLBAR_HEIGHT): New macros.
* window.h (struct window): New field `vertical_scrollbar'.
* xterm.h (struct x_display): vertical_scrollbars,
judge_timestamp, vertical_scrollbar_extra: New fields.
(struct scrollbar): New struct.
(VERTICAL_SCROLLBAR_PIXEL_WIDTH, VERTICAL_SCROLLBAR_PIXEL_HEIGHT,
VERTICAL_SCROLLBAR_LEFT_BORDER, VERTICAL_SCROLLBAR_RIGHT_BORDER,
VERTICAL_SCROLLBAR_TOP_BORDER, VERTICAL_SCROLLBAR_BOTTOM_BORDER,
CHAR_TO_PIXEL_WIDTH, CHAR_TO_PIXEL_HEIGHT, PIXEL_TO_CHAR_WIDTH,
PIXEL_TO_CHAR_HEIGHT): New accessors and macros.
* frame.c (make_frame): Initialize the `can_have_scrollbars' and
`has_vertical_scrollbars' fields of the frame.
* term.c (term_init): Note that TERMCAP terminals don't support
scrollbars.
(mouse_position_hook): Document new args.
(set_vertical_scrollbar_hook, condemn_scrollbars_hook,
redeem_scrollbar_hook, judge_scrollbars_hook): New hooks.
* termhooks.h: Declare and document them.
(enum scrollbar_part): New type.
(struct input_event): Describe the new form of the scrollbar_click
event type. Change `part' from a Lisp_Object to an enum
scrollbar_part. Add a new field `scrollbar'.
* keyboard.c (kbd_buffer_get_event): Pass appropriate new
parameters to *mouse_position_hook, and make_lispy_movement.
* xfns.c (x_set_vertical_scrollbar): New function.
(x_figure_window_size): Use new macros to calculate frame size.
(Fx_create_frame): Note that X Windows frames do support scroll
bars. Default to "yes".
* xterm.c: #include <X11/cursorfont.h> and "window.h".
(x_vertical_scrollbar_cursor): New variable.
(x_term_init): Initialize it.
(last_mouse_bar, last_mouse_bar_frame, last_mouse_part,
last_mouse_scroll_range_start, last_mouse_scroll_range_end): New
variables.
(XTmouse_position): Use them to return scrollbar movement events.
Take new arguments, for that purpose.
(x_window_to_scrollbar, x_scrollbar_create,
x_scrollbar_set_handle, x_scrollbar_remove, x_scrollbar_move,
XTset_scrollbar, XTcondemn_scrollbars, XTredeem_scrollbar,
XTjudge_scrollbars, x_scrollbar_expose,
x_scrollbar_background_expose, x_scrollbar_handle_click,
x_scrollbar_handle_motion): New functions to implement scrollbars.
(x_term_init): Set the termhooks.h hooks to point to them.
(x_set_window_size): Use new macros to calculate frame size. Set
vertical_scrollbar_extra field.
(x_make_frame_visible): Use the frame accessor
FRAME_HAS_VERTICAL_SCROLLBARS to decide if we need to map the
frame's subwindows as well.
(XTread_socket): Use new size-calculation macros from xterm.h when
processing ConfigureNotify events.
(x_wm_set_size_hint): Use PIXEL_TO_CHAR_WIDTH and
PIXEL_TO_CHAR_HEIGHT macros.
* ymakefile (xdisp.o): This now depends on termhooks.h.
(xterm.o): This now depends on window.h.
| author | Jim Blandy <jimb@redhat.com> |
|---|---|
| date | Thu, 24 Dec 1992 06:17:18 +0000 |
| parents | 7e4999005da1 |
| children | 10e417efb12a |
| rev | line source |
|---|---|
|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
1 ;;; c++-mode.el --- C++ code editing commands for Emacs |
| 896 | 2 ;;; Copyright (C) 1985, 1992 Free Software Foundation, Inc. |
| 3 | |
| 4 ;; This file is part of GNU Emacs. | |
|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
5 |
| 896 | 6 ;; GNU Emacs is free software; you can redistribute it and/or modify |
| 7 ;; it under the terms of the GNU General Public License as published by | |
| 8 ;; the Free Software Foundation; either version 2, or (at your option) | |
| 9 ;; any later version. | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
10 |
| 896 | 11 ;; GNU Emacs is distributed in the hope that it will be useful, |
| 12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 ;; GNU General Public License for more details. | |
| 15 | |
| 16 ;; You should have received a copy of the GNU General Public License | |
| 17 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
| 18 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | |
|
798
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
19 ;; Maintainer: Dave Detlefs <dld@cs.cmu.edu> |
|
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
20 ;; Keywords: c |
|
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
21 |
|
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
22 ;;; Commentary: |
|
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
23 |
| 257 | 24 ;; 1987 Dave Detlefs (dld@cs.cmu.edu) |
| 25 ;; and Stewart Clamen (clamen@cs.cmu.edu). | |
| 26 ;; Done by fairly faithful modification of: | |
|
798
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
27 ;;; Change Log: |
|
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
28 |
| 257 | 29 ;; Feb, 1990 (Dave Detlefs, dld@cs.cmu.edu) |
| 30 ;; Fixed electric-c++-terminator to handle double colons, at the | |
| 31 ;; request of John Hagerman. | |
| 32 ;; | |
| 33 ;; Jan, 1990 (Doug Lea, dl@oswego.edu) | |
| 34 ;; Replaced c++-comment-region and c++-uncomment-region with | |
| 35 ;; versions from Igor Metz that avoid potential infinite loops. | |
| 36 ;; | |
| 37 ;; Oct, 1989 (Dave Detlefs, dld@cs.cmu.edu) | |
| 38 ;; Added contribution from Igor Metz <metz@iam.unibe.ch>: | |
| 39 ;; functions c++-comment-region and c++-uncomment-region and | |
| 40 ;; corresponding key-binding. | |
| 41 ;; Also fixed bug in indentation of second line after an empty | |
| 42 ;; arglist with empty-arglist non-null. | |
| 43 ;; | |
| 44 ;; Sept, 1989 (Glen Ditchfield, gjditchfield@violet.uwaterloo.ca): | |
| 45 ;; Textual changes to more closely imitate Emacs 18.55's c-mode. | |
| 46 ;; Fixed handling of "default:", where ":" was the last character in the | |
| 47 ;; buffer. Fixed indentation of comments starting in column 0, and when | |
| 48 ;; previous line contained more than one comment start string. Fixed | |
| 49 ;; handling of "friend class". | |
| 50 ;; | |
| 51 ;; Aug 7, 1989; John Hagerman (hagerman@ece.cmu.edu): | |
| 52 ;; Changed calculate-c++-indent to handle member initializations | |
| 53 ;; more flexibly. Two new variables are used to control behavior: | |
| 54 ;; c++-member-init-indent and c++-continued-member-init-offset. | |
| 55 ;; Note the assumption that member initializations and argument | |
| 56 ;; declarations are not mixed in one function definition. | |
| 57 ;; | |
| 58 ;; June 1989 (Dave Detlefs, dld@cs.cmu.edu) | |
| 59 ;; Fixed calculate-c++-indent to handle continued lines ending in | |
| 60 ;; {'s. (I wasn't following C-mode closely enough, or C-mode | |
| 61 ;; changed.) Made ' a quote character, at the behest of someone | |
| 62 ;; whose mail I apparently deleted (if they send me mail I'll credit | |
| 63 ;; them here in a future revision.) | |
| 64 ;; Dan Weinreb (dlw@odi.com) pointed out that 'c++-mode successively | |
| 65 ;; bound c++-indent-exp and c++-indent-defun to ESC-^q. ESC-^q is | |
| 66 ;; now bound to c++-indent-exp, while, c++-indent-defun is invoked | |
| 67 ;; with ESC-^x. | |
| 68 | |
| 69 ;; February 1989 (Dave Detlefs, dld@cs.cmu.edu) | |
| 70 ;; Fixed some errors in c++-indent-defun, as pointed out by Sam | |
| 71 ;; Haradhvala (odi!sam@talcott.harvard.edu). | |
| 72 ;; October 1988 (Dave Detlefs, dld@cs.cmu.edu) | |
| 73 ;; It turns out I had only *thought* I had made | |
| 74 ;; beginning(end)-of-defun work. It should work better now -- you | |
| 75 ;; can either attempt to match defun headers "strongly," using a | |
| 76 ;; very complicated regexp, or "weakly," using a simple one. This | |
| 77 ;; is settable by a variable; the default is the cheaper weak | |
| 78 ;; method. (Stewart Clamen was intimately involved in this, too.) | |
| 79 ;; | |
| 80 ;; I made "'" *not* be a string delimiter, because that was causing | |
| 81 ;; comments containing contractions to ("// don't") to mess up paren | |
| 82 ;; balancing. | |
| 83 ;; | |
| 84 ;; I also incorporated another slight indentation fix from Glen | |
| 85 ;; Ditchfield. | |
| 86 ;; | |
| 87 ;; We hope this is will make into version 19 of gnu-emacs. | |
| 88 ;; | |
| 89 ;; September 1988: incorporated changes from Fred Calm at Schlumberger. | |
| 90 ;; Also, made beginning(end)-of-defun, indent-defun work. | |
| 91 ;; | |
| 92 ;; August 1987: incorporated changes done by Glen Ditchfield of Waterloo. | |
| 93 | |
|
798
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
94 ;;; Code: |
|
b7932f859d4e
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
662
diff
changeset
|
95 |
| 257 | 96 (defvar c++-mode-abbrev-table nil |
| 97 "Abbrev table used in C++ mode.") | |
| 98 (define-abbrev-table 'c++-mode-abbrev-table ()) | |
| 99 | |
| 100 (defvar c++-mode-map () | |
| 101 "Keymap used in C++ mode.") | |
| 102 (if c++-mode-map | |
| 103 () | |
| 104 (setq c++-mode-map (make-sparse-keymap)) | |
| 105 (define-key c++-mode-map "\C-j" 'reindent-then-newline-and-indent) | |
| 106 (define-key c++-mode-map "{" 'electric-c++-brace) | |
| 107 (define-key c++-mode-map "}" 'electric-c++-brace) | |
| 108 (define-key c++-mode-map ";" 'electric-c++-semi) | |
| 109 (define-key c++-mode-map "\e\C-h" 'mark-c-function) | |
| 110 (define-key c++-mode-map "\e\C-q" 'indent-c++-exp) | |
| 111 (define-key c++-mode-map "\177" 'backward-delete-char-untabify) | |
| 112 (define-key c++-mode-map "\t" 'c++-indent-command) | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
113 ;; (define-key c++-mode-map "\C-c\C-i" 'c++-insert-header) |
|
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
114 (define-key c++-mode-map "\C-c\C-\\" 'c-backslash-region)) |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
115 ;; (define-key c++-mode-map "\e\C-a" 'c++-beginning-of-defun) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
116 ;; (define-key c++-mode-map "\e\C-e" 'c++-end-of-defun) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
117 ;; (define-key c++-mode-map "\e\C-x" 'c++-indent-defun)) |
| 257 | 118 |
| 119 (defvar c++-mode-syntax-table nil | |
| 120 "Syntax table used in C++ mode.") | |
| 121 | |
| 122 (if c++-mode-syntax-table | |
| 123 () | |
| 124 (setq c++-mode-syntax-table (copy-syntax-table c-mode-syntax-table)) | |
| 125 (modify-syntax-entry ?/ ". 12" c++-mode-syntax-table) | |
| 126 (modify-syntax-entry ?\n ">" c++-mode-syntax-table) | |
| 127 (modify-syntax-entry ?\' "." c++-mode-syntax-table)) | |
| 128 | |
| 129 (defvar c++-continued-member-init-offset nil | |
| 130 "*Extra indent for continuation lines of member inits; | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
131 nil means to align with previous initializations rather than |
| 257 | 132 with the colon on the first line.") |
| 133 (defvar c++-member-init-indent 0 | |
| 134 "*Indentation level of member initializations in function declarations.") | |
| 135 (defvar c++-friend-offset -4 | |
| 136 "*Offset of C++ friend class declarations relative to member declarations.") | |
| 137 (defvar c++-electric-colon t | |
| 138 "*If t, colon is an electric terminator.") | |
| 139 (defvar c++-empty-arglist-indent nil | |
| 140 "*Indicates how far to indent an line following an empty argument | |
| 141 list. Nil indicates to just after the paren.") | |
| 142 | |
| 143 | |
| 144 ;;;###autoload | |
| 145 (defun c++-mode () | |
| 146 "Major mode for editing C++ code. Very much like editing C code. | |
| 147 Expression and list commands understand all C++ brackets. | |
| 148 Tab at left margin indents for C++ code | |
| 149 Comments are delimited with /* ... */ {or with // ... <newline>} | |
| 150 Paragraphs are separated by blank lines only. | |
| 151 Delete converts tabs to spaces as it moves back. | |
| 152 \\{c++-mode-map} | |
| 153 Variables controlling indentation style: | |
| 154 c-tab-always-indent | |
| 155 Non-nil means TAB in C mode should always reindent the current line, | |
| 156 regardless of where in the line point is when the TAB command is used. | |
| 157 Default is t. | |
| 158 c-auto-newline | |
| 159 Non-nil means automatically newline before and after braces, | |
| 160 and after colons and semicolons, inserted in C code. | |
| 161 c-indent-level | |
| 162 Indentation of C statements within surrounding block. | |
| 163 The surrounding block's indentation is the indentation | |
| 164 of the line on which the open-brace appears. | |
| 165 c-continued-statement-offset | |
| 166 Extra indentation given to a substatement, such as the | |
| 167 then-clause of an if or body of a while. | |
| 168 c-continued-brace-offset | |
| 169 Extra indentation given to a brace that starts a substatement. | |
| 170 This is in addition to c-continued-statement-offset. | |
| 171 c-brace-offset | |
| 172 Extra indentation for line if it starts with an open brace. | |
| 173 c-brace-imaginary-offset | |
| 174 An open brace following other text is treated as if it were | |
| 175 this far to the right of the start of its line. | |
| 176 c-argdecl-indent | |
| 177 Indentation level of declarations of C function arguments. | |
| 178 c-label-offset | |
| 179 Extra indentation for line that is a label, or case or ``default:'', or | |
| 180 ``public:'' or ``private:'', or ``protected:''. | |
| 181 c++-electric-colon | |
| 182 If non-nil at invocation of c++-mode (t is the default) colon electricly | |
| 183 indents. | |
| 184 c++-empty-arglist-indent | |
| 185 If non-nil, a function declaration or invocation which ends a line with a | |
| 186 left paren is indented this many extra spaces, instead of flush with the | |
| 187 left paren. | |
| 188 c++-friend-offset | |
| 189 Offset of C++ friend class declarations relative to member declarations. | |
| 190 c++-member-init-indent | |
| 191 Indentation level of member initializations in function declarations, | |
| 192 if they are on a separate line beginning with a colon. | |
| 193 c++-continued-member-init-offset | |
| 194 Extra indentation for continuation lines of member initializations; NIL | |
| 195 means to align with previous initializations rather than with the colon. | |
| 196 | |
| 197 Settings for K&R, BSD, and Stroustrup indentation styles are | |
| 198 c-indent-level 5 8 4 | |
| 199 c-continued-statement-offset 5 8 4 | |
| 200 c-continued-brace-offset 0 | |
| 201 c-brace-offset -5 -8 0 | |
| 202 c-brace-imaginary-offset 0 | |
| 203 c-argdecl-indent 0 8 4 | |
| 204 c-label-offset -5 -8 -4 | |
| 205 c++-empty-arglist-indent 4 | |
| 206 c++-friend-offset 0 | |
| 207 | |
| 208 Turning on C++ mode calls the value of the variable `c++-mode-hook' with | |
| 209 no args if that value is non-nil." | |
| 210 (interactive) | |
| 211 (kill-all-local-variables) | |
| 212 (use-local-map c++-mode-map) | |
| 213 (set-syntax-table c++-mode-syntax-table) | |
| 214 (setq major-mode 'c++-mode | |
| 215 mode-name "C++" | |
| 216 comment-column 32 | |
| 217 local-abbrev-table c++-mode-abbrev-table) | |
| 218 (set (make-local-variable 'indent-line-function) 'c++-indent-line) | |
| 219 (set (make-local-variable 'comment-start) "// ") | |
| 220 (set (make-local-variable 'comment-end) "") | |
| 221 (set (make-local-variable 'comment-start-skip) "/\\*+ *\\|// *") | |
| 222 (set (make-local-variable 'comment-indent-hook) 'c++-comment-indent) | |
| 223 (set (make-local-variable 'paragraph-start) (concat "^$\\|" page-delimiter)) | |
| 224 (set (make-local-variable 'paragraph-separate) paragraph-start) | |
| 225 (set (make-local-variable 'paragraph-ignore-fill-prefix) t) | |
| 226 (set (make-local-variable 'require-final-newline) t) | |
| 227 (set (make-local-variable 'parse-sexp-ignore-comments) nil) | |
| 228 (run-hooks 'c++-mode-hook) | |
| 229 (if c++-electric-colon | |
| 230 (define-key c++-mode-map ":" 'electric-c++-terminator))) | |
| 231 | |
| 232 ;; This is used by indent-for-comment | |
| 233 ;; to decide how much to indent a comment in C++ code | |
| 234 ;; based on its context. | |
| 235 (defun c++-comment-indent () | |
| 236 (if (looking-at "^\\(/\\*\\|//\\)") | |
| 237 0 ; Existing comment at bol stays there. | |
| 238 (save-excursion | |
| 239 (skip-chars-backward " \t") | |
| 240 (max | |
| 241 ;; leave at least one space on non-empty lines. | |
| 242 (if (zerop (current-column)) 0 (1+ (current-column))) | |
| 243 (let ((cur-pt (point))) | |
| 244 (beginning-of-line 0) | |
| 245 ;; If previous line had a comment, use it's indent | |
| 246 (if (re-search-forward comment-start-skip cur-pt t) | |
| 247 (progn | |
| 248 (goto-char (match-beginning 0)) | |
| 249 (current-column)) | |
| 250 comment-column)))))) ; otherwise indent at comment column. | |
| 251 | |
| 252 (defun electric-c++-brace (arg) | |
| 253 "Insert character and correct line's indentation." | |
| 254 (interactive "P") | |
| 255 (let (insertpos) | |
| 256 (if (and (not arg) | |
| 257 (eolp) | |
| 258 (or (save-excursion | |
| 259 (skip-chars-backward " \t") | |
| 260 (bolp)) | |
| 261 (if c-auto-newline (progn (c++-indent-line) (newline) t)))) | |
| 262 (progn | |
| 263 (insert last-command-char) | |
| 264 (c++-indent-line) | |
| 265 (if c-auto-newline | |
| 266 (progn | |
| 267 (newline) | |
| 268 ;; (newline) may have done auto-fill | |
| 269 (setq insertpos (- (point) 2)) | |
| 270 (c++-indent-line))) | |
| 271 (save-excursion | |
| 272 (if insertpos (goto-char (1+ insertpos))) | |
| 273 (delete-char -1)))) | |
| 274 (if insertpos | |
| 275 (save-excursion | |
| 276 (goto-char insertpos) | |
| 277 (self-insert-command (prefix-numeric-value arg))) | |
| 278 (self-insert-command (prefix-numeric-value arg))))) | |
| 279 | |
| 280 (defun electric-c++-semi (arg) | |
| 281 "Insert character and correct line's indentation." | |
| 282 (interactive "P") | |
| 283 (if c-auto-newline | |
| 284 (electric-c++-terminator arg) | |
| 285 (self-insert-command (prefix-numeric-value arg)))) | |
| 286 | |
| 287 (defun electric-c++-terminator (arg) | |
| 288 "Insert character and correct line's indentation." | |
| 289 (interactive "P") | |
| 290 (let (insertpos (end (point))) | |
| 291 (if (and (not arg) (eolp) | |
| 292 (not (save-excursion | |
| 293 (beginning-of-line) | |
| 294 (skip-chars-forward " \t") | |
| 295 (or (= (following-char) ?#) | |
| 296 ;; Colon is special only after a label, or | |
| 297 ;; case, or another colon. | |
| 298 ;; So quickly rule out most other uses of colon | |
| 299 ;; and do no indentation for them. | |
| 300 (and (eq last-command-char ?:) | |
| 301 (not (looking-at "case[ \t]")) | |
| 302 (save-excursion | |
| 303 (forward-word 1) | |
| 304 (skip-chars-forward " \t") | |
| 305 (< (point) end)) | |
| 306 ;; Do re-indent double colons | |
| 307 (save-excursion | |
| 308 (end-of-line 1) | |
| 309 (looking-at ":"))) | |
| 310 (progn | |
| 311 (beginning-of-defun) | |
| 312 (let ((pps (parse-partial-sexp (point) end))) | |
| 313 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))))) | |
| 314 (progn | |
| 315 (insert last-command-char) | |
| 316 (c++-indent-line) | |
| 317 (and c-auto-newline | |
| 318 (not (c-inside-parens-p)) | |
| 319 (progn | |
| 320 ;; the new marker object, used to be just an integer | |
| 321 (setq insertpos (make-marker)) | |
| 322 ;; changed setq to set-marker | |
| 323 (set-marker insertpos (1- (point))) | |
| 324 ;; do this before the newline, since in auto fill can break | |
| 325 (newline) | |
| 326 (c-indent-line))) | |
| 327 (save-excursion | |
| 328 (if insertpos (goto-char (1+ insertpos))) | |
| 329 (delete-char -1)))) | |
| 330 (if insertpos | |
| 331 (save-excursion | |
| 332 (goto-char insertpos) | |
| 333 (self-insert-command (prefix-numeric-value arg))) | |
| 334 (self-insert-command (prefix-numeric-value arg))))) | |
| 335 | |
| 336 (defun c++-indent-command (&optional whole-exp) | |
| 337 "Indent current line as C++ code, or in some cases insert a tab character. | |
| 338 If `c-tab-always-indent' is non-nil (the default), always indent current | |
| 339 line. Otherwise, indent the current line only if point is at the left | |
| 340 margin or in the line's indentation; otherwise insert a tab. | |
| 341 | |
| 342 A numeric argument, regardless of its value, means indent rigidly all means | |
| 343 indent rigidly all the lines of the expression starting after point so that | |
| 344 this line becomes properly indented. The relative indentation among the | |
| 345 lines of the expression are preserved." | |
| 346 (interactive "P") | |
| 347 (if whole-exp | |
| 348 ;; If arg, always indent this line as C | |
| 349 ;; and shift remaining lines of expression the same amount. | |
| 350 (let ((shift-amt (c++-indent-line)) | |
| 351 beg end) | |
| 352 (save-excursion | |
| 353 (if c-tab-always-indent | |
| 354 (beginning-of-line)) | |
| 355 (setq beg (point)) | |
| 356 (forward-sexp 1) | |
| 357 (setq end (point)) | |
| 358 (goto-char beg) | |
| 359 (forward-line 1) | |
| 360 (setq beg (point))) | |
| 361 (if (> end beg) | |
| 362 (indent-code-rigidly beg end shift-amt "#"))) | |
| 363 (if (and (not c-tab-always-indent) | |
| 364 (save-excursion | |
| 365 (skip-chars-backward " \t") | |
| 366 (not (bolp)))) | |
| 367 (insert-tab) | |
| 368 (c++-indent-line)))) | |
| 369 | |
| 370 (defun c++-indent-line () | |
| 371 "Indent current line as C++ code. | |
| 372 Return the amount the indentation changed by." | |
| 373 (let ((indent (calculate-c++-indent nil)) | |
| 374 beg shift-amt | |
| 375 (case-fold-search nil) | |
| 376 (pos (- (point-max) (point)))) | |
| 377 (beginning-of-line) | |
| 378 (setq beg (point)) | |
| 379 (cond ((eq indent nil) | |
| 380 (setq indent (current-indentation))) | |
| 381 ((eq indent t) | |
| 382 (setq indent (calculate-c-indent-within-comment))) | |
| 383 ((looking-at "[ \t]*#") | |
| 384 (setq indent 0)) | |
| 385 (t | |
| 386 (skip-chars-forward " \t") | |
| 387 (if (listp indent) (setq indent (car indent))) | |
| 388 (cond ((looking-at "\\(default\\|public\\|private\\|protected\\):") | |
| 389 (setq indent (+ indent c-label-offset))) | |
| 390 ((or (looking-at "case\\b") | |
| 391 (and (looking-at "[A-Za-z]") | |
| 392 (save-excursion | |
| 393 (forward-sexp 1) | |
| 394 (looking-at ":[^:]")))) | |
| 395 (setq indent (max 1 (+ indent c-label-offset)))) | |
| 396 ((and (looking-at "else\\b") | |
| 397 (not (looking-at "else\\s_"))) | |
| 398 (setq indent (save-excursion | |
| 399 (c-backward-to-start-of-if) | |
| 400 (current-indentation)))) | |
| 401 ((looking-at "friend\[ \t]class[ \t]") | |
| 402 (setq indent (+ indent c++-friend-offset))) | |
| 403 ((= (following-char) ?}) | |
| 404 (setq indent (- indent c-indent-level))) | |
| 405 ((= (following-char) ?{) | |
| 406 (setq indent (+ indent c-brace-offset)))))) | |
| 407 (skip-chars-forward " \t") | |
| 408 (setq shift-amt (- indent (current-column))) | |
| 409 (if (zerop shift-amt) | |
| 410 (if (> (- (point-max) pos) (point)) | |
| 411 (goto-char (- (point-max) pos))) | |
| 412 (delete-region beg (point)) | |
| 413 (indent-to indent) | |
| 414 ;; If initial point was within line's indentation, | |
| 415 ;; position after the indentation. Else stay at same point in text. | |
| 416 (if (> (- (point-max) pos) (point)) | |
| 417 (goto-char (- (point-max) pos)))) | |
| 418 shift-amt)) | |
| 419 | |
| 420 (defun calculate-c++-indent (&optional parse-start) | |
| 421 "Return appropriate indentation for current line as C++ code. | |
| 422 In usual case returns an integer: the column to indent to. | |
| 423 Returns nil if line starts inside a string, t if in a comment." | |
| 424 (save-excursion | |
| 425 (beginning-of-line) | |
| 426 (let ((indent-point (point)) | |
| 427 (case-fold-search nil) | |
| 428 state | |
| 429 containing-sexp) | |
| 430 (if parse-start | |
| 431 (goto-char parse-start) | |
| 432 (beginning-of-defun)) | |
| 433 (while (< (point) indent-point) | |
| 434 (setq parse-start (point)) | |
| 435 (setq state (parse-partial-sexp (point) indent-point 0)) | |
| 436 (setq containing-sexp (car (cdr state)))) | |
| 437 (cond ((or (nth 3 state) (nth 4 state)) | |
| 438 ;; return nil or t if should not change this line | |
| 439 (nth 4 state)) | |
| 440 ((null containing-sexp) | |
| 441 ;; Line is at top level. May be data or function definition, or | |
| 442 ;; may be function argument declaration or member initialization. | |
| 443 ;; Indent like the previous top level line unless | |
| 444 ;; (1) the previous line ends in a closeparen without semicolon, | |
| 445 ;; in which case this line is the first argument declaration or | |
| 446 ;; member initialization, or | |
| 447 ;; (2) the previous line begins with a colon, | |
| 448 ;; in which case this is the second line of member inits. | |
| 449 ;; It is assumed that arg decls and member inits are not mixed. | |
| 450 (goto-char indent-point) | |
| 451 (skip-chars-forward " \t") | |
| 452 (if (= (following-char) ?{) | |
| 453 0 ; Unless it starts a function body | |
| 454 (c++-backward-to-noncomment (or parse-start (point-min))) | |
| 455 (if (= (preceding-char) ?\)) | |
| 456 (progn ; first arg decl or member init | |
| 457 (goto-char indent-point) | |
| 458 (skip-chars-forward " \t") | |
| 459 (if (= (following-char) ?:) | |
| 460 c++-member-init-indent | |
| 461 c-argdecl-indent)) | |
| 462 (if (= (preceding-char) ?\;) | |
| 463 (backward-char 1)) | |
| 464 (if (= (preceding-char) ?}) | |
| 465 0 | |
| 466 (beginning-of-line) ; continued arg decls or member inits | |
| 467 (skip-chars-forward " \t") | |
| 468 (if (= (following-char) ?:) | |
| 469 (if c++-continued-member-init-offset | |
| 470 (+ (current-indentation) | |
| 471 c++-continued-member-init-offset) | |
| 472 (progn | |
| 473 (forward-char 1) | |
| 474 (skip-chars-forward " \t") | |
| 475 (current-column))) | |
| 476 (current-indentation))) | |
| 477 ))) | |
| 478 ((/= (char-after containing-sexp) ?{) | |
| 479 ;; line is expression, not statement: | |
| 480 ;; indent to just after the surrounding open -- unless | |
| 481 ;; empty arg list, in which case we do what | |
| 482 ;; c++-empty-arglist-indent says to do. | |
| 483 (if (and c++-empty-arglist-indent | |
| 484 (or (null (nth 2 state)) ;; indicates empty arg | |
| 485 ;; list. | |
| 486 ;; Use a heuristic: if the first | |
| 487 ;; non-whitespace following left paren on | |
| 488 ;; same line is not a comment, | |
| 489 ;; is not an empty arglist. | |
| 490 (save-excursion | |
| 491 (goto-char (1+ containing-sexp)) | |
| 492 (not | |
| 493 (looking-at "\\( \\|\t\\)*[^/\n]"))))) | |
| 494 (progn | |
| 495 (goto-char containing-sexp) | |
| 496 (beginning-of-line) | |
| 497 (skip-chars-forward " \t") | |
| 498 (goto-char (min (+ (point) c++-empty-arglist-indent) | |
| 499 (1+ containing-sexp))) | |
| 500 (current-column)) | |
| 501 ;; In C-mode, we would always indent to one after the | |
| 502 ;; left paren. Here, though, we may have an | |
| 503 ;; empty-arglist, so we'll indent to the min of that | |
| 504 ;; and the beginning of the first argument. | |
| 505 (goto-char (1+ containing-sexp)) | |
| 506 (current-column))) | |
| 507 (t | |
| 508 ;; Statement. Find previous non-comment character. | |
| 509 (goto-char indent-point) | |
| 510 (c++-backward-to-noncomment containing-sexp) | |
| 511 (if (not (memq (preceding-char) '(nil ?\, ?\; ?} ?: ?\{))) | |
| 512 ;; This line is continuation of preceding line's statement; | |
| 513 ;; indent c-continued-statement-offset more than the | |
| 514 ;; previous line of the statement. | |
| 515 (progn | |
| 516 (c-backward-to-start-of-continued-exp containing-sexp) | |
| 517 (+ c-continued-statement-offset (current-column))) | |
| 518 ;; This line starts a new statement. | |
| 519 ;; Position following last unclosed open. | |
| 520 (goto-char containing-sexp) | |
| 521 ;; Is line first statement after an open-brace? | |
| 522 (or | |
| 523 ;; If no, find that first statement and indent like it. | |
| 524 (save-excursion | |
| 525 (forward-char 1) | |
| 526 (while (progn (skip-chars-forward " \t\n") | |
| 527 (looking-at | |
| 528 (concat | |
| 529 "#\\|/\\*\\|//" | |
| 530 "\\|case[ \t]" | |
| 531 "\\|[a-zA-Z0-9_$]*:[^:]" | |
| 532 "\\|friend[ \t]class[ \t]"))) | |
| 533 ;; Skip over comments and labels following openbrace. | |
| 534 (cond ((= (following-char) ?\#) | |
| 535 (forward-line 1)) | |
| 536 ((looking-at "/\\*") | |
| 537 (search-forward "*/" nil 'move)) | |
| 538 ((looking-at "//\\|friend[ \t]class[ \t]") | |
| 539 (forward-line 1)) | |
| 540 (t | |
| 541 (re-search-forward ":[^:]" nil 'move)))) | |
| 542 ;; The first following code counts | |
| 543 ;; if it is before the line we want to indent. | |
| 544 (and (< (point) indent-point) | |
| 545 (current-column))) | |
| 546 ;; If no previous statement, | |
| 547 ;; indent it relative to line brace is on. | |
| 548 ;; For open brace in column zero, don't let statement | |
| 549 ;; start there too. If c-indent-offset is zero, | |
| 550 ;; use c-brace-offset + c-continued-statement-offset instead. | |
| 551 ;; For open-braces not the first thing in a line, | |
| 552 ;; add in c-brace-imaginary-offset. | |
| 553 (+ (if (and (bolp) (zerop c-indent-level)) | |
| 554 (+ c-brace-offset c-continued-statement-offset) | |
| 555 c-indent-level) | |
| 556 ;; Move back over whitespace before the openbrace. | |
| 557 ;; If openbrace is not first nonwhite thing on the line, | |
| 558 ;; add the c-brace-imaginary-offset. | |
| 559 (progn (skip-chars-backward " \t") | |
| 560 (if (bolp) 0 c-brace-imaginary-offset)) | |
| 561 ;; If the openbrace is preceded by a parenthesized exp, | |
| 562 ;; move to the beginning of that; | |
| 563 ;; possibly a different line | |
| 564 (progn | |
| 565 (if (eq (preceding-char) ?\)) | |
| 566 (forward-sexp -1)) | |
| 567 ;; Get initial indentation of the line we are on. | |
| 568 (current-indentation)))))))))) | |
| 569 | |
| 570 (defun c++-backward-to-noncomment (lim) | |
| 571 (let (opoint stop) | |
| 572 (while (not stop) | |
| 573 (skip-chars-backward " \t\n\r\f" lim) | |
| 574 (setq opoint (point)) | |
| 575 (cond ((and (>= (point) (+ 2 lim)) | |
| 576 (save-excursion | |
| 577 (forward-char -2) | |
| 578 (looking-at "\\*/"))) | |
| 579 (search-backward "/*" lim 'move)) | |
| 580 ((and | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
581 (search-backward "//" (max (c++-point-bol) lim) 'move) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
582 (not (c++-within-string-p (point) opoint)))) |
| 257 | 583 (t (beginning-of-line) |
| 584 (skip-chars-forward " \t") | |
| 585 (if (looking-at "#") | |
| 586 (setq stop (<= (point) lim)) | |
| 587 (setq stop t) | |
| 588 (goto-char opoint))))))) | |
| 589 | |
| 590 (defun indent-c++-exp () | |
| 591 "Indent each line of the C++ grouping following point." | |
| 592 (interactive) | |
| 593 (let ((indent-stack (list nil)) | |
| 594 (contain-stack (list (point))) | |
| 595 (case-fold-search nil) | |
| 596 restart outer-loop-done inner-loop-done state ostate | |
|
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
597 this-indent last-sexp last-depth |
| 257 | 598 at-else at-brace |
| 599 (opoint (point)) | |
| 600 (next-depth 0)) | |
| 601 (save-excursion | |
| 602 (forward-sexp 1)) | |
| 603 (save-excursion | |
| 604 (setq outer-loop-done nil) | |
| 605 (while (and (not (eobp)) (not outer-loop-done)) | |
| 606 (setq last-depth next-depth) | |
| 607 ;; Compute how depth changes over this line | |
| 608 ;; plus enough other lines to get to one that | |
| 609 ;; does not end inside a comment or string. | |
| 610 ;; Meanwhile, do appropriate indentation on comment lines. | |
|
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
611 (setq inner-loop-done nil) |
|
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
612 (while (and (not inner-loop-done) |
| 257 | 613 (not (and (eobp) (setq outer-loop-done t)))) |
| 614 (setq ostate state) | |
| 615 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point)) | |
| 616 nil nil state)) | |
| 617 (setq next-depth (car state)) | |
| 618 (if (and (car (cdr (cdr state))) | |
| 619 (>= (car (cdr (cdr state))) 0)) | |
| 620 (setq last-sexp (car (cdr (cdr state))))) | |
| 621 (if (or (nth 4 ostate)) | |
| 622 (c++-indent-line)) | |
| 623 (if (or (nth 3 state)) | |
| 624 (forward-line 1) | |
|
861
345296f94a1e
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
846
diff
changeset
|
625 (setq inner-loop-done t))) |
| 257 | 626 (if (<= next-depth 0) |
| 627 (setq outer-loop-done t)) | |
| 628 (if outer-loop-done | |
| 629 nil | |
| 630 ;; If this line had ..))) (((.. in it, pop out of the levels | |
| 631 ;; that ended anywhere in this line, even if the final depth | |
| 632 ;; doesn't indicate that they ended. | |
| 633 (while (> last-depth (nth 6 state)) | |
| 634 (setq indent-stack (cdr indent-stack) | |
| 635 contain-stack (cdr contain-stack) | |
| 636 last-depth (1- last-depth))) | |
| 637 (if (/= last-depth next-depth) | |
| 638 (setq last-sexp nil)) | |
| 639 ;; Add levels for any parens that were started in this line. | |
| 640 (while (< last-depth next-depth) | |
| 641 (setq indent-stack (cons nil indent-stack) | |
| 642 contain-stack (cons nil contain-stack) | |
| 643 last-depth (1+ last-depth))) | |
| 644 (if (null (car contain-stack)) | |
| 645 (setcar contain-stack (or (car (cdr state)) | |
| 646 (save-excursion (forward-sexp -1) | |
| 647 (point))))) | |
| 648 (forward-line 1) | |
| 649 (skip-chars-forward " \t") | |
| 650 (if (eolp) | |
| 651 nil | |
| 652 (if (and (car indent-stack) | |
| 653 (>= (car indent-stack) 0)) | |
| 654 ;; Line is on an existing nesting level. | |
| 655 ;; Lines inside parens are handled specially. | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
656 (if (/= (char-after (car contain-stack)) ?\{) |
| 257 | 657 (setq this-indent (car indent-stack)) |
| 658 ;; Line is at statement level. | |
| 659 ;; Is it a new statement? Is it an else? | |
| 660 ;; Find last non-comment character before this line | |
| 661 (save-excursion | |
| 662 (setq at-else (looking-at "else\\W")) | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
663 (setq at-brace (= (following-char) ?\{)) |
| 257 | 664 (c++-backward-to-noncomment opoint) |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
665 (if (not (memq (preceding-char) '(nil ?\, ?\; ?\} ?: ?\{))) |
| 257 | 666 ;; Preceding line did not end in comma or semi; |
| 667 ;; indent this line c-continued-statement-offset | |
| 668 ;; more than previous. | |
| 669 (progn | |
| 670 (c-backward-to-start-of-continued-exp | |
| 671 (car contain-stack)) | |
| 672 (setq this-indent | |
| 673 (+ c-continued-statement-offset | |
| 674 (current-column) | |
| 675 (if at-brace c-continued-brace-offset 0)))) | |
| 676 ;; Preceding line ended in comma or semi; | |
| 677 ;; use the standard indent for this level. | |
| 678 (if at-else | |
| 679 (progn (c-backward-to-start-of-if opoint) | |
| 680 (setq this-indent (current-indentation))) | |
| 681 (setq this-indent (car indent-stack)))))) | |
| 682 ;; Just started a new nesting level. | |
| 683 ;; Compute the standard indent for this level. | |
| 684 (let ((val (calculate-c++-indent | |
| 685 (if (car indent-stack) | |
| 686 (- (car indent-stack)))))) | |
| 687 (setcar indent-stack | |
| 688 (setq this-indent val)))) | |
| 689 ;; Adjust line indentation according to its contents | |
| 690 (if (looking-at "\\(public\\|private\\|protected\\):") | |
| 691 (setq this-indent (- this-indent c-indent-level))) | |
| 692 (if (or (looking-at "case[ \t]") | |
| 693 (and (looking-at "[A-Za-z]") | |
| 694 (save-excursion | |
| 695 (forward-sexp 1) | |
| 696 (looking-at ":[^:]")))) | |
| 697 (setq this-indent (max 1 (+ this-indent c-label-offset)))) | |
| 698 (if (looking-at "friend[ \t]class[ \t]") | |
| 699 (setq this-indent (+ this-indent c++-friend-offset))) | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
700 (if (= (following-char) ?\}) |
| 257 | 701 (setq this-indent (- this-indent c-indent-level))) |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
702 (if (= (following-char) ?\{) |
| 257 | 703 (setq this-indent (+ this-indent c-brace-offset))) |
| 704 ;; Put chosen indentation into effect. | |
| 705 (or (= (current-column) this-indent) | |
| 706 (= (following-char) ?\#) | |
| 707 (progn | |
| 708 (delete-region (point) (progn (beginning-of-line) (point))) | |
| 709 (indent-to this-indent))) | |
| 710 ;; Indent any comment following the text. | |
| 711 (or (looking-at comment-start-skip) | |
| 712 (if (re-search-forward comment-start-skip | |
| 713 (save-excursion (end-of-line) | |
| 714 (point)) t) | |
| 715 (progn | |
| 716 (indent-for-comment) | |
| 717 (beginning-of-line)))))))))) | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
718 |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
719 (defun fill-c++-comment () |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
720 "Fill a comment contained in consecutive lines containing point. |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
721 The fill lines remain a comment." |
| 257 | 722 (interactive) |
| 723 (save-excursion | |
| 724 (let ((save fill-prefix)) | |
| 725 (beginning-of-line 1) | |
| 726 (save-excursion | |
| 727 (re-search-forward comment-start-skip | |
| 728 (save-excursion (end-of-line) (point)) | |
| 729 t) | |
| 730 (goto-char (match-end 0)) | |
| 731 (set-fill-prefix)) | |
| 732 (while (looking-at fill-prefix) | |
| 733 (previous-line 1)) | |
| 734 (next-line 1) | |
| 735 (insert-string "\n") | |
| 736 (fill-paragraph nil) | |
| 737 (delete-char -1) | |
| 738 (setq fill-prefix save)))) | |
| 739 | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
740 (defun c++-point-bol () |
| 257 | 741 "Returns the value of the point at the beginning of the current line." |
| 742 (save-excursion | |
| 743 (beginning-of-line) | |
| 744 (point))) | |
| 745 | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
746 ;; (defun c++-insert-header () |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
747 ;; "Insert header denoting C++ code at top of buffer." |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
748 ;; (interactive) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
749 ;; (save-excursion |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
750 ;; (goto-char (point-min)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
751 ;; (insert "// " |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
752 ;; "This may look like C code, but it is really " |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
753 ;; "-*- C++ -*-" |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
754 ;; "\n\n"))) |
| 257 | 755 |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
756 (defun c++-within-string-p (point1 point2) |
| 257 | 757 "Returns true if number of double quotes between two points is odd." |
| 758 (let ((s (buffer-substring point1 point2))) | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
759 (not (zerop (% (c++-count-char-in-string ?\" s) 2))))) |
| 257 | 760 |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
761 (defun c++-count-char-in-string (c s) |
| 257 | 762 (let ((count 0) |
| 763 (pos 0)) | |
| 764 (while (< pos (length s)) | |
| 765 (setq count (+ count (if (\= (aref s pos) c) 1 0))) | |
| 766 (setq pos (1+ pos))) | |
| 767 count)) | |
| 768 | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
769 ;; rms: This page is creeping featurism, and not worth having. |
| 257 | 770 |
| 771 ;;; Below are two regular expressions that attempt to match defuns | |
| 772 ;;; "strongly" and "weakly." The strong one almost reconstructs the | |
| 773 ;;; grammar of C++; the weak one just figures anything id or curly on | |
| 774 ;;; the left begins a defun. The constant "c++-match-header-strongly" | |
| 775 ;;; determines which to use; the default is the weak one. | |
| 776 | |
|
846
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
777 ;; (defvar c++-match-header-strongly nil |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
778 ;; "*If nil, use `c++-defun-header-weak' to identify beginning of definitions. |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
779 ;; If non-nil, use `c++-defun-header-strong'.") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
780 ;; |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
781 ;; (defvar c++-defun-header-strong-struct-equivs "\\(class\\|struct\\|enum\\)" |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
782 ;; "Regexp to match names of structure declaration blocks in C++.") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
783 ;; |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
784 ;; (defconst c++-defun-header-strong |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
785 ;; (let* |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
786 ;; (; valid identifiers |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
787 ;; ;; There's a real wierdness here -- if I switch the below |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
788 ;; (id "\\(\\w\\|_\\)+") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
789 ;; ;; to be |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
790 ;; ;; (id "\\(_\\|\\w\\)+") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
791 ;; ;; things no longer work right. Try it and see! |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
792 ;; |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
793 ;; ; overloadable operators |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
794 ;; (op-sym1 |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
795 ;; "[---+*/%^&|~!=<>]\\|[---+*/%^&|<>=!]=\\|<<=?\\|>>=?") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
796 ;; (op-sym2 |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
797 ;; "&&\\|||\\|\\+\\+\\|--\\|()\\|\\[\\]") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
798 ;; (op-sym (concat "\\(" op-sym1 "\\|" op-sym2 "\\)")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
799 ;; ; whitespace |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
800 ;; (middle "[^\\*]*\\(\\*+[^/\\*][^\\*]*\\)*") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
801 ;; (c-comment (concat "/\\*" middle "\\*+/")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
802 ;; (wh (concat "\\(\\s \\|\n\\|//.*$\\|" c-comment "\\)")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
803 ;; (wh-opt (concat wh "*")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
804 ;; (wh-nec (concat wh "+")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
805 ;; (oper (concat "\\(" "operator" "\\(" |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
806 ;; wh-opt op-sym "\\|" wh-nec id "\\)" "\\)")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
807 ;; (dcl-list "([^():]*)") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
808 ;; (func-name (concat "\\(" oper "\\|" id "::" id "\\|" id "\\)")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
809 ;; (inits |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
810 ;; (concat "\\(:" |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
811 ;; "\\(" wh-opt id "(.*\\()" wh-opt "," "\\)\\)*" |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
812 ;; wh-opt id "(.*)" wh-opt "{" |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
813 ;; "\\|" wh-opt "{\\)")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
814 ;; (type-name (concat |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
815 ;; "\\(" c++-defun-header-strong-struct-equivs wh-nec "\\)?" |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
816 ;; id)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
817 ;; (type (concat "\\(const" wh-nec "\\)?" |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
818 ;; "\\(" type-name "\\|" type-name wh-opt "\\*+" "\\|" |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
819 ;; type-name wh-opt "&" "\\)")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
820 ;; (modifier "\\(inline\\|virtual\\|overload\\|auto\\|static\\)") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
821 ;; (modifiers (concat "\\(" modifier wh-nec "\\)*")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
822 ;; (func-header |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
823 ;; ;; type arg-dcl |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
824 ;; (concat modifiers type wh-nec func-name wh-opt dcl-list wh-opt inits)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
825 ;; (inherit (concat "\\(:" wh-opt "\\(public\\|private\\)?" |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
826 ;; wh-nec id "\\)")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
827 ;; (cs-header (concat |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
828 ;; c++-defun-header-strong-struct-equivs |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
829 ;; wh-nec id wh-opt inherit "?" wh-opt "{"))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
830 ;; (concat "^\\(" func-header "\\|" cs-header "\\)")) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
831 ;; "Strongly-defined regexp to match beginning of structure or function def.") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
832 ;; |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
833 ;; |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
834 ;; ;; This part has to do with recognizing defuns. |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
835 ;; |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
836 ;; ;; The weak convention we will use is that a defun begins any time |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
837 ;; ;; there is a left curly brace, or some identifier on the left margin, |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
838 ;; ;; followed by a left curly somewhere on the line. (This will also |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
839 ;; ;; incorrectly match some continued strings, but this is after all |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
840 ;; ;; just a weak heuristic.) Suggestions for improvement (short of the |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
841 ;; ;; strong scheme shown above) are welcomed. |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
842 ;; |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
843 ;; (defconst c++-defun-header-weak "^{\\|^[_a-zA-Z].*{" |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
844 ;; "Weakly-defined regexp to match beginning of structure or function def.") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
845 ;; |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
846 ;; (defun c++-beginning-of-defun (arg) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
847 ;; (interactive "p") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
848 ;; (let ((c++-defun-header (if c++-match-header-strongly |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
849 ;; c++-defun-header-strong |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
850 ;; c++-defun-header-weak))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
851 ;; (cond ((or (= arg 0) (and (> arg 0) (bobp))) nil) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
852 ;; ((and (not (looking-at c++-defun-header)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
853 ;; (let ((curr-pos (point)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
854 ;; (open-pos (if (search-forward "{" nil 'move) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
855 ;; (point))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
856 ;; (beg-pos |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
857 ;; (if (re-search-backward c++-defun-header nil 'move) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
858 ;; (match-beginning 0)))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
859 ;; (if (and open-pos beg-pos |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
860 ;; (< beg-pos curr-pos) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
861 ;; (> open-pos curr-pos)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
862 ;; (progn |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
863 ;; (goto-char beg-pos) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
864 ;; (if (= arg 1) t nil));; Are we done? |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
865 ;; (goto-char curr-pos) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
866 ;; nil)))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
867 ;; (t |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
868 ;; (if (and (looking-at c++-defun-header) (not (bobp))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
869 ;; (forward-char (if (< arg 0) 1 -1))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
870 ;; (and (re-search-backward c++-defun-header nil 'move (or arg 1)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
871 ;; (goto-char (match-beginning 0))))))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
872 ;; |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
873 ;; |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
874 ;; (defun c++-end-of-defun (arg) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
875 ;; (interactive "p") |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
876 ;; (let ((c++-defun-header (if c++-match-header-strongly |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
877 ;; c++-defun-header-strong |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
878 ;; c++-defun-header-weak))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
879 ;; (if (and (eobp) (> arg 0)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
880 ;; nil |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
881 ;; (if (and (> arg 0) (looking-at c++-defun-header)) (forward-char 1)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
882 ;; (let ((pos (point))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
883 ;; (c++-beginning-of-defun |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
884 ;; (if (< arg 0) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
885 ;; (- (- arg (if (eobp) 0 1))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
886 ;; arg)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
887 ;; (if (and (< arg 0) (bobp)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
888 ;; t |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
889 ;; (if (re-search-forward c++-defun-header nil 'move) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
890 ;; (progn (forward-char -1) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
891 ;; (forward-sexp) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
892 ;; (beginning-of-line 2))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
893 ;; (if (and (= pos (point)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
894 ;; (re-search-forward c++-defun-header nil 'move)) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
895 ;; (c++-end-of-defun 1)))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
896 ;; t))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
897 ;; |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
898 ;; (defun c++-indent-defun () |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
899 ;; "Indents the current function definition, struct or class declaration." |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
900 ;; (interactive) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
901 ;; (let ((restore (point))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
902 ;; (c++-end-of-defun 1) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
903 ;; (beginning-of-line 1) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
904 ;; (let ((end (point))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
905 ;; (c++-beginning-of-defun 1) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
906 ;; (while (<= (point) end) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
907 ;; (c++-indent-line) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
908 ;; (next-line 1) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
909 ;; (beginning-of-line 1))) |
|
20674ae6bf52
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
798
diff
changeset
|
910 ;; (goto-char restore))) |
|
662
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
911 |
|
8a533acedb77
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
257
diff
changeset
|
912 ;;; c++-mode.el ends here |
