annotate lisp/progmodes/cc-cmds.el @ 24826:a134726a4a15

(getf): Don't call get*.
author Karl Heuer <kwzh@gnu.org>
date Sat, 12 Jun 1999 03:36:46 +0000
parents 2986e6d0e927
children 03befb219d03
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1 ;;; cc-cmds.el --- user level commands for CC Mode
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Softare Foundation, Inc.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
5 ;; Authors: 1998 Barry A. Warsaw and Martin Stjernholm
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
6 ;; 1992-1997 Barry A. Warsaw
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; 1987 Dave Detlefs and Stewart Clamen
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; 1985 Richard M. Stallman
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
9 ;; Maintainer: bug-cc-mode@gnu.org
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; Created: 22-Apr-1997 (split from cc-mode.el)
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
11 ;; Version: See cc-mode.el
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
12 ;; Keywords: c languages oop
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14 ;; This file is part of GNU Emacs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16 ;; GNU Emacs is free software; you can redistribute it and/or modify
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; it under the terms of the GNU General Public License as published by
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; the Free Software Foundation; either version 2, or (at your option)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
19 ;; any later version.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; GNU Emacs is distributed in the hope that it will be useful,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; GNU General Public License for more details.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26 ;; You should have received a copy of the GNU General Public License
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;; Boston, MA 02111-1307, USA.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
18843
6e04c0670f55 Require cc-defs for the c-add-syntax macro.
Richard M. Stallman <rms@gnu.org>
parents: 18720
diff changeset
31
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
32
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
33 (eval-when-compile
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
34 (require 'cc-defs))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
35
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
36 (defun c-calculate-state (arg prevstate)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37 ;; Calculate the new state of PREVSTATE, t or nil, based on arg. If
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
38 ;; arg is nil or zero, toggle the state. If arg is negative, turn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
39 ;; the state off, and if arg is positive, turn the state on
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
40 (if (or (not arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
41 (zerop (setq arg (prefix-numeric-value arg))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42 (not prevstate)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (> arg 0)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; Auto-newline and hungry-delete
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 (defun c-toggle-auto-state (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 "Toggle auto-newline feature.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 Optional numeric ARG, if supplied turns on auto-newline when positive,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 turns it off when negative, and just toggles it when zero.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 When the auto-newline feature is enabled (as evidenced by the `/a' or
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 `/ah' on the modeline after the mode name) newlines are automatically
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 inserted after special characters such as brace, comma, semi-colon,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 and colon."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 (interactive "P")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57 (c-update-modeline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 (defun c-toggle-hungry-state (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 "Toggle hungry-delete-key feature.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 Optional numeric ARG, if supplied turns on hungry-delete when positive,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 turns it off when negative, and just toggles it when zero.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 When the hungry-delete-key feature is enabled (as evidenced by the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 `/h' or `/ah' on the modeline after the mode name) the delete key
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 gobbles all preceding whitespace in one fell swoop."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 (interactive "P")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 (setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 (c-update-modeline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 (defun c-toggle-auto-hungry-state (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 "Toggle auto-newline and hungry-delete-key features.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 Optional numeric ARG, if supplied turns on auto-newline and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 hungry-delete when positive, turns them off when negative, and just
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
77 toggles them when zero.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79 See `c-toggle-auto-state' and `c-toggle-hungry-state' for details."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (interactive "P")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 (setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 (c-update-modeline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
85
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
86
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 ;; Electric keys
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 ;; Note: In XEmacs 20.3 the Delete and BackSpace keysyms have been
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
90 ;; separated and "\177" is no longer an alias for both keys. Also,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 ;; the variable delete-key-deletes-forward controls in which direction
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92 ;; the Delete keysym deletes characters. The functions
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93 ;; c-electric-delete and c-electric-backspace attempt to deal with
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; this new functionality. For Emacs 19 and XEmacs 19 backwards
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95 ;; compatibility, the old behavior has moved to c-electric-backspace
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;; and c-backspace-function.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 (defun c-electric-backspace (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 "Deletes preceding character or whitespace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 If `c-hungry-delete-key' is non-nil, as evidenced by the \"/h\" or
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 \"/ah\" string on the mode line, then all preceding whitespace is
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 consumed. If however an ARG is supplied, or `c-hungry-delete-key' is
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 nil, or point is inside a literal then the function in the variable
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104 `c-backspace-function' is called.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 See also \\[c-electric-delete]."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
107 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108 (if (or (not c-hungry-delete-key)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 arg
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
110 (c-in-literal))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
111 (funcall c-backspace-function (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112 (let ((here (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 (skip-chars-backward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
114 (if (/= (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (delete-region (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 (funcall c-backspace-function 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (defun c-electric-delete (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 "Deletes preceding or following character or whitespace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 The behavior of this function depends on the variable
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 `delete-key-deletes-forward'. If this variable is nil (or does not
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 exist, as in older Emacsen), then this function behaves identical to
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125 \\[c-electric-backspace].
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
127 If `delete-key-deletes-forward' is non-nil and is supported in your
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
128 Emacs, then deletion occurs in the forward direction. So if
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
129 `c-hungry-delete-key' is non-nil, as evidenced by the \"/h\" or
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
130 \"/ah\" string on the mode line, then all following whitespace is
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
131 consumed. If however an ARG is supplied, or `c-hungry-delete-key' is
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
132 nil, or point is inside a literal then the function in the variable
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
133 `c-delete-function' is called."
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
134 (interactive "*P")
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
135 (if (or (and (fboundp 'delete-forward-p) ;XEmacs 21
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
136 (delete-forward-p))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
137 (and (boundp 'delete-key-deletes-forward) ;XEmacs 20
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
138 delete-key-deletes-forward))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 (if (or (not c-hungry-delete-key)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 arg
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (c-in-literal))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142 (funcall c-delete-function (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (let ((here (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (skip-chars-forward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 (if (/= (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (delete-region (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 (funcall c-delete-function 1))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 ;; act just like c-electric-backspace
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (c-electric-backspace arg)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (defun c-electric-pound (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 "Electric pound (`#') insertion.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 Inserts a `#' character specially depending on the variable
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 `c-electric-pound-behavior'. If a numeric ARG is supplied, or if
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 point is inside a literal, nothing special happens."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
156 (interactive "*P")
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
157 (if (or arg
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
158 (not (memq 'alignleft c-electric-pound-behavior))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
159 (save-excursion (skip-chars-backward " \t") (not (bolp)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
160 (c-in-literal))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 ;; do nothing special
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 ;; place the pound character at the left edge
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (let ((pos (- (point-max) (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165 (bolp (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 (delete-horizontal-space)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 (insert-char last-command-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (and (not bolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (goto-char (- (point-max) pos)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (defun c-electric-brace (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 "Insert a brace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 If the auto-newline feature is turned on, as evidenced by the \"/a\"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 or \"/ah\" string on the mode line, newlines are inserted before and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 after braces based on the value of `c-hanging-braces-alist'.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 Also, the line is re-indented unless a numeric ARG is supplied, there
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 are non-whitespace characters present on the line after the brace, or
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
182 the brace is inserted inside a literal.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
183
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
184 This function does various newline cleanups based on the value of
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
185 `c-cleanup-list'."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
186 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (let* ((c-state-cache (c-parse-state))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (safepos (c-safe-position (point) c-state-cache))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (literal (c-in-literal safepos)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 ;; if we're in a literal, or we're not at the end of the line, or
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 ;; a numeric arg is provided, or auto-newlining is turned off,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 ;; then just insert the character.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
193 (if (or literal
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
194 arg
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (not (looking-at "[ \t]*$")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (self-insert-command (prefix-numeric-value arg))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
197 (let* ((syms
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
198 ;; This is the list of brace syntactic symbols that can
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
199 ;; hang. If any new ones are added to c-offsets-alist,
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
200 ;; they should be added here as well.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
201 '(class-open class-close defun-open defun-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
202 inline-open inline-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
203 brace-list-open brace-list-close
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
204 brace-list-intro brace-entry-open
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
205 block-open block-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
206 substatement-open statement-case-open
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
207 extern-lang-open extern-lang-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
208 namespace-open namespace-close
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
209 inexpr-class-open inexpr-class-close
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
210 ))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;; we want to inhibit blinking the paren since this will
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 ;; be most disruptive. we'll blink it ourselves later on
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (old-blink-paren blink-paren-function)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 blink-paren-function
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (insertion-point (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 delete-temp-newline
19306
974544be1a17 (c-electric-brace): Make preserve-p nil at BOB.
Richard M. Stallman <rms@gnu.org>
parents: 19297
diff changeset
217 (preserve-p (and (not (bobp))
974544be1a17 (c-electric-brace): Make preserve-p nil at BOB.
Richard M. Stallman <rms@gnu.org>
parents: 19297
diff changeset
218 (eq ?\ (char-syntax (char-before)))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 ;; shut this up too
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 (c-echo-syntactic-information-p nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (syntax (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ;; only insert a newline if there is
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ;; non-whitespace behind us
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (skip-chars-backward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 (not (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (progn (newline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (setq delete-temp-newline t)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ;; state cache doesn't change
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (c-guess-basic-syntax)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (newlines (and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 c-auto-newline
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
234 (or (c-lookup-lists
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
235 syms
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
236 ;; Substitute inexpr-class and class-open
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
237 ;; or class-close with inexpr-class-open
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
238 ;; or inexpr-class-close.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
239 (if (assq 'inexpr-class syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
240 (cond ((assq 'class-open syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
241 '((inexpr-class-open)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
242 ((assq 'class-close syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
243 '((inexpr-class-close)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
244 (t syntax))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
245 syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
246 c-hanging-braces-alist)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 '(ignore before after)))))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
248 ;; Do not try to insert newlines around a special (Pike-style)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
249 ;; brace list.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
250 (if (and c-special-brace-lists
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
251 (c-intersect-lists '(brace-list-open brace-list-close
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
252 brace-list-intro brace-entry-open)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
253 syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
254 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
255 (c-safe (if (= (char-before) ?{)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
256 (forward-char -1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
257 (c-forward-sexp -1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
258 (c-looking-at-special-brace-list))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
259 (setq newlines nil))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 ;; If syntax is a function symbol, then call it using the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 ;; defined semantics.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (if (and (not (consp (cdr newlines)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 (functionp (cdr newlines)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (let ((c-syntactic-context syntax))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (setq newlines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (funcall (cdr newlines) (car newlines) insertion-point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 ;; does a newline go before the open brace?
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 (if (memq 'before newlines)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 ;; we leave the newline we've put in there before,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 ;; but we need to re-indent the line above
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (let ((pos (- (point-max) (point)))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
272 (here (point)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (forward-line -1)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
274 (let ((c-state-cache (c-whack-state (point) c-state-cache)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
275 ;; we may need to update the cache. this should
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
276 ;; still be faster than recalculating the state
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
277 ;; in many cases
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
278 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
279 (save-restriction
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
280 (narrow-to-region here (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
281 (if (and (c-safe (progn (backward-up-list -1) t))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
282 (memq (char-before) '(?\) ?}))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
283 (progn (widen)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
284 (c-safe (progn (c-forward-sexp -1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
285 t))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
286 (setq c-state-cache
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
287 (c-hack-state (point) 'open c-state-cache)))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
288 (c-indent-line))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
289 (setq c-state-cache (c-adjust-state (c-point 'bol) here
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
290 (- (point) (c-point 'bol))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
291 c-state-cache))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (goto-char (- (point-max) pos))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 ;; if the buffer has changed due to the indentation, we
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 ;; need to recalculate syntax for the current line, but
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 ;; we won't need to update the state cache.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296 (if (/= (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
297 (setq syntax (c-guess-basic-syntax))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 ;; must remove the newline we just stuck in (if we really did it)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
299 (and delete-temp-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
300 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
301 ;; if there is whitespace before point, then preserve
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302 ;; at least one space.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (delete-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 (just-one-space)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 (if (not preserve-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (delete-char -1))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 ;; since we're hanging the brace, we need to recalculate
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 ;; syntax. Update the state to accurately reflect the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 ;; beginning of the line. We punt if we cross any open or
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 ;; closed parens because its just too hard to modify the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 ;; known state. This limitation will be fixed in v5.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 (let ((bol (c-point 'bol)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (if (zerop (car (parse-partial-sexp bol (1- (point)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (setq c-state-cache (c-whack-state bol c-state-cache)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 syntax (c-guess-basic-syntax))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 ;; gotta punt. this requires some horrible kludgery
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (makunbound 'c-state-cache)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (setq c-state-cache (c-parse-state)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 syntax nil))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 ;; now adjust the line's indentation. don't update the state
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 ;; cache since c-guess-basic-syntax isn't called when the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 ;; syntax is passed to c-indent-line
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
326 (let* ((here (point)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
327 (c-indent-line syntax)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 (setq c-state-cache (c-adjust-state (c-point 'bol) here
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
329 (- (c-point 'boi) (c-point 'bol))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
330 c-state-cache)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 ;; Do all appropriate clean ups
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (let ((here (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 (pos (- (point-max) (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 mbeg mend)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 ;; clean up empty defun braces
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (if (and c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (memq 'empty-defun-braces c-cleanup-list)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (eq last-command-char ?\})
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (c-intersect-lists '(defun-close class-close inline-close)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 syntax)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (skip-chars-backward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (eq (char-before) ?\{))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 ;; make sure matching open brace isn't in a comment
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (not (c-in-literal)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (delete-region (point) (1- here)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 ;; clean up brace-else-brace
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (if (and c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (memq 'brace-else-brace c-cleanup-list)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (eq last-command-char ?\{)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (re-search-backward "}[ \t\n]*else[ \t\n]*{" nil t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (setq mbeg (match-beginning 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 mend (match-end 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 (= mend here))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 (not (c-in-literal)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (delete-region mbeg mend)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 (insert "} else {")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (goto-char (- (point-max) pos))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 ;; does a newline go after the brace?
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 (if (memq 'after newlines)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (newline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 ;; update on c-state-cache
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 (let* ((bufpos (- (point) 2))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (which (if (eq (char-after bufpos) ?{) 'open 'close))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (c-state-cache (c-hack-state bufpos which c-state-cache)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (c-indent-line))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 ;; blink the paren
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 (and (eq last-command-char ?\})
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 old-blink-paren
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (c-backward-syntactic-ws safepos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (funcall old-blink-paren)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 ))))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
379
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 (defun c-electric-slash (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 "Insert a slash character.
19297
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
382
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
383 Indent the line as a comment, if:
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
384
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
385 1. The slash is second of a `//' line oriented comment introducing
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
386 token and we are on a comment-only-line, or
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
387
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
388 2. The slash is part of a `*/' token that closes a block oriented
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
389 comment.
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
390
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 If numeric ARG is supplied or point is inside a literal, indentation
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 is inhibited."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
393 (interactive "*P")
19297
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
394 (let* ((ch (char-before))
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
395 (indentp (and (not arg)
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
396 (eq last-command-char ?/)
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
397 (or (and (eq ch ?/)
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
398 (not (c-in-literal)))
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
399 (and (eq ch ?*)
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
400 (c-in-literal)))
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
401 ))
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
402 ;; shut this up
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
403 (c-echo-syntactic-information-p nil))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (if indentp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (c-indent-line))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (defun c-electric-star (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 "Insert a star character.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 If the star is the second character of a C style comment introducing
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 construct, and we are on a comment-only-line, indent line as comment.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 If numeric ARG is supplied or point is inside a literal, indentation
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 is inhibited."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
414 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 ;; if we are in a literal, or if arg is given do not re-indent the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 ;; current line, unless this star introduces a comment-only line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (if (and (not arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (memq (c-in-literal) '(c))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (eq (char-before) ?*)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (skip-chars-backward "*")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424 (if (eq (char-before) ?/)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (forward-char -1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (skip-chars-backward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 ;; shut this up
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (let (c-echo-syntactic-information-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (c-indent-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 ))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
432
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (defun c-electric-semi&comma (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 "Insert a comma or semicolon.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 When the auto-newline feature is turned on, as evidenced by the \"/a\"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 or \"/ah\" string on the mode line, a newline might be inserted. See
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 the variable `c-hanging-semi&comma-criteria' for how newline insertion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 is determined.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440 When semicolon is inserted, the line is re-indented unless a numeric
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
441 arg is supplied, point is inside a literal, or there are
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
442 non-whitespace characters on the line following the semicolon.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
443
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
444 Based on the value of `c-cleanup-list', this function cleans up commas
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
445 following brace lists and semicolons following defuns."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
446 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (let* ((lim (c-most-enclosing-brace (c-parse-state)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 (literal (c-in-literal lim))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (here (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 ;; shut this up
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (c-echo-syntactic-information-p nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (if (or literal
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 arg
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (not (looking-at "[ \t]*$")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 ;; do some special stuff with the character
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (self-insert-command (prefix-numeric-value arg))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
458 ;; do all cleanups and newline insertions if c-auto-newline is
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
459 ;; turned on
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
460 (if (not c-auto-newline)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
461 (c-indent-line)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462 ;; clean ups
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (let ((pos (- (point-max) (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 (if (and (or (and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 (eq last-command-char ?,)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (memq 'list-close-comma c-cleanup-list))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 (and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 (eq last-command-char ?\;)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469 (memq 'defun-close-semi c-cleanup-list)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
472 (skip-chars-backward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (eq (char-before) ?}))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474 ;; make sure matching open brace isn't in a comment
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
475 (not (c-in-literal lim)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (delete-region (point) here))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (goto-char (- (point-max) pos)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 ;; re-indent line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (c-indent-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 ;; check to see if a newline should be added
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (let ((criteria c-hanging-semi&comma-criteria)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 answer add-newline-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (while criteria
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 (setq answer (funcall (car criteria)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 ;; only nil value means continue checking
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (if (not answer)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (setq criteria (cdr criteria))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 (setq criteria nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 ;; only 'stop specifically says do not add a newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 (setq add-newline-p (not (eq answer 'stop)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 ))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (if add-newline-p
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 (progn (newline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (c-indent-line)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 )))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (defun c-electric-colon (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 "Insert a colon.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 If the auto-newline feature is turned on, as evidenced by the \"/a\"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 or \"/ah\" string on the mode line, newlines are inserted before and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 after colons based on the value of `c-hanging-colons-alist'.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 Also, the line is re-indented unless a numeric ARG is supplied, there
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 are non-whitespace characters present on the line after the colon, or
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 the colon is inserted inside a literal.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 This function cleans up double colon scope operators based on the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 value of `c-cleanup-list'."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
510 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 (let* ((bod (c-point 'bod))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (literal (c-in-literal bod))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
513 syntax newlines is-scope-op
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 ;; shut this up
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (c-echo-syntactic-information-p nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (if (or literal
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 arg
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (not (looking-at "[ \t]*$")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 ;; insert the colon, then do any specified cleanups
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 (let ((pos (- (point-max) (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (here (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (if (and c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (memq 'scope-operator c-cleanup-list)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 (eq (char-before) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (skip-chars-backward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (eq (char-before) ?:))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (not (c-in-literal))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (not (eq (char-after (- (point) 2)) ?:)))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
533 (progn
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
534 (delete-region (point) (1- here))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
535 (setq is-scope-op t)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (goto-char (- (point-max) pos)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 ;; lets do some special stuff with the colon character
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (setq syntax (c-guess-basic-syntax)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 ;; some language elements can only be determined by
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 ;; checking the following line. Lets first look for ones
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 ;; that can be found when looking on the line with the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 ;; colon
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 newlines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (and c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (or (c-lookup-lists '(case-label label access-label)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 syntax c-hanging-colons-alist)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (c-lookup-lists '(member-init-intro inher-intro)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
548 (let ((buffer-undo-list t))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
549 (insert "\n")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
550 (unwind-protect
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
551 (c-guess-basic-syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
552 (delete-char -1)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 c-hanging-colons-alist))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 ;; indent the current line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (c-indent-line syntax)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 ;; does a newline go before the colon? Watch out for already
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 ;; non-hung colons. However, we don't unhang them because that
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 ;; would be a cleanup (and anti-social).
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (if (and (memq 'before newlines)
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
560 (not is-scope-op)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 (skip-chars-backward ": \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (not (bolp))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (let ((pos (- (point-max) (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 (newline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 (c-indent-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 (goto-char (- (point-max) pos))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
569 ;; does a newline go after the colon?
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
570 (if (and (memq 'after (cdr-safe newlines))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
571 (not is-scope-op))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (newline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 (c-indent-line)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 (defun c-electric-lt-gt (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 "Insert a less-than, or greater-than character.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
579 The line will be re-indented if the character inserted is the second
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
580 of a C++ style stream operator and the buffer is in C++ mode.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
581 Exceptions are when a numeric argument is supplied, or point is inside
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
582 a literal, in which case the line will not be re-indented."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
583 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
584 (let ((indentp (and (not arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 (eq (char-before) last-command-char)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
586 (not (c-in-literal))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 ;; shut this up
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 (c-echo-syntactic-information-p nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 (if indentp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 (c-indent-line))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
593 (defun c-electric-paren (arg)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
594 "Insert a parenthesis.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
595
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
596 If the auto-newline feature is turned on, as evidenced by the \"/a\"
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
597 or \"/ah\" string on the mode line, some newline cleanups are done if
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
598 appropriate; see the variable `c-cleanup-list'.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
599
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
600 Also, the line is re-indented unless a numeric ARG is supplied, there
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
601 are non-whitespace characters present on the line after the colon, or
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
602 the colon is inserted inside a literal."
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
603 (interactive "*P")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
604 (let (;; shut this up
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
605 (c-echo-syntactic-information-p nil))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
606 (if (or arg
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
607 (not (looking-at "[ \t]*$"))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
608 (c-in-literal (c-point 'bod)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
609 (self-insert-command (prefix-numeric-value arg))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
610 ;; do some special stuff with the character
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
611 (let* (;; We want to inhibit blinking the paren since this will
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
612 ;; be most disruptive. We'll blink it ourselves
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
613 ;; afterwards.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
614 (old-blink-paren blink-paren-function)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
615 blink-paren-function)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
616 (self-insert-command (prefix-numeric-value arg))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
617 (c-indent-line)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
618 (when c-auto-newline
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
619 ;; Do all appropriate clean ups
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
620 (let ((here (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
621 (pos (- (point-max) (point)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
622 mbeg mend)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
623 ;; clean up brace-elseif-brace
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
624 (if (and (memq 'brace-elseif-brace c-cleanup-list)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
625 (eq last-command-char ?\()
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
626 (re-search-backward "}[ \t\n]*else[ \t\n]+if[ \t\n]*("
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
627 nil t)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
628 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
629 (setq mbeg (match-beginning 0)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
630 mend (match-end 0))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
631 (= mend here))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
632 (not (c-in-literal)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
633 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
634 (delete-region mbeg mend)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
635 (insert "} else if (")))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
636 ;; clean up brace-catch-brace
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
637 (if (and (memq 'brace-catch-brace c-cleanup-list)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
638 (eq last-command-char ?\()
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
639 (re-search-backward "}[ \t\n]*catch[ \t\n]*(" nil t)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
640 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
641 (setq mbeg (match-beginning 0)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
642 mend (match-end 0))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
643 (= mend here))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
644 (not (c-in-literal)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
645 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
646 (delete-region mbeg mend)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
647 (insert "} catch (")))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
648 (goto-char (- (point-max) pos))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
649 ))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
650 (funcall old-blink-paren)))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
651
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
652
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 ;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655 ;; originally contributed by Terry_Glanfield.Southern@rxuk.xerox.com
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 (defun c-forward-into-nomenclature (&optional arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
657 "Move forward to end of a nomenclature section or word.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 With arg, to it arg times."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
660 (let ((case-fold-search nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
661 (if (> arg 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
662 (re-search-forward "\\W*\\([A-Z]*[a-z0-9]*\\)" (point-max) t arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 (while (and (< arg 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (re-search-backward
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 "\\(\\(\\W\\|[a-z0-9]\\)[A-Z]+\\|\\W\\w+\\)"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 (point-min) 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 (setq arg (1+ arg)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
671 (defun c-backward-into-nomenclature (&optional arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
672 "Move backward to beginning of a nomenclature section or word.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
673 With optional ARG, move that many times. If ARG is negative, move
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 forward."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 (c-forward-into-nomenclature (- arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
678
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 (defun c-scope-operator ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 "Insert a double colon scope operator at point.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 No indentation or other \"electric\" behavior is performed."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
682 (interactive "*")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 (insert "::"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
685 (defun c-beginning-of-defun (&optional arg)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
686 "Move backward to the beginning of a defun.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
687 With argument, do it that many times. Negative arg -N
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
688 means move forward to Nth following beginning of defun.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
689 Returns t unless search stops due to beginning or end of buffer.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
690
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
691 Unlike the built-in `beginning-of-defun' this tries to be smarter
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
692 about finding the char with open-parenthesis syntax that starts the
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
693 defun."
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
694 (interactive "p")
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
695 (if (< arg 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
696 (c-end-of-defun (- arg))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
697 (while (> arg 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
698 (let ((state (nreverse (c-parse-state)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
699 prevbod bod)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
700 (while (and state (not bod))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
701 (setq bod (car state)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
702 state (cdr state))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
703 (if (consp bod)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
704 (setq prevbod (car bod)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
705 bod nil)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
706 (cond
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
707 (bod (goto-char bod))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
708 (prevbod (goto-char prevbod))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
709 (t (goto-char (c-point 'bod)))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
710 (setq arg (1- arg))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
711 (c-keep-region-active))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
712
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
713 (defun c-end-of-defun (&optional arg)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
714 "Move forward to next end of defun. With argument, do it that many times.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
715 Negative argument -N means move back to Nth preceding end of defun.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
716
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
717 An end of a defun occurs right after the close-parenthesis that matches
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
718 the open-parenthesis that starts a defun; see `beginning-of-defun'."
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
719 (interactive "p")
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
720 (if (not arg)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
721 (setq arg 1))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
722 (if (< arg 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
723 (c-beginning-of-defun (- arg))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
724 (while (> arg 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
725 ;; skip down into the next defun-block
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
726 (while (and (c-safe (down-list 1) t)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
727 (not (eq (char-before) ?{)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
728 (forward-char -1)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
729 (c-forward-sexp))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
730 (c-beginning-of-defun 1)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
731 (c-forward-sexp 1)
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
732 (setq arg (1- arg)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
733 (forward-line 1))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
734 (c-keep-region-active))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
735
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 (defun c-beginning-of-statement (&optional count lim sentence-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 "Go to the beginning of the innermost C statement.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 With prefix arg, go back N - 1 statements. If already at the
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
740 beginning of a statement then go to the beginning of the closest
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
741 preceding one, moving into nested blocks if necessary (use
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
742 \\[backward-sexp] to skip over a block). If within a comment, or next
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
743 to a comment (only whitespace between), move by sentences instead of
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
744 statements.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 When called from a program, this function takes 3 optional args: the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 repetition count, a buffer position limit which is the farthest back
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 to search, and a flag saying whether to do sentence motion when in a
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 comment."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 (interactive (list (prefix-numeric-value current-prefix-arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 nil t))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
752 (let* ((count (or count 1))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
753 here
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
754 (range (c-collect-line-comments (c-literal-limits lim))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
755 (while (and (/= count 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
756 (or (not lim) (> (point) lim)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
757 (setq here (point))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
758 (if (and (not range) sentence-flag)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
759 (save-excursion
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
760 ;; Find the comment next to point if we're not in one.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
761 (if (> count 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
762 ;; Finding a comment backwards is a bit cumbersome
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
763 ;; because `forward-comment' regards every newline as
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
764 ;; a comment when searching backwards (Emacs 19.34).
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
765 (while (and (progn (skip-chars-backward " \t")
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
766 (setq range (point))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
767 (setq range (if (forward-comment -1)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
768 (cons (point) range)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
769 nil)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
770 (= (char-after) ?\n)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
771 (skip-chars-forward " \t\n")
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
772 (setq range (point))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
773 (setq range (if (forward-comment 1)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
774 (cons range (point))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
775 nil)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
776 (setq range (c-collect-line-comments range))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
777 (if (and (< count 0) (= here (point-max)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
778 ;; Special case because eob might be in a literal.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
779 (setq range nil))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
780 (if range
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
781 (if (and sentence-flag
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
782 (/= (char-syntax (char-after (car range))) ?\"))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
783 (progn
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
784 ;; move by sentence, but not past the limit of the literal
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
785 (save-restriction
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
786 (narrow-to-region (save-excursion
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
787 (goto-char (car range))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
788 (looking-at comment-start-skip)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
789 (goto-char (match-end 0))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
790 (point))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
791 (save-excursion
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
792 (goto-char (cdr range))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
793 (if (save-excursion
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
794 (goto-char (car range))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
795 (looking-at "/\\*"))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
796 (backward-char 2))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
797 (skip-chars-backward " \t\n")
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
798 (point)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
799 (c-safe (forward-sentence (if (> count 0) -1 1))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
800 ;; See if we should escape the literal.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
801 (if (> count 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
802 (if (< (point) here)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
803 (setq count (1- count))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
804 (goto-char (car range))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
805 (setq range nil))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
806 (if (> (point) here)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
807 (setq count (1+ count))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
808 (goto-char (cdr range))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
809 (setq range nil))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
810 (goto-char (if (> count 0) (car range) (cdr range)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
811 (setq range nil))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
812 ;; Below we do approximately the same as
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
813 ;; c-beginning-of-statement-1 and c-end-of-statement-1 and
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
814 ;; perhaps they should be changed, but that'd likely break a
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
815 ;; lot in cc-engine.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
816 (goto-char here)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
817 (if (> count 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
818 (if (condition-case nil
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
819 ;; Stop before `{' and after `;', `{', `}' and
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
820 ;; `};' when not followed by `}' or `)', but on
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
821 ;; the other side of the syntactic ws. Also stop
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
822 ;; before `}', but only to catch comments. Move
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
823 ;; by sexps and move into parens.
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
824 (catch 'done
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
825 (let (last)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
826 (while t
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
827 (setq last (point))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
828 (if (and (looking-at "[{}]")
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
829 (/= here last))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
830 (throw 'done (= (char-after) ?{)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
831 (c-backward-syntactic-ws)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
832 (cond ((bobp) ; Must handle bob specially.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
833 (if (= here last)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
834 (if (= last (point-min))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
835 (throw 'done t)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
836 (goto-char last)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
837 (throw 'done nil))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
838 (goto-char last)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
839 (throw 'done t)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
840 ((progn (backward-char)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
841 (looking-at "[;{}]"))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
842 (if (or (= here last)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
843 (memq (char-after last) '(?\) ?})))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
844 (if (and (= (char-before) ?})
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
845 (= (char-after) ?\;))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
846 (backward-char))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
847 (goto-char last)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
848 (throw 'done t)))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
849 ((= (char-syntax (char-after)) ?\")
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
850 (forward-char)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
851 (c-backward-sexp))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
852 ))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
853 (error
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
854 (goto-char (point-min))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
855 t))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
856 (setq count (1- count)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
857 (if (condition-case nil
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
858 ;; Stop before `{' and `}', but on the other side of
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
859 ;; the syntactic ws, and after `;', `}' and `};'.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
860 ;; Only stop before `{' if at top level or inside
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
861 ;; braces, though. Also stop after `{', but only to
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
862 ;; catch comments. Move by sexps and move into
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
863 ;; parens.
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
864 (catch 'done
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
865 (let (last)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
866 (while t
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
867 (setq last (point))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
868 (c-forward-syntactic-ws)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
869 (cond ((= (char-after) ?{)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
870 (if (or (= here last)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
871 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
872 (and (c-safe (progn (up-list -1) t))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
873 (/= (char-after) ?{))))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
874 (progn (forward-char)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
875 (throw 'done nil))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
876 (goto-char last)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
877 (throw 'done t)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
878 ((and (= (char-after) ?})
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
879 (/= here last))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
880 (goto-char last)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
881 (throw 'done t))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
882 ((looking-at ";\\|};?")
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
883 (goto-char (match-end 0))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
884 (throw 'done t))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
885 ((= (char-syntax (char-after)) ?\")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
886 (c-forward-sexp))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
887 (t
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
888 (forward-char))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
889 ))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
890 (error
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
891 (goto-char (point-max))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
892 t))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
893 (setq count (1+ count)))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
894 ;; If we haven't moved we're near a buffer limit.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
895 (when (= (point) here)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
896 (goto-char (if (> count 0) (point-min) (point-max)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
897 (setq count 0)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
898 ;; its possible we've been left up-buf of lim
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
899 (if lim (goto-char (max (point) lim))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
900 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
901
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
902 (defun c-end-of-statement (&optional count lim sentence-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
903 "Go to the end of the innermost C statement.
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
904 With prefix arg, go forward N - 1 statements. Move forward to the end
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
905 of the next statement if already at end, and move into nested blocks
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
906 \(use \\[forward-sexp] to skip over a block). If within a comment, or
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
907 next to a comment (only whitespace between), move by sentences instead
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
908 of statements.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
909
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
910 When called from a program, this function takes 3 optional args: the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
911 repetition count, a buffer position limit which is the farthest back
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
912 to search, and a flag saying whether to do sentence motion when in a
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
913 comment."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
914 (interactive (list (prefix-numeric-value current-prefix-arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
915 nil t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
916 (c-beginning-of-statement (- (or count 1)) lim sentence-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
917 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
918
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
919
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
920 ;; set up electric character functions to work with pending-del,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
921 ;; (a.k.a. delsel) mode. All symbols get the t value except
18843
6e04c0670f55 Require cc-defs for the c-add-syntax macro.
Richard M. Stallman <rms@gnu.org>
parents: 18720
diff changeset
922 ;; the functions which delete, which gets 'supersede.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
923 (mapcar
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
924 (function
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
925 (lambda (sym)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
926 (put sym 'delete-selection t) ; for delsel (Emacs)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
927 (put sym 'pending-delete t))) ; for pending-del (XEmacs)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
928 '(c-electric-pound
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
929 c-electric-brace
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
930 c-electric-slash
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
931 c-electric-star
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
932 c-electric-semi&comma
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
933 c-electric-lt-gt
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
934 c-electric-colon
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
935 c-electric-paren))
18843
6e04c0670f55 Require cc-defs for the c-add-syntax macro.
Richard M. Stallman <rms@gnu.org>
parents: 18720
diff changeset
936 (put 'c-electric-delete 'delete-selection 'supersede) ; delsel
6e04c0670f55 Require cc-defs for the c-add-syntax macro.
Richard M. Stallman <rms@gnu.org>
parents: 18720
diff changeset
937 (put 'c-electric-delete 'pending-delete 'supersede) ; pending-del
6e04c0670f55 Require cc-defs for the c-add-syntax macro.
Richard M. Stallman <rms@gnu.org>
parents: 18720
diff changeset
938 (put 'c-electric-backspace 'delete-selection 'supersede) ; delsel
6e04c0670f55 Require cc-defs for the c-add-syntax macro.
Richard M. Stallman <rms@gnu.org>
parents: 18720
diff changeset
939 (put 'c-electric-backspace 'pending-delete 'supersede) ; pending-del
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
940
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
941
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
942 ;; This is used by indent-for-comment to decide how much to indent a
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
943 ;; comment in C code based on its context.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
944 (defun c-comment-indent ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
945 (if (looking-at (concat "^\\(" c-comment-start-regexp "\\)"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
946 0 ;Existing comment at bol stays there.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
947 (let ((opoint (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
948 placeholder)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
949 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
950 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
951 (cond
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
952 ;; CASE 1: A comment following a solitary close-brace should
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
953 ;; have only one space.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
954 ((looking-at (concat "[ \t]*}[ \t]*\\($\\|"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
955 c-comment-start-regexp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
956 "\\)"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
957 (search-forward "}")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
958 (1+ (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
959 ;; CASE 2: 2 spaces after #endif
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
960 ((or (looking-at "^#[ \t]*endif[ \t]*")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
961 (looking-at "^#[ \t]*else[ \t]*"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
962 7)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
963 ;; CASE 3: when c-indent-comments-syntactically-p is t,
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
964 ;; calculate the offset according to c-offsets-alist.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
965 ;; E.g. identical to hitting TAB.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
966 ((and c-indent-comments-syntactically-p
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
967 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
968 (skip-chars-forward " \t")
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
969 (or (looking-at c-comment-start-regexp)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
970 (eolp))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
971 (let ((syntax (c-guess-basic-syntax)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
972 ;; BOGOSITY ALERT: if we're looking at the eol, its
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
973 ;; because indent-for-comment hasn't put the comment-start
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
974 ;; in the buffer yet. this will screw up the syntactic
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
975 ;; analysis so we kludge in the necessary info. Another
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
976 ;; kludge is that if we're at the bol, then we really want
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
977 ;; to ignore any anchoring as specified by
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
978 ;; c-comment-only-line-offset since it doesn't apply here.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
979 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
980 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
981 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
982 (eolp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
983 (c-add-syntax 'comment-intro))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
984 (let ((c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
985 (if (consp c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
986 c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
987 (cons c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
988 c-comment-only-line-offset))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
989 (apply '+ (mapcar 'c-get-offset syntax)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
990 ;; CASE 4: use comment-column if previous line is a
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
991 ;; comment-only line indented to the left of comment-column
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
992 ((save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
993 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
994 (and (not (bobp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
995 (forward-line -1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
996 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
997 (prog1
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
998 (looking-at c-comment-start-regexp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
999 (setq placeholder (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1000 (goto-char placeholder)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1001 (if (< (current-column) comment-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1002 comment-column
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1003 (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1004 ;; CASE 5: If comment-column is 0, and nothing but space
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1005 ;; before the comment, align it at 0 rather than 1.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1006 ((progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1007 (goto-char opoint)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1008 (skip-chars-backward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1009 (and (= comment-column 0) (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1010 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1011 ;; CASE 6: indent at comment column except leave at least one
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1012 ;; space.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1013 (t (max (1+ (current-column))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1014 comment-column))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 )))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016
19804
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1017
19297
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
1018 ;; for proposed new variable comment-line-break-function
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
1019 (defun c-comment-line-break-function (&optional soft)
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
1020 ;; we currently don't do anything with soft line breaks
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1021 (let ((literal (c-in-literal))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1022 at-comment-col)
19804
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1023 (cond
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1024 ((eq literal 'string)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1025 (insert ?\n))
19804
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1026 ((or (not c-comment-continuation-stars)
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1027 (not literal))
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1028 (indent-new-comment-line soft))
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1029 (t (let ((here (point))
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1030 (leader c-comment-continuation-stars))
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1031 (back-to-indentation)
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1032 ;; comment could be hanging
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1033 (if (not (c-in-literal))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1034 (progn
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1035 (forward-line 1)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1036 (forward-comment -1)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1037 (setq at-comment-col (= (current-column) comment-column))))
19804
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1038 ;; are we looking at a block or lines style comment?
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1039 (if (and (looking-at (concat "\\(" c-comment-start-regexp
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1040 "\\)[ \t]+"))
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1041 (string-equal (match-string 1) "//"))
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1042 ;; line style
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1043 (setq leader (match-string 0)))
19804
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1044 (goto-char here)
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1045 (delete-region (progn (skip-chars-backward " \t") (point))
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1046 (progn (skip-chars-forward " \t") (point)))
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1047 (newline)
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1048 ;; to avoid having an anchored comment that c-indent-line will
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1049 ;; trip up on
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1050 (insert " " leader)
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1051 (if at-comment-col
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1052 (indent-for-comment))
19804
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1053 (c-indent-line))))))
19297
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
1054
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
1055 ;; advice for indent-new-comment-line for older Emacsen
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1056 (or (boundp 'comment-line-break-function)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1057 (defadvice indent-new-comment-line (around c-line-break-advice
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1058 activate preactivate)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1059 "Calls c-comment-line-break-function if in a comment in CC Mode."
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1060 (if (or (not c-buffer-is-cc-mode)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1061 (not (c-in-literal))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1062 (not c-comment-continuation-stars))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1063 ad-do-it
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1064 (c-comment-line-break-function (ad-get-arg 0)))))
19297
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
1065
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1066 ;; used by outline-minor-mode
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1067 (defun c-outline-level ()
24447
8309f6535486 (c-outline-level): Bind
Dave Love <fx@gnu.org>
parents: 24282
diff changeset
1068 ;; This so that `current-column' DTRT in otherwise-hidden text.
8309f6535486 (c-outline-level): Bind
Dave Love <fx@gnu.org>
parents: 24282
diff changeset
1069 (let (buffer-invisibility-spec)
8309f6535486 (c-outline-level): Bind
Dave Love <fx@gnu.org>
parents: 24282
diff changeset
1070 (save-excursion
8309f6535486 (c-outline-level): Bind
Dave Love <fx@gnu.org>
parents: 24282
diff changeset
1071 (skip-chars-forward "\t ")
8309f6535486 (c-outline-level): Bind
Dave Love <fx@gnu.org>
parents: 24282
diff changeset
1072 (current-column))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1073
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1074
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1075 (defun c-up-conditional (count)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1076 "Move back to the containing preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1077 A prefix argument acts as a repeat count. With a negative argument,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1078 move forward to the end of the containing preprocessor conditional.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1079 When going backwards, `#elif' is treated like `#else' followed by
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1080 `#if'. When going forwards, `#elif' is ignored."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1081 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1082 (c-forward-conditional (- count) t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1083 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1084
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1085 (defun c-backward-conditional (count &optional up-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1086 "Move back across a preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1087 A prefix argument acts as a repeat count. With a negative argument,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1088 move forward across a preprocessor conditional."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1089 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1090 (c-forward-conditional (- count) up-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1091 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1092
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1093 (defun c-forward-conditional (count &optional up-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1094 "Move forward across a preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1095 A prefix argument acts as a repeat count. With a negative argument,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1096 move backward across a preprocessor conditional."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1097 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1098 (let* ((forward (> count 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1099 (increment (if forward -1 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1100 (search-function (if forward 're-search-forward 're-search-backward))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1101 (new))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1102 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1103 (while (/= count 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1104 (let ((depth (if up-flag 0 -1)) found)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1105 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1106 ;; Find the "next" significant line in the proper direction.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1107 (while (and (not found)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1108 ;; Rather than searching for a # sign that
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1109 ;; comes at the beginning of a line aside from
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1110 ;; whitespace, search first for a string
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1111 ;; starting with # sign. Then verify what
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1112 ;; precedes it. This is faster on account of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1113 ;; the fastmap feature of the regexp matcher.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1114 (funcall search-function
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1115 "#[ \t]*\\(if\\|elif\\|endif\\)"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1116 nil t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1117 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1118 ;; Now verify it is really a preproc line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1119 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\)")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1120 (let ((prev depth))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1121 ;; Update depth according to what we found.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1122 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1123 (cond ((looking-at "[ \t]*#[ \t]*endif")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1124 (setq depth (+ depth increment)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1125 ((looking-at "[ \t]*#[ \t]*elif")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1126 (if (and forward (= depth 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1127 (setq found (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1128 (t (setq depth (- depth increment))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1129 ;; If we are trying to move across, and we find an
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1130 ;; end before we find a beginning, get an error.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1131 (if (and (< prev 0) (< depth prev))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1132 (error (if forward
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1133 "No following conditional at this level"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1134 "No previous conditional at this level")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1135 ;; When searching forward, start from next line so
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1136 ;; that we don't find the same line again.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1137 (if forward (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1138 ;; If this line exits a level of conditional, exit
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1139 ;; inner loop.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1140 (if (< depth 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1141 (setq found (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1142 ;; else
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1143 (if forward (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1144 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1145 (or found
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1146 (error "No containing preprocessor conditional"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1147 (goto-char (setq new found)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1148 (setq count (+ count increment))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1149 (push-mark)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1150 (goto-char new))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1151 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1152
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1153
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1154 ;; commands to indent lines, regions, defuns, and expressions
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1155 (defun c-indent-command (&optional whole-exp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1156 "Indent current line as C code, and/or insert some whitespace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1157
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1158 If `c-tab-always-indent' is t, always just indent the current line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1159 If nil, indent the current line only if point is at the left margin or
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1160 in the line's indentation; otherwise insert some whitespace[*]. If
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1161 other than nil or t, then some whitespace[*] is inserted only within
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1162 literals (comments and strings) and inside preprocessor directives,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1163 but the line is always reindented.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1164
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1165 A numeric argument, regardless of its value, means indent rigidly all
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1166 the lines of the expression starting after point so that this line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1167 becomes properly indented. The relative indentation among the lines
24529
2986e6d0e927 (c-indent-command): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents: 24447
diff changeset
1168 of the expression is preserved.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1169
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1170 [*] The amount and kind of whitespace inserted is controlled by the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171 variable `c-insert-tab-function', which is called to do the actual
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1172 insertion of whitespace. Normally the function in this variable
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1173 just inserts a tab character, or the equivalent number of spaces,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1174 depending on the variable `indent-tabs-mode'."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1175
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1176 (interactive "P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1177 (let ((bod (c-point 'bod)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1178 (if whole-exp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1179 ;; If arg, always indent this line as C
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1180 ;; and shift remaining lines of expression the same amount.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 (let ((shift-amt (c-indent-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1182 beg end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1183 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1184 (if (eq c-tab-always-indent t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1185 (beginning-of-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1186 (setq beg (point))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1187 (c-forward-sexp 1)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1188 (setq end (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1189 (goto-char beg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1190 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1191 (setq beg (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1192 (if (> end beg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1193 (indent-code-rigidly beg end (- shift-amt) "#")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1194 ;; No arg supplied, use c-tab-always-indent to determine
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1195 ;; behavior
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1196 (cond
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1197 ;; CASE 1: indent when at column zero or in lines indentation,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1198 ;; otherwise insert a tab
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1199 ((not c-tab-always-indent)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1200 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1201 (skip-chars-backward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1202 (not (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1203 (funcall c-insert-tab-function)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1204 (c-indent-line)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1205 ;; CASE 2: just indent the line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1206 ((eq c-tab-always-indent t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1207 (c-indent-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1208 ;; CASE 3: if in a literal, insert a tab, but always indent the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1209 ;; line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1210 (t
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1211 (if (c-in-literal bod)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1212 (funcall c-insert-tab-function))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1213 (c-indent-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1214 )))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1215
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1216 (defun c-indent-exp (&optional shutup-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1217 "Indent each line in balanced expression following point.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1218 Optional SHUTUP-P if non-nil, inhibits message printing and error checking."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1219 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1220 (let ((here (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1221 end progress-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1222 (unwind-protect
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1223 (let ((c-echo-syntactic-information-p nil) ;keep quiet for speed
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 (start (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 ;; try to be smarter about finding the range of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 ;; lines to indent. skip all following
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1227 ;; whitespace. failing that, try to find any
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1228 ;; opening brace on the current line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1229 (skip-chars-forward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1230 (if (memq (char-after) '(?\( ?\[ ?\{))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1231 (point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1232 (let ((state (parse-partial-sexp (point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1233 (c-point 'eol))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1234 (and (nth 1 state)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1235 (goto-char (nth 1 state))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1236 (memq (char-after) '(?\( ?\[ ?\{))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1237 (point)))))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1238 ;; find balanced expression end
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1239 (setq end (and (c-safe (progn (c-forward-sexp 1) t))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1240 (point-marker)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1241 ;; sanity check
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1242 (and (not start)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1243 (not shutup-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1244 (error "Cannot find start of balanced expression to indent."))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1245 (and (not end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1246 (not shutup-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1247 (error "Cannot find end of balanced expression to indent."))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1248 (c-progress-init start end 'c-indent-exp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1249 (setq progress-p t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1250 (goto-char start)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1251 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1252 (while (< (point) end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1253 (if (not (looking-at "[ \t]*$"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1254 (c-indent-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1255 (c-progress-update)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1256 (forward-line 1)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1257 ;; make sure marker is deleted
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1258 (and end
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1259 (set-marker end nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1260 (and progress-p
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1261 (c-progress-fini 'c-indent-exp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1262 (goto-char here))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1263
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1264 (defun c-indent-defun ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1265 "Re-indents the current top-level function def, struct or class declaration."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1266 (interactive "*")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1267 (let ((here (point-marker))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1268 (c-echo-syntactic-information-p nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1269 (brace (c-least-enclosing-brace (c-parse-state))))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1270 (goto-char (or brace (c-point 'bod)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1271 ;; if we're sitting at b-o-b, it might be because there was no
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1272 ;; least enclosing brace and we were sitting on the defun's open
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1273 ;; brace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1274 (if (and (bobp) (not (eq (char-after) ?\{)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1275 (goto-char here))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1276 ;; if defun-prompt-regexp is non-nil, b-o-d might not leave us at
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1277 ;; the open brace. I consider this an Emacs bug.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1278 (and (boundp 'defun-prompt-regexp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1279 defun-prompt-regexp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1280 (looking-at defun-prompt-regexp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1281 (goto-char (match-end 0)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1282 ;; catch all errors in c-indent-exp so we can 1. give more
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1283 ;; meaningful error message, and 2. restore point
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1284 (unwind-protect
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1285 (c-indent-exp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1286 (goto-char here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1287 (set-marker here nil))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1288
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1289 (defun c-indent-region (start end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1290 ;; Indent every line whose first char is between START and END inclusive.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1291 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1292 (goto-char start)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1293 ;; Advance to first nonblank line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1294 (skip-chars-forward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1295 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1296 (let (endmark)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1297 (unwind-protect
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1298 (let ((c-tab-always-indent t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1299 ;; shut up any echo msgs on indiv lines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1300 (c-echo-syntactic-information-p nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1301 fence)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1302 (c-progress-init start end 'c-indent-region)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1303 (setq endmark (copy-marker end))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1304 (while (and (bolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1305 (not (eobp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1306 (< (point) endmark))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1307 ;; update progress
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1308 (c-progress-update)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1309 ;; Indent one line as with TAB.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1310 (let (nextline sexpend sexpbeg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1311 ;; skip blank lines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1312 (skip-chars-forward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1313 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1314 ;; indent the current line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1315 (c-indent-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1316 (setq fence (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1317 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1318 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1319 (looking-at "[ \t]*#"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1320 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1321 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1322 ;; Find beginning of following line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1323 (setq nextline (c-point 'bonl))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1324 ;; Find first beginning-of-sexp for sexp extending past
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1325 ;; this line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1326 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1327 (while (< (point) nextline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1328 (condition-case nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1329 (progn
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1330 (c-forward-sexp 1)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1331 (setq sexpend (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1332 (error (setq sexpend nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1333 (goto-char nextline)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1334 (c-forward-syntactic-ws))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1335 (if sexpend
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1336 (progn
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1337 ;; make sure the sexp we found really starts on the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1338 ;; current line and extends past it
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1339 (goto-char sexpend)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1340 (setq sexpend (point-marker))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1341 (c-safe (c-backward-sexp 1))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342 (setq sexpbeg (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1343 (if (and sexpbeg (< sexpbeg fence))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1344 (setq sexpbeg fence)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1345 ;; check to see if the next line starts a
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1346 ;; comment-only line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1347 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1348 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1349 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1350 (if (looking-at c-comment-start-regexp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1351 (setq sexpbeg (c-point 'bol))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1352 ;; If that sexp ends within the region, indent it all at
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1353 ;; once, fast.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1354 (condition-case nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1355 (if (and sexpend
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1356 (> sexpend nextline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1357 (<= sexpend endmark))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1358 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1359 (goto-char sexpbeg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1360 (c-indent-exp 'shutup)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1361 (c-progress-update)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1362 (goto-char sexpend)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1363 (error
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1364 (goto-char sexpbeg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1365 (c-indent-line)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1366 ;; Move to following line and try again.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1367 (and sexpend
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1368 (markerp sexpend)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1369 (set-marker sexpend nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1370 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1371 (setq fence (point))))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1372 (set-marker endmark nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1373 (c-progress-fini 'c-indent-region)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1374 (c-echo-parsing-error)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1375 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1376
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1377 (defun c-mark-function ()
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1378 "Put mark at end of current top-level defun, point at beginning."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1379 (interactive)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1380 (let ((here (point))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1381 (eod (c-point 'eod))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1382 (state (c-parse-state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1383 ;; Are we sitting at the top level, someplace between either the
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1384 ;; beginning of buffer, or the nearest preceding defun? If so,
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1385 ;; try first to figure out whether we're sitting on the
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1386 ;; introduction to a top-level defun, in which case we want to
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1387 ;; mark the entire defun we're sitting on.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1388 ;;
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1389 ;; If we're sitting on anything else at the top-level, we want to
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1390 ;; just mark the statement that we're on
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1391 (if (or (and (consp (car state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1392 (= (length state) 1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1393 (null state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1394 ;; Are we in the whitespace after the nearest preceding defun?
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1395 (if (and state
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1396 (looking-at "[ \t]*$")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1397 (= (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1398 (c-backward-syntactic-ws)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1399 (skip-chars-backward ";")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1400 (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1401 (cdar state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1402 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1403 (setq eod (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1404 (goto-char (caar state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1405 (c-beginning-of-statement-1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1406 (if (= ?{ (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1407 (c-end-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1408 (char-before)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1409 ;; We must be in a defuns's introduction
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1410 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1411 (c-end-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1412 (skip-chars-backward "{")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1413 (c-beginning-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1414 (c-forward-syntactic-ws))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1415 ;; Just mark the statement
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1416 (c-end-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1417 (forward-line 1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1418 (setq eod (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1419 (c-beginning-of-statement-1)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1420 ;; We are inside some enclosing brace structure, so we first
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1421 ;; need to find our way to the least enclosing brace. Then, in
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1422 ;; both cases, we to mark the region from the beginning of the
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1423 ;; current statement, until the end of the next following defun
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1424 (while (and state)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1425 (or (consp (car state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1426 (goto-char (car state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1427 (setq state (cdr state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1428 (c-beginning-of-statement-1))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1429 (push-mark here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1430 (push-mark eod nil t)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1431
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1432 (defun c-indent-line-or-region ()
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1433 "When the region is active, indent it. Otherwise indent the current line."
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1434 ;; Emacs has a variable called mark-active, XEmacs uses region-active-p
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1435 (interactive)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1436 (if (c-region-is-active-p)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1437 (c-indent-region (region-beginning) (region-end))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1438 (c-indent-command)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1439
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1440
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1441 ;; for progress reporting
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1442 (defvar c-progress-info nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1443
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1444 (defun c-progress-init (start end context)
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1445 (cond
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1446 ;; Be silent
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1447 ((not c-progress-interval))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1448 ;; Start the progress update messages. If this Emacs doesn't have
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1449 ;; a built-in timer, just be dumb about it.
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1450 ((not (fboundp 'current-time))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1451 (message "indenting region... (this may take a while)"))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1452 ;; If progress has already been initialized, do nothing. otherwise
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1453 ;; initialize the counter with a vector of:
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1454 ;; [start end lastsec context]
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1455 (c-progress-info)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1456 (t (setq c-progress-info (vector start
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1457 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1458 (goto-char end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1459 (point-marker))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1460 (nth 1 (current-time))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1461 context))
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1462 (message "indenting region..."))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1463 ))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1464
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1465 (defun c-progress-update ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1466 ;; update progress
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1467 (if (not (and c-progress-info c-progress-interval))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1468 nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1469 (let ((now (nth 1 (current-time)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1470 (start (aref c-progress-info 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1471 (end (aref c-progress-info 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1472 (lastsecs (aref c-progress-info 2)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1473 ;; should we update? currently, update happens every 2 seconds,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1474 ;; what's the right value?
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1475 (if (< c-progress-interval (- now lastsecs))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1476 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1477 (message "indenting region... (%d%% complete)"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1478 (/ (* 100 (- (point) start)) (- end start)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1479 (aset c-progress-info 2 now)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1480 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1481
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1482 (defun c-progress-fini (context)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1483 ;; finished
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1484 (if (not c-progress-interval)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1485 nil
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1486 (if (or (eq context (aref c-progress-info 3))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1487 (eq context t))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1488 (progn
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1489 (set-marker (aref c-progress-info 1) nil)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1490 (setq c-progress-info nil)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1491 (message "indenting region...done")))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1492
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1493
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1494
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1495 ;;; This page handles insertion and removal of backslashes for C macros.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1496
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1497 (defun c-backslash-region (from to delete-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1498 "Insert, align, or delete end-of-line backslashes on the lines in the region.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1499 With no argument, inserts backslashes and aligns existing backslashes.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1500 With an argument, deletes the backslashes.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1501
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1502 This function does not modify blank lines at the start of the region.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1503 If the region ends at the start of a line, it always deletes the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1504 backslash (if any) at the end of the previous line.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1505
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1506 You can put the region around an entire macro definition and use this
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1507 command to conveniently insert and align the necessary backslashes."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1508 (interactive "*r\nP")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1509 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1510 (goto-char from)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1511 (let ((column c-backslash-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1512 (endmark (make-marker)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1513 (move-marker endmark to)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1514 ;; Compute the smallest column number past the ends of all the lines.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1515 (if (not delete-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1516 (while (< (point) to)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1517 (end-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1518 (if (eq (char-before) ?\\)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1519 (progn (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1520 (skip-chars-backward " \t")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1521 (setq column (max column (1+ (current-column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1522 (forward-line 1)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1523 ;; Adjust upward to a tab column, if that doesn't push past the margin.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1524 (if (> (% column tab-width) 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1525 (let ((adjusted (* (/ (+ column tab-width -1) tab-width) tab-width)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1526 (if (< adjusted (window-width))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1527 (setq column adjusted))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1528 ;; Don't modify blank lines at start of region.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1529 (goto-char from)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1530 (while (and (< (point) endmark) (eolp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1531 (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1532 ;; Add or remove backslashes on all the lines.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1533 (while (< (point) endmark)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1534 (if (and (not delete-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1535 ;; Un-backslashify the last line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1536 ;; if the region ends right at the start of the next line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1537 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1538 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1539 (< (point) endmark)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1540 (c-append-backslash column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1541 (c-delete-backslash))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1542 (forward-line 1))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1543 (move-marker endmark nil))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1544
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1545 (defun c-append-backslash (column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1546 (end-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1547 (if (eq (char-before) ?\\)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1548 (progn (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1549 (delete-horizontal-space)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1550 (indent-to column))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1551 (indent-to column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1552 (insert "\\")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1553
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1554 (defun c-delete-backslash ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1555 (end-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1556 (or (bolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1557 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1558 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1559 (if (looking-at "\\\\")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1560 (delete-region (1+ (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1561 (progn (skip-chars-backward " \t") (point)))))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1562
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1563
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1564 (defun c-fill-paragraph (&optional arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1565 "Like \\[fill-paragraph] but handles C and C++ style comments.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1566 If any of the current line is a comment or within a comment,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1567 fill the comment or the paragraph of it that point is in,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1568 preserving the comment indentation or line-starting decorations.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1569
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1570 If point is inside multiline string literal, fill it. This currently
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1571 does not respect escaped newlines, except for the special case when it
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1572 is the very first thing in the string. The intended use for this rule
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1573 is in situations like the following:
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1574
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1575 char description[] = \"\\
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1576 A very long description of something that you want to fill to make
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1577 nicely formatted output.\"\;
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1578
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1579 If point is in any other situation, i.e. in normal code, do nothing.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1580
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1581 Optional prefix ARG means justify paragraph as well."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1582 (interactive "*P")
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1583 (let* ((point-save (point-marker))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1584 limits
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1585 comment-start-place
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1586 (first-line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1587 ;; Check for obvious entry to comment.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1588 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1589 (beginning-of-line)
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1590 (skip-chars-forward " \t")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1591 (and (looking-at comment-start-skip)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1592 (setq comment-start-place (point)))))
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1593 (re1 "\\|\\([ \t]*/\\*[ \t]*\\|[ \t]*\\*/[ \t]*\\|[ \t/*]*\\)"))
19378
a1987ab30543 (c-comment-line-break-function): In this function, and the defadvice,
Richard M. Stallman <rms@gnu.org>
parents: 19306
diff changeset
1594 (if (save-excursion
a1987ab30543 (c-comment-line-break-function): In this function, and the defadvice,
Richard M. Stallman <rms@gnu.org>
parents: 19306
diff changeset
1595 (beginning-of-line)
a1987ab30543 (c-comment-line-break-function): In this function, and the defadvice,
Richard M. Stallman <rms@gnu.org>
parents: 19306
diff changeset
1596 (looking-at ".*//"))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1597 (let ((fill-prefix fill-prefix)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1598 ;; Lines containing just a comment start or just an end
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1599 ;; should not be filled into paragraphs they are next
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1600 ;; to.
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1601 (paragraph-start (concat paragraph-start re1 "$"))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1602 (paragraph-separate (concat paragraph-separate re1 "$")))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1603 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1604 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1605 ;; Move up to first line of this comment.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1606 (while (and (not (bobp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1607 (looking-at "[ \t]*//[ \t]*[^ \t\n]"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1608 (forward-line -1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1609 (if (not (looking-at ".*//[ \t]*[^ \t\n]"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1610 (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1611 ;; Find the comment start in this line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1612 (re-search-forward "[ \t]*//[ \t]*")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1613 ;; Set the fill-prefix to be what all lines except the first
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1614 ;; should start with. But do not alter a user set fill-prefix.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1615 (if (null fill-prefix)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1616 (setq fill-prefix (buffer-substring (match-beginning 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1617 (match-end 0))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1618 (save-restriction
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1619 ;; Narrow down to just the lines of this comment.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1620 (narrow-to-region (c-point 'bol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1621 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1622 (forward-line 1)
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1623 (while
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1624 (looking-at (regexp-quote fill-prefix))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1625 (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1626 (point)))
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1627 (or (c-safe
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1628 ;; fill-paragraph sometimes fails to detect when we
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1629 ;; are between paragraphs.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1630 (beginning-of-line)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1631 (search-forward fill-prefix (c-point 'eol))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1632 (looking-at paragraph-separate))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1633 ;; Avoids recursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1634 (let (fill-paragraph-function)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1635 (fill-paragraph arg))))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1636 ;; else C style comments
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1637 (if (or first-line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1638 ;; t if we enter a comment between start of function and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1639 ;; this line.
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1640 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1641 (setq limits (c-literal-limits))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1642 (and (consp limits)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1643 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1644 (goto-char (car limits))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1645 (looking-at c-comment-start-regexp))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1646 ;; t if this line contains a comment starter.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1647 (setq first-line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1648 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1649 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1650 (prog1
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1651 (re-search-forward comment-start-skip
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1652 (save-excursion (end-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1653 (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1654 t)
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1655 (setq comment-start-place (point)))))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1656 ;; t if we're in the whitespace after a comment ender
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1657 ;; which ends its line.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1658 (and (not limits)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1659 (when (and (looking-at "[ \t]*$")
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1660 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1661 (beginning-of-line)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1662 (looking-at ".*\\*/[ \t]*$")))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1663 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1664 (forward-comment -1)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1665 (setq comment-start-place (point)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1666 t)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1667 ;; Inside a comment: fill one comment paragraph.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1668 (let ((fill-prefix
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1669 (or
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1670 ;; Keep user set fill prefix if any.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1671 fill-prefix
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1672 ;; The prefix for each line of this paragraph
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1673 ;; is the appropriate part of the start of this line,
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1674 ;; up to the column at which text should be indented.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1675 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1676 (beginning-of-line)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1677 (if (looking-at ".*/\\*.*\\*/")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1678 (progn (re-search-forward comment-start-skip)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1679 (make-string (current-column) ?\ ))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1680 (if first-line
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1681 (forward-line 1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1682 (if (and (looking-at "[ \t]*\\*/")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1683 (not (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1684 (forward-line -1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1685 (looking-at ".*/\\*"))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1686 (forward-line -1)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1687
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1688 (let ((line-width (progn (end-of-line)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1689 (current-column))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1690 (beginning-of-line)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1691 (prog1
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1692 (buffer-substring
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1693 (point)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1694
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1695 ;; How shall we decide where the end of the
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1696 ;; fill-prefix is?
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1697 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1698 (skip-chars-forward " \t*" (c-point 'eol))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1699 ;; kludge alert, watch out for */, in
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1700 ;; which case fill-prefix should *not*
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1701 ;; be "*"!
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1702 (if (and (eq (char-after) ?/)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1703 (eq (char-before) ?*))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1704 (forward-char -1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1705 (point)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1706
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1707 ;; If the comment is only one line followed
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1708 ;; by a blank line, calling move-to-column
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1709 ;; above may have added some spaces and tabs
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1710 ;; to the end of the line; the fill-paragraph
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1711 ;; function will then delete it and the
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1712 ;; newline following it, so we'll lose a
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1713 ;; blank line when we shouldn't. So delete
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1714 ;; anything move-to-column added to the end
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1715 ;; of the line. We record the line width
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1716 ;; instead of the position of the old line
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1717 ;; end because move-to-column might break a
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1718 ;; tab into spaces, and the new characters
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1719 ;; introduced there shouldn't be deleted.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1720
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1721 ;; If you can see a better way to do this,
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1722 ;; please make the change. This seems very
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1723 ;; messy to me.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1724 (delete-region (progn (move-to-column line-width)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1725 (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1726 (progn (end-of-line) (point)))))))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1727
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1728 ;; Lines containing just a comment start or just an end
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1729 ;; should not be filled into paragraphs they are next
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1730 ;; to.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1731 (paragraph-start (if (c-major-mode-is 'java-mode)
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1732 (concat paragraph-start
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1733 re1 "\\("
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1734 c-Java-javadoc-paragraph-start
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1735 "\\|$\\)")
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1736 (concat paragraph-start re1 "$")))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1737 (paragraph-separate (concat paragraph-separate re1 "$"))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1738 (chars-to-delete 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1739 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1740 (save-restriction
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1741 ;; Don't fill the comment together with the code
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1742 ;; following it. So temporarily exclude everything
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1743 ;; before the comment start, and everything after the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1744 ;; line where the comment ends. If comment-start-place
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1745 ;; is non-nil, the comment starter is there. Otherwise,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1746 ;; point is inside the comment.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1747 (narrow-to-region (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1748 (if comment-start-place
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1749 (goto-char comment-start-place)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1750 (search-backward "/*"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1751 (if (and (not c-hanging-comment-starter-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1752 (looking-at
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1753 (concat c-comment-start-regexp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1754 "[ \t]*$")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1755 (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1756 ;; Protect text before the comment
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1757 ;; start by excluding it. Add
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1758 ;; spaces to bring back proper
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1759 ;; indentation of that point.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1760 (let ((column (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1761 (prog1 (point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1762 (setq chars-to-delete column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1763 (insert-char ?\ column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1764 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1765 (if comment-start-place
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1766 (goto-char (+ comment-start-place 2)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1767 (search-forward "*/" nil 'move)
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1768 (if (and (not c-hanging-comment-ender-p)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1769 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1770 (beginning-of-line)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1771 (looking-at "[ \t]*\\*/")))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1772 (beginning-of-line)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1773 (forward-line 1))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1774 (point)))
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1775 (or (c-safe
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1776 ;; fill-paragraph sometimes fails to detect when we
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1777 ;; are between paragraphs.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1778 (beginning-of-line)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1779 (search-forward fill-prefix (c-point 'eol))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1780 (looking-at paragraph-separate))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1781 ;; Avoids recursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1782 (let (fill-paragraph-function)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1783 (fill-paragraph arg)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1784 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1785 ;; Delete the chars we inserted to avoid clobbering
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1786 ;; the stuff before the comment start.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1787 (goto-char (point-min))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1788 (if (> chars-to-delete 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1789 (delete-region (point) (+ (point) chars-to-delete)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1790 ;; Find the comment ender (should be on last line of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1791 ;; buffer, given the narrowing) and don't leave it on
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1792 ;; its own line, unless that's the style that's desired.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1793 (goto-char (point-max))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1794 (forward-line -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1795 (search-forward "*/" nil 'move)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1796 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1797 (if (and c-hanging-comment-ender-p
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1798 (looking-at "[ \t]*\\*/"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1799 ;(delete-indentation)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1800 (let ((fill-column (+ fill-column 9999)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1801 (forward-line -1)
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1802 (fill-region-as-paragraph (point) (point-max))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1803 ;; If fill-prefix ended with a `*', it may be
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1804 ;; taken away from the comment ender. We got to
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1805 ;; check this and put it back if that is the
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1806 ;; case.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1807 (goto-char (- (point-max) 2))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1808 (if (not (= (char-before) ?*))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1809 (insert ?*))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1810 )))))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1811 ;; Else maybe a string. Fill it if it's a multiline string.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1812 ;; FIXME: This currently doesn't handle escaped newlines.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1813 ;; Doing that correctly is a bit tricky.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1814 (if (and limits
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1815 (eq (char-syntax (char-after (car limits))) ?\")
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1816 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1817 (goto-char (car limits))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1818 (end-of-line)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1819 (< (point) (cdr limits))))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1820 (let (fill-paragraph-function)
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1821 (save-restriction
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1822 (narrow-to-region (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1823 (goto-char (1+ (car limits)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1824 (if (looking-at "\\\\$")
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1825 ;; Some DWIM: Leave the start
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1826 ;; line if it's nothing but an
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1827 ;; escaped newline.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1828 (1+ (match-end 0))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1829 (point)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1830 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1831 (goto-char (1- (cdr limits)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1832 ;; Inserting a newline and
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1833 ;; removing it again after
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1834 ;; fill-paragraph makes it more
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1835 ;; predictable.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1836 (insert ?\n)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1837 (point)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1838 ;; Do not compensate for the narrowed column. This
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1839 ;; way the literal will always be filled at the same
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1840 ;; column internally.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1841 (fill-paragraph arg)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1842 (goto-char (1- (point-max)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1843 (delete-char 1)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1844 )))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1845 (goto-char (marker-position point-save))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1846 (set-marker point-save nil)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1847 ;; Always return t. This has the effect that if filling isn't
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1848 ;; done above, it isn't done at all, and it's therefore
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1849 ;; effectively disabled in normal code.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1850 t))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1851
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1852
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1853 (provide 'cc-cmds)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1854 ;;; cc-cmds.el ends here