annotate lisp/progmodes/cc-cmds.el @ 24282:5b0864259a4b Release_5_25

Installed CC Mode 5.25.
author Barry A. Warsaw <barry@zope.org>
date Mon, 08 Feb 1999 16:53:18 +0000
parents d67e858e738b
children 8309f6535486
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 ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1068 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1069 (skip-chars-forward "\t ")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1070 (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1071
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1072
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1073 (defun c-up-conditional (count)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1074 "Move back to the containing preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1075 A prefix argument acts as a repeat count. With a negative argument,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1076 move forward to the end of the containing preprocessor conditional.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1077 When going backwards, `#elif' is treated like `#else' followed by
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1078 `#if'. When going forwards, `#elif' is ignored."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1079 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1080 (c-forward-conditional (- count) t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1081 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1082
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1083 (defun c-backward-conditional (count &optional up-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1084 "Move back across a preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1085 A prefix argument acts as a repeat count. With a negative argument,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1086 move forward across a preprocessor conditional."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1087 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1088 (c-forward-conditional (- count) up-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1089 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1090
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1091 (defun c-forward-conditional (count &optional up-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1092 "Move forward across a preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1093 A prefix argument acts as a repeat count. With a negative argument,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1094 move backward across a preprocessor conditional."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1095 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1096 (let* ((forward (> count 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1097 (increment (if forward -1 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1098 (search-function (if forward 're-search-forward 're-search-backward))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1099 (new))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1100 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1101 (while (/= count 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1102 (let ((depth (if up-flag 0 -1)) found)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1103 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1104 ;; Find the "next" significant line in the proper direction.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1105 (while (and (not found)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1106 ;; Rather than searching for a # sign that
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1107 ;; comes at the beginning of a line aside from
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1108 ;; whitespace, search first for a string
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1109 ;; starting with # sign. Then verify what
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1110 ;; precedes it. This is faster on account of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1111 ;; the fastmap feature of the regexp matcher.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1112 (funcall search-function
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1113 "#[ \t]*\\(if\\|elif\\|endif\\)"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1114 nil t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1115 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1116 ;; Now verify it is really a preproc line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1117 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\)")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1118 (let ((prev depth))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1119 ;; Update depth according to what we found.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1120 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1121 (cond ((looking-at "[ \t]*#[ \t]*endif")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1122 (setq depth (+ depth increment)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1123 ((looking-at "[ \t]*#[ \t]*elif")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1124 (if (and forward (= depth 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1125 (setq found (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1126 (t (setq depth (- depth increment))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1127 ;; If we are trying to move across, and we find an
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1128 ;; end before we find a beginning, get an error.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1129 (if (and (< prev 0) (< depth prev))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1130 (error (if forward
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1131 "No following conditional at this level"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1132 "No previous conditional at this level")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1133 ;; When searching forward, start from next line so
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1134 ;; that we don't find the same line again.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1135 (if forward (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1136 ;; If this line exits a level of conditional, exit
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1137 ;; inner loop.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1138 (if (< depth 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1139 (setq found (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1140 ;; else
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1141 (if forward (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1142 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1143 (or found
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1144 (error "No containing preprocessor conditional"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1145 (goto-char (setq new found)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1146 (setq count (+ count increment))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1147 (push-mark)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1148 (goto-char new))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1149 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1150
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1151
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1152 ;; commands to indent lines, regions, defuns, and expressions
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1153 (defun c-indent-command (&optional whole-exp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1154 "Indent current line as C code, and/or insert some whitespace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1155
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1156 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
1157 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
1158 in the line's indentation; otherwise insert some whitespace[*]. If
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1159 other than nil or t, then some whitespace[*] is inserted only within
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1160 literals (comments and strings) and inside preprocessor directives,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1161 but the line is always reindented.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1162
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1163 A numeric argument, regardless of its value, means indent rigidly all
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1164 the lines of the expression starting after point so that this line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1165 becomes properly indented. The relative indentation among the lines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1166 of the expression are preserved.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1167
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1168 [*] The amount and kind of whitespace inserted is controlled by the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1169 variable `c-insert-tab-function', which is called to do the actual
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1170 insertion of whitespace. Normally the function in this variable
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171 just inserts a tab character, or the equivalent number of spaces,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1172 depending on the variable `indent-tabs-mode'."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1173
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1174 (interactive "P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1175 (let ((bod (c-point 'bod)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1176 (if whole-exp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1177 ;; If arg, always indent this line as C
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1178 ;; and shift remaining lines of expression the same amount.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1179 (let ((shift-amt (c-indent-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1180 beg end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1182 (if (eq c-tab-always-indent t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1183 (beginning-of-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1184 (setq beg (point))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1185 (c-forward-sexp 1)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1186 (setq end (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1187 (goto-char beg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1188 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1189 (setq beg (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1190 (if (> end beg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1191 (indent-code-rigidly beg end (- shift-amt) "#")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1192 ;; No arg supplied, use c-tab-always-indent to determine
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1193 ;; behavior
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1194 (cond
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1195 ;; CASE 1: indent when at column zero or in lines indentation,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1196 ;; otherwise insert a tab
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1197 ((not c-tab-always-indent)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1198 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1199 (skip-chars-backward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1200 (not (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1201 (funcall c-insert-tab-function)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1202 (c-indent-line)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1203 ;; CASE 2: just indent the line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1204 ((eq c-tab-always-indent t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1205 (c-indent-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1206 ;; 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
1207 ;; line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1208 (t
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1209 (if (c-in-literal bod)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1210 (funcall c-insert-tab-function))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1211 (c-indent-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1212 )))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1213
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1214 (defun c-indent-exp (&optional shutup-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1215 "Indent each line in balanced expression following point.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1216 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
1217 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1218 (let ((here (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1219 end progress-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1220 (unwind-protect
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1221 (let ((c-echo-syntactic-information-p nil) ;keep quiet for speed
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1222 (start (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1223 ;; try to be smarter about finding the range of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1224 ;; lines to indent. skip all following
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 ;; whitespace. failing that, try to find any
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 ;; opening brace on the current line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1227 (skip-chars-forward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1228 (if (memq (char-after) '(?\( ?\[ ?\{))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1229 (point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1230 (let ((state (parse-partial-sexp (point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1231 (c-point 'eol))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1232 (and (nth 1 state)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1233 (goto-char (nth 1 state))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1234 (memq (char-after) '(?\( ?\[ ?\{))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1235 (point)))))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1236 ;; find balanced expression end
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1237 (setq end (and (c-safe (progn (c-forward-sexp 1) t))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1238 (point-marker)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1239 ;; sanity check
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1240 (and (not start)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1241 (not shutup-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1242 (error "Cannot find start of balanced expression to indent."))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1243 (and (not end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1244 (not shutup-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1245 (error "Cannot find end of balanced expression to indent."))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1246 (c-progress-init start end 'c-indent-exp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1247 (setq progress-p t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1248 (goto-char start)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1249 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1250 (while (< (point) end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1251 (if (not (looking-at "[ \t]*$"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1252 (c-indent-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1253 (c-progress-update)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1254 (forward-line 1)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1255 ;; make sure marker is deleted
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1256 (and end
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1257 (set-marker end nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1258 (and progress-p
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1259 (c-progress-fini 'c-indent-exp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1260 (goto-char here))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1261
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1262 (defun c-indent-defun ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1263 "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
1264 (interactive "*")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1265 (let ((here (point-marker))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1266 (c-echo-syntactic-information-p nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1267 (brace (c-least-enclosing-brace (c-parse-state))))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1268 (goto-char (or brace (c-point 'bod)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1269 ;; 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
1270 ;; least enclosing brace and we were sitting on the defun's open
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1271 ;; brace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1272 (if (and (bobp) (not (eq (char-after) ?\{)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1273 (goto-char here))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1274 ;; 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
1275 ;; the open brace. I consider this an Emacs bug.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1276 (and (boundp 'defun-prompt-regexp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1277 defun-prompt-regexp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1278 (looking-at defun-prompt-regexp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1279 (goto-char (match-end 0)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1280 ;; 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
1281 ;; meaningful error message, and 2. restore point
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1282 (unwind-protect
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1283 (c-indent-exp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1284 (goto-char here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1285 (set-marker here nil))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1286
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1287 (defun c-indent-region (start end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1288 ;; Indent every line whose first char is between START and END inclusive.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1289 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1290 (goto-char start)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1291 ;; Advance to first nonblank line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1292 (skip-chars-forward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1293 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1294 (let (endmark)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1295 (unwind-protect
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1296 (let ((c-tab-always-indent t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1297 ;; shut up any echo msgs on indiv lines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1298 (c-echo-syntactic-information-p nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1299 fence)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1300 (c-progress-init start end 'c-indent-region)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1301 (setq endmark (copy-marker end))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1302 (while (and (bolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1303 (not (eobp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1304 (< (point) endmark))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1305 ;; update progress
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1306 (c-progress-update)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1307 ;; Indent one line as with TAB.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1308 (let (nextline sexpend sexpbeg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1309 ;; skip blank lines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1310 (skip-chars-forward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1311 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1312 ;; indent the current line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1313 (c-indent-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1314 (setq fence (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1315 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1316 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1317 (looking-at "[ \t]*#"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1318 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1319 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1320 ;; Find beginning of following line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1321 (setq nextline (c-point 'bonl))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1322 ;; Find first beginning-of-sexp for sexp extending past
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1323 ;; this line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1324 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1325 (while (< (point) nextline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1326 (condition-case nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1327 (progn
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1328 (c-forward-sexp 1)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1329 (setq sexpend (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1330 (error (setq sexpend nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1331 (goto-char nextline)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1332 (c-forward-syntactic-ws))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1333 (if sexpend
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1334 (progn
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1335 ;; make sure the sexp we found really starts on the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1336 ;; current line and extends past it
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1337 (goto-char sexpend)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1338 (setq sexpend (point-marker))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1339 (c-safe (c-backward-sexp 1))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1340 (setq sexpbeg (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1341 (if (and sexpbeg (< sexpbeg fence))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342 (setq sexpbeg fence)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1343 ;; check to see if the next line starts a
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1344 ;; comment-only line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1345 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1346 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1347 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1348 (if (looking-at c-comment-start-regexp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1349 (setq sexpbeg (c-point 'bol))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1350 ;; If that sexp ends within the region, indent it all at
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1351 ;; once, fast.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1352 (condition-case nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1353 (if (and sexpend
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1354 (> sexpend nextline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1355 (<= sexpend endmark))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1356 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1357 (goto-char sexpbeg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1358 (c-indent-exp 'shutup)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1359 (c-progress-update)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1360 (goto-char sexpend)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1361 (error
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1362 (goto-char sexpbeg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1363 (c-indent-line)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1364 ;; Move to following line and try again.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1365 (and sexpend
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1366 (markerp sexpend)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1367 (set-marker sexpend nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1368 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1369 (setq fence (point))))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1370 (set-marker endmark nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1371 (c-progress-fini 'c-indent-region)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1372 (c-echo-parsing-error)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1373 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1374
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1375 (defun c-mark-function ()
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1376 "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
1377 (interactive)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1378 (let ((here (point))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1379 (eod (c-point 'eod))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1380 (state (c-parse-state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1381 ;; 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
1382 ;; 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
1383 ;; 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
1384 ;; 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
1385 ;; mark the entire defun we're sitting on.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1386 ;;
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1387 ;; 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
1388 ;; just mark the statement that we're on
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1389 (if (or (and (consp (car state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1390 (= (length state) 1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1391 (null state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1392 ;; 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
1393 (if (and state
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1394 (looking-at "[ \t]*$")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1395 (= (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1396 (c-backward-syntactic-ws)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1397 (skip-chars-backward ";")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1398 (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1399 (cdar state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1400 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1401 (setq eod (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1402 (goto-char (caar state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1403 (c-beginning-of-statement-1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1404 (if (= ?{ (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1405 (c-end-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1406 (char-before)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1407 ;; We must be in a defuns's introduction
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1408 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1409 (c-end-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1410 (skip-chars-backward "{")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1411 (c-beginning-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1412 (c-forward-syntactic-ws))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1413 ;; Just mark the statement
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1414 (c-end-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1415 (forward-line 1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1416 (setq eod (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1417 (c-beginning-of-statement-1)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1418 ;; 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
1419 ;; 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
1420 ;; 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
1421 ;; 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
1422 (while (and state)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1423 (or (consp (car state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1424 (goto-char (car state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1425 (setq state (cdr state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1426 (c-beginning-of-statement-1))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1427 (push-mark here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1428 (push-mark eod nil t)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1429
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1430 (defun c-indent-line-or-region ()
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1431 "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
1432 ;; 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
1433 (interactive)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1434 (if (c-region-is-active-p)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1435 (c-indent-region (region-beginning) (region-end))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1436 (c-indent-command)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1437
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1438
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1439 ;; for progress reporting
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1440 (defvar c-progress-info nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1441
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1442 (defun c-progress-init (start end context)
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1443 (cond
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1444 ;; Be silent
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1445 ((not c-progress-interval))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1446 ;; 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
1447 ;; 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
1448 ((not (fboundp 'current-time))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1449 (message "indenting region... (this may take a while)"))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1450 ;; 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
1451 ;; initialize the counter with a vector of:
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1452 ;; [start end lastsec context]
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1453 (c-progress-info)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1454 (t (setq c-progress-info (vector start
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1455 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1456 (goto-char end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1457 (point-marker))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1458 (nth 1 (current-time))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1459 context))
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1460 (message "indenting region..."))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1461 ))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1462
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1463 (defun c-progress-update ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1464 ;; update progress
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1465 (if (not (and c-progress-info c-progress-interval))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1466 nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1467 (let ((now (nth 1 (current-time)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1468 (start (aref c-progress-info 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1469 (end (aref c-progress-info 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1470 (lastsecs (aref c-progress-info 2)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1471 ;; should we update? currently, update happens every 2 seconds,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1472 ;; what's the right value?
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1473 (if (< c-progress-interval (- now lastsecs))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1474 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1475 (message "indenting region... (%d%% complete)"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1476 (/ (* 100 (- (point) start)) (- end start)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1477 (aset c-progress-info 2 now)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1478 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1479
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1480 (defun c-progress-fini (context)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1481 ;; finished
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1482 (if (not c-progress-interval)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1483 nil
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1484 (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
1485 (eq context t))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1486 (progn
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1487 (set-marker (aref c-progress-info 1) nil)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1488 (setq c-progress-info nil)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1489 (message "indenting region...done")))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1490
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1491
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 ;;; This page handles insertion and removal of backslashes for C macros.
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 (defun c-backslash-region (from to delete-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1496 "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
1497 With no argument, inserts backslashes and aligns existing backslashes.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1498 With an argument, deletes the backslashes.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1499
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1500 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
1501 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
1502 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
1503
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1504 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
1505 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
1506 (interactive "*r\nP")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1507 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1508 (goto-char from)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1509 (let ((column c-backslash-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1510 (endmark (make-marker)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1511 (move-marker endmark to)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1512 ;; Compute the smallest column number past the ends of all the lines.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1513 (if (not delete-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1514 (while (< (point) to)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1515 (end-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1516 (if (eq (char-before) ?\\)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1517 (progn (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1518 (skip-chars-backward " \t")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1519 (setq column (max column (1+ (current-column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1520 (forward-line 1)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1521 ;; 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
1522 (if (> (% column tab-width) 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1523 (let ((adjusted (* (/ (+ column tab-width -1) tab-width) tab-width)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1524 (if (< adjusted (window-width))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1525 (setq column adjusted))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1526 ;; Don't modify blank lines at start of region.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1527 (goto-char from)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1528 (while (and (< (point) endmark) (eolp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1529 (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1530 ;; Add or remove backslashes on all the lines.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1531 (while (< (point) endmark)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1532 (if (and (not delete-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1533 ;; Un-backslashify the last line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1534 ;; if the region ends right at the start of the next line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1535 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1536 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1537 (< (point) endmark)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1538 (c-append-backslash column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1539 (c-delete-backslash))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1540 (forward-line 1))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1541 (move-marker endmark nil))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1542
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1543 (defun c-append-backslash (column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1544 (end-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1545 (if (eq (char-before) ?\\)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1546 (progn (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1547 (delete-horizontal-space)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1548 (indent-to column))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1549 (indent-to column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1550 (insert "\\")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1551
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1552 (defun c-delete-backslash ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1553 (end-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1554 (or (bolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1555 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1556 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1557 (if (looking-at "\\\\")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1558 (delete-region (1+ (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1559 (progn (skip-chars-backward " \t") (point)))))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1560
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1561
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1562 (defun c-fill-paragraph (&optional arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1563 "Like \\[fill-paragraph] but handles C and C++ style comments.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1564 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
1565 fill the comment or the paragraph of it that point is in,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1566 preserving the comment indentation or line-starting decorations.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1567
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1568 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
1569 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
1570 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
1571 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
1572
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1573 char description[] = \"\\
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1574 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
1575 nicely formatted output.\"\;
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1576
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1577 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
1578
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1579 Optional prefix ARG means justify paragraph as well."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1580 (interactive "*P")
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1581 (let* ((point-save (point-marker))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1582 limits
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1583 comment-start-place
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1584 (first-line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1585 ;; Check for obvious entry to comment.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1586 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1587 (beginning-of-line)
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1588 (skip-chars-forward " \t")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1589 (and (looking-at comment-start-skip)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1590 (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
1591 (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
1592 (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
1593 (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
1594 (looking-at ".*//"))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1595 (let ((fill-prefix fill-prefix)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1596 ;; Lines containing just a comment start or just an end
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1597 ;; should not be filled into paragraphs they are next
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1598 ;; to.
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1599 (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
1600 (paragraph-separate (concat paragraph-separate re1 "$")))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1601 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1602 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1603 ;; Move up to first line of this comment.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1604 (while (and (not (bobp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1605 (looking-at "[ \t]*//[ \t]*[^ \t\n]"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1606 (forward-line -1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1607 (if (not (looking-at ".*//[ \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 ;; Find the comment start in this line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1610 (re-search-forward "[ \t]*//[ \t]*")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1611 ;; Set the fill-prefix to be what all lines except the first
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1612 ;; should start with. But do not alter a user set fill-prefix.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1613 (if (null fill-prefix)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1614 (setq fill-prefix (buffer-substring (match-beginning 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1615 (match-end 0))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1616 (save-restriction
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1617 ;; Narrow down to just the lines of this comment.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1618 (narrow-to-region (c-point 'bol)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1619 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1620 (forward-line 1)
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1621 (while
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1622 (looking-at (regexp-quote fill-prefix))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1623 (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1624 (point)))
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1625 (or (c-safe
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1626 ;; 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
1627 ;; are between paragraphs.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1628 (beginning-of-line)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1629 (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
1630 (looking-at paragraph-separate))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1631 ;; Avoids recursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1632 (let (fill-paragraph-function)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1633 (fill-paragraph arg))))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1634 ;; else C style comments
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1635 (if (or first-line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1636 ;; t if we enter a comment between start of function and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1637 ;; this line.
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1638 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1639 (setq limits (c-literal-limits))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1640 (and (consp limits)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1641 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1642 (goto-char (car limits))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1643 (looking-at c-comment-start-regexp))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1644 ;; t if this line contains a comment starter.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1645 (setq first-line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1646 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1647 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1648 (prog1
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1649 (re-search-forward comment-start-skip
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1650 (save-excursion (end-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1651 (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1652 t)
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1653 (setq comment-start-place (point)))))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1654 ;; 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
1655 ;; which ends its line.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1656 (and (not limits)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1657 (when (and (looking-at "[ \t]*$")
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1658 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1659 (beginning-of-line)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1660 (looking-at ".*\\*/[ \t]*$")))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1661 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1662 (forward-comment -1)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1663 (setq comment-start-place (point)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1664 t)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1665 ;; Inside a comment: fill one comment paragraph.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1666 (let ((fill-prefix
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1667 (or
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1668 ;; Keep user set fill prefix if any.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1669 fill-prefix
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1670 ;; The prefix for each line of this paragraph
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1671 ;; 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
1672 ;; 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
1673 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1674 (beginning-of-line)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1675 (if (looking-at ".*/\\*.*\\*/")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1676 (progn (re-search-forward comment-start-skip)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1677 (make-string (current-column) ?\ ))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1678 (if first-line
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1679 (forward-line 1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1680 (if (and (looking-at "[ \t]*\\*/")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1681 (not (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1682 (forward-line -1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1683 (looking-at ".*/\\*"))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1684 (forward-line -1)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1685
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1686 (let ((line-width (progn (end-of-line)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1687 (current-column))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1688 (beginning-of-line)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1689 (prog1
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1690 (buffer-substring
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1691 (point)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1692
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1693 ;; 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
1694 ;; fill-prefix is?
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1695 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1696 (skip-chars-forward " \t*" (c-point 'eol))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1697 ;; kludge alert, watch out for */, in
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1698 ;; which case fill-prefix should *not*
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1699 ;; be "*"!
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1700 (if (and (eq (char-after) ?/)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1701 (eq (char-before) ?*))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1702 (forward-char -1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1703 (point)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1704
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1705 ;; If the comment is only one line followed
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1706 ;; by a blank line, calling move-to-column
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1707 ;; above may have added some spaces and tabs
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1708 ;; 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
1709 ;; function will then delete it and the
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1710 ;; newline following it, so we'll lose a
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1711 ;; blank line when we shouldn't. So delete
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1712 ;; anything move-to-column added to the end
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1713 ;; of the line. We record the line width
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1714 ;; instead of the position of the old line
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1715 ;; end because move-to-column might break a
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1716 ;; tab into spaces, and the new characters
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1717 ;; introduced there shouldn't be deleted.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1718
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1719 ;; 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
1720 ;; please make the change. This seems very
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1721 ;; messy to me.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1722 (delete-region (progn (move-to-column line-width)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1723 (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1724 (progn (end-of-line) (point)))))))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1725
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1726 ;; Lines containing just a comment start or just an end
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1727 ;; should not be filled into paragraphs they are next
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1728 ;; to.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1729 (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
1730 (concat paragraph-start
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1731 re1 "\\("
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1732 c-Java-javadoc-paragraph-start
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1733 "\\|$\\)")
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1734 (concat paragraph-start re1 "$")))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1735 (paragraph-separate (concat paragraph-separate re1 "$"))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1736 (chars-to-delete 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1737 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1738 (save-restriction
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1739 ;; Don't fill the comment together with the code
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1740 ;; following it. So temporarily exclude everything
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1741 ;; before the comment start, and everything after the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1742 ;; line where the comment ends. If comment-start-place
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1743 ;; is non-nil, the comment starter is there. Otherwise,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1744 ;; point is inside the comment.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1745 (narrow-to-region (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1746 (if comment-start-place
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1747 (goto-char comment-start-place)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1748 (search-backward "/*"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1749 (if (and (not c-hanging-comment-starter-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1750 (looking-at
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1751 (concat c-comment-start-regexp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1752 "[ \t]*$")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1753 (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1754 ;; Protect text before the comment
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1755 ;; start by excluding it. Add
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1756 ;; spaces to bring back proper
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1757 ;; indentation of that point.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1758 (let ((column (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1759 (prog1 (point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1760 (setq chars-to-delete column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1761 (insert-char ?\ column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1762 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1763 (if comment-start-place
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1764 (goto-char (+ comment-start-place 2)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1765 (search-forward "*/" nil 'move)
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1766 (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
1767 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1768 (beginning-of-line)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1769 (looking-at "[ \t]*\\*/")))
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 (forward-line 1))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1772 (point)))
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1773 (or (c-safe
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1774 ;; 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
1775 ;; are between paragraphs.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1776 (beginning-of-line)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1777 (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
1778 (looking-at paragraph-separate))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1779 ;; Avoids recursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1780 (let (fill-paragraph-function)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1781 (fill-paragraph arg)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1782 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1783 ;; Delete the chars we inserted to avoid clobbering
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1784 ;; the stuff before the comment start.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1785 (goto-char (point-min))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1786 (if (> chars-to-delete 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1787 (delete-region (point) (+ (point) chars-to-delete)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1788 ;; Find the comment ender (should be on last line of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1789 ;; buffer, given the narrowing) and don't leave it on
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1790 ;; its own line, unless that's the style that's desired.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1791 (goto-char (point-max))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1792 (forward-line -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1793 (search-forward "*/" nil 'move)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1794 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1795 (if (and c-hanging-comment-ender-p
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1796 (looking-at "[ \t]*\\*/"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1797 ;(delete-indentation)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1798 (let ((fill-column (+ fill-column 9999)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1799 (forward-line -1)
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1800 (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
1801 ;; 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
1802 ;; 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
1803 ;; 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
1804 ;; case.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1805 (goto-char (- (point-max) 2))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1806 (if (not (= (char-before) ?*))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1807 (insert ?*))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1808 )))))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1809 ;; 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
1810 ;; 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
1811 ;; 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
1812 (if (and limits
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1813 (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
1814 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1815 (goto-char (car limits))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1816 (end-of-line)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1817 (< (point) (cdr limits))))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1818 (let (fill-paragraph-function)
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1819 (save-restriction
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1820 (narrow-to-region (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1821 (goto-char (1+ (car limits)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1822 (if (looking-at "\\\\$")
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1823 ;; Some DWIM: Leave the start
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1824 ;; 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
1825 ;; escaped newline.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1826 (1+ (match-end 0))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1827 (point)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1828 (save-excursion
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1829 (goto-char (1- (cdr limits)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1830 ;; Inserting a newline and
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1831 ;; removing it again after
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1832 ;; fill-paragraph makes it more
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1833 ;; predictable.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1834 (insert ?\n)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1835 (point)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1836 ;; 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
1837 ;; 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
1838 ;; column internally.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1839 (fill-paragraph arg)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1840 (goto-char (1- (point-max)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1841 (delete-char 1)))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1842 )))
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1843 (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
1844 (set-marker point-save nil)
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1845 ;; 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
1846 ;; 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
1847 ;; effectively disabled in normal code.
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
1848 t))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1849
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1850
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1851 (provide 'cc-cmds)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1852 ;;; cc-cmds.el ends here