annotate lisp/progmodes/cc-cmds.el @ 35317:6391ae41f1d0

*** empty log message ***
author Gerd Moellmann <gerd@gnu.org>
date Mon, 15 Jan 2001 20:15:25 +0000
parents dd613770eb0f
children 32a4317c6aa5
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
34304
dd613770eb0f Fix copyright years.
Dave Love <fx@gnu.org>
parents: 30406
diff changeset
3 ;; Copyright (C) 1985,87,92,93,94,95,96,97,98,99,2000 Free Software Foundation, Inc.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
4
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
5 ;; Authors: 2000- Martin Stjernholm
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
6 ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
7 ;; 1992-1997 Barry A. Warsaw
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
8 ;; 1987 Dave Detlefs and Stewart Clamen
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
9 ;; 1985 Richard M. Stallman
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
10 ;; Maintainer: bug-cc-mode@gnu.org
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11 ;; 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
12 ;; Version: See cc-mode.el
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13 ;; Keywords: c languages oop
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
14
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; This file is part of GNU Emacs.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
16
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
17 ;; GNU Emacs is free software; you can redistribute it and/or modify
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
18 ;; 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
19 ;; the Free Software Foundation; either version 2, or (at your option)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; any later version.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; GNU Emacs is distributed in the hope that it will be useful,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25 ;; GNU General Public License for more details.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
26
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
27 ;; You should have received a copy of the GNU General Public License
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28 ;; 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
29 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;; Boston, MA 02111-1307, USA.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
31
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
32 (eval-when-compile
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
33 (let ((load-path
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
34 (if (and (boundp 'byte-compile-current-file)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
35 (stringp byte-compile-current-file))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
36 (cons (file-name-directory byte-compile-current-file)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
37 load-path)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
38 load-path)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
39 (load "cc-defs" nil t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
40 (require 'cc-engine)
18843
6e04c0670f55 Require cc-defs for the c-add-syntax macro.
Richard M. Stallman <rms@gnu.org>
parents: 18720
diff changeset
41
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
42
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 (defun c-calculate-state (arg prevstate)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; 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
45 ;; 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
46 ;; the state off, and if arg is positive, turn the state on
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
47 (if (or (not arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
48 (zerop (setq arg (prefix-numeric-value arg))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
49 (not prevstate)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 (> arg 0)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
52 ;; Auto-newline and hungry-delete
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
53 (defun c-toggle-auto-state (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
54 "Toggle auto-newline feature.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55 Optional numeric ARG, if supplied turns on auto-newline when positive,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
56 turns it off when negative, and just toggles it when zero.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
57
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 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
59 `/ah' on the modeline after the mode name) newlines are automatically
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 inserted after special characters such as brace, comma, semi-colon,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 and colon."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 (interactive "P")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 (c-update-modeline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 (defun c-toggle-hungry-state (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
68 "Toggle hungry-delete-key feature.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
69 Optional numeric ARG, if supplied turns on hungry-delete when positive,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
70 turns it off when negative, and just toggles it when zero.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
71
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72 When the hungry-delete-key feature is enabled (as evidenced by the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 `/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
74 gobbles all preceding whitespace in one fell swoop."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 (interactive "P")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 (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
77 (c-update-modeline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
78 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
79
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
80 (defun c-toggle-auto-hungry-state (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 "Toggle auto-newline and hungry-delete-key features.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
82 Optional numeric ARG, if supplied turns on auto-newline and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
83 hungry-delete when positive, turns them off when negative, and just
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
84 toggles them when zero.
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 See `c-toggle-auto-state' and `c-toggle-hungry-state' for details."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
87 (interactive "P")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
88 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
89 (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
90 (c-update-modeline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
91 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
92
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
93
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
94 ;; Electric keys
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
95
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96 ;; Note: In XEmacs 20.3 the Delete and BackSpace keysyms have been
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
97 ;; separated and "\177" is no longer an alias for both keys. Also,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
98 ;; the variable delete-key-deletes-forward controls in which direction
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
99 ;; the Delete keysym deletes characters. The functions
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
100 ;; c-electric-delete and c-electric-backspace attempt to deal with
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101 ;; this new functionality. For Emacs 19 and XEmacs 19 backwards
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
102 ;; compatibility, the old behavior has moved to c-electric-backspace
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
103 ;; and c-backspace-function.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
104
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
105 (defun c-electric-backspace (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
106 "Deletes preceding character or whitespace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
107 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
108 \"/ah\" string on the mode line, then all preceding whitespace is
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
109 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
110 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
111 `c-backspace-function' is called.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
112
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
113 See also \\[c-electric-delete]."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
114 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115 (if (or (not c-hungry-delete-key)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
116 arg
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 (c-in-literal))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 (funcall c-backspace-function (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
119 (let ((here (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
120 (skip-chars-backward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 (if (/= (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
122 (delete-region (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
123 (funcall c-backspace-function 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
124 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
125
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126 (defun c-electric-delete (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 "Deletes preceding or following character or whitespace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 The behavior of this function depends on the variable
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130 `delete-key-deletes-forward'. If this variable is nil (or does not
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 exist, as in older Emacsen), then this function behaves identical to
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 \\[c-electric-backspace].
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
134 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
135 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
136 `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
137 \"/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
138 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
139 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
140 `c-delete-function' is called."
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
141 (interactive "*P")
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
142 (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
143 (delete-forward-p))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
144 (and (boundp 'delete-key-deletes-forward) ;XEmacs 20
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
145 delete-key-deletes-forward))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (if (or (not c-hungry-delete-key)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 arg
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 (c-in-literal))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149 (funcall c-delete-function (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (let ((here (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 (skip-chars-forward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 (if (/= (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153 (delete-region (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 (funcall c-delete-function 1))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 ;; act just like c-electric-backspace
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 (c-electric-backspace arg)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 (defun c-electric-pound (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 "Electric pound (`#') insertion.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 Inserts a `#' character specially depending on the variable
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 `c-electric-pound-behavior'. If a numeric ARG is supplied, or if
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 point is inside a literal, nothing special happens."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
163 (interactive "*P")
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
164 (if (or arg
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
165 (not (memq 'alignleft c-electric-pound-behavior))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
166 (save-excursion (skip-chars-backward " \t") (not (bolp)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
167 (c-in-literal))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 ;; do nothing special
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 ;; place the pound character at the left edge
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171 (let ((pos (- (point-max) (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (bolp (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (delete-horizontal-space)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (insert-char last-command-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (and (not bolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 (goto-char (- (point-max) pos)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 )))
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 (defun c-electric-brace (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 "Insert a brace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 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
184 or \"/ah\" string on the mode line, newlines are inserted before and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 after braces based on the value of `c-hanging-braces-alist'.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 Also, the line is re-indented unless a numeric ARG is supplied, there
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
188 are non-whitespace characters present on the line after the brace, the
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
189 brace is inserted inside a literal, or `c-syntactic-indentation' is
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
190 nil.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
191
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
192 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
193 `c-cleanup-list'."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
194 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (let* ((c-state-cache (c-parse-state))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (safepos (c-safe-position (point) c-state-cache))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197 (literal (c-in-literal safepos)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 ;; 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
199 ;; a numeric arg is provided, or auto-newlining is turned off,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 ;; then just insert the character.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
201 (if (or literal
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
202 arg
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (not (looking-at "[ \t]*$")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (self-insert-command (prefix-numeric-value arg))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
205 (let* ((syms
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
206 ;; 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
207 ;; 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
208 ;; they should be added here as well.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
209 '(class-open class-close defun-open defun-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
210 inline-open inline-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
211 brace-list-open brace-list-close
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
212 brace-list-intro brace-entry-open
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
213 block-open block-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
214 substatement-open statement-case-open
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
215 extern-lang-open extern-lang-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
216 namespace-open namespace-close
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
217 inexpr-class-open inexpr-class-close
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
218 ))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 ;; we want to inhibit blinking the paren since this will
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 ;; be most disruptive. we'll blink it ourselves later on
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 (old-blink-paren blink-paren-function)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 blink-paren-function
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (insertion-point (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 delete-temp-newline
19306
974544be1a17 (c-electric-brace): Make preserve-p nil at BOB.
Richard M. Stallman <rms@gnu.org>
parents: 19297
diff changeset
225 (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
226 (eq ?\ (char-syntax (char-before)))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ;; shut this up too
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 (c-echo-syntactic-information-p nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (syntax (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ;; only insert a newline if there is
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 ;; non-whitespace behind us
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (skip-chars-backward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 (not (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (progn (newline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 (setq delete-temp-newline t)))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
237 (if (eq last-command-char ?{)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
238 (setq c-state-cache (cons (point) c-state-cache)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 ;; state cache doesn't change
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (c-guess-basic-syntax)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (newlines (and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 c-auto-newline
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
244 (or (c-lookup-lists
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
245 syms
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
246 ;; Substitute inexpr-class and class-open
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
247 ;; or class-close with inexpr-class-open
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
248 ;; or inexpr-class-close.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
249 (if (assq 'inexpr-class syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
250 (cond ((assq 'class-open syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
251 '((inexpr-class-open)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
252 ((assq 'class-close syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
253 '((inexpr-class-close)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
254 (t syntax))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
255 syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
256 c-hanging-braces-alist)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 '(ignore before after)))))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
258 ;; 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
259 ;; brace list.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
260 (if (and c-special-brace-lists
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
261 (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
262 brace-list-intro brace-entry-open)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
263 syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
264 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
265 (c-safe (if (= (char-before) ?{)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
266 (forward-char -1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
267 (c-forward-sexp -1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
268 (c-looking-at-special-brace-list))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
269 (setq newlines nil))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270 ;; If syntax is a function symbol, then call it using the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 ;; defined semantics.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 (if (and (not (consp (cdr newlines)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (functionp (cdr newlines)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 (let ((c-syntactic-context syntax))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (setq newlines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 (funcall (cdr newlines) (car newlines) insertion-point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 ;; does a newline go before the open brace?
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 (if (memq 'before newlines)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 ;; we leave the newline we've put in there before,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 ;; but we need to re-indent the line above
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (let ((pos (- (point-max) (point)))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
282 (here (point)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (forward-line -1)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
284 (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
285 ;; 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
286 ;; still be faster than recalculating the state
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
287 ;; in many cases
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
288 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
289 (save-restriction
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
290 (narrow-to-region here (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
291 (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
292 (memq (char-before) '(?\) ?}))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
293 (progn (widen)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
294 (c-safe (progn (c-forward-sexp -1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
295 t))))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
296 (setq c-state-cache
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
297 (c-hack-state (point) 'open c-state-cache)))))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
298 (if c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
299 (c-indent-line)))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
300 (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
301 (- (point) (c-point 'bol))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
302 c-state-cache))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 (goto-char (- (point-max) pos))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 ;; if the buffer has changed due to the indentation, we
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305 ;; need to recalculate syntax for the current line, but
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 ;; we won't need to update the state cache.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (if (/= (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 (setq syntax (c-guess-basic-syntax))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 ;; 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
310 (and delete-temp-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 ;; if there is whitespace before point, then preserve
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313 ;; at least one space.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (delete-indentation)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 (just-one-space)
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
316 (setq c-state-cache (c-whack-state (point) c-state-cache))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (if (not preserve-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (delete-char -1))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 ;; since we're hanging the brace, we need to recalculate
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 ;; syntax. Update the state to accurately reflect the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 ;; beginning of the line. We punt if we cross any open or
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 ;; closed parens because its just too hard to modify the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 ;; known state. This limitation will be fixed in v5.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (let ((bol (c-point 'bol)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (if (zerop (car (parse-partial-sexp bol (1- (point)))))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
327 (setq syntax (c-guess-basic-syntax))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 ;; gotta punt. this requires some horrible kludgery
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330 (makunbound 'c-state-cache)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (setq c-state-cache (c-parse-state)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 syntax nil))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 ;; now adjust the line's indentation. don't update the state
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 ;; cache since c-guess-basic-syntax isn't called when the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 ;; syntax is passed to c-indent-line
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
337 (let* ((here (point)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
338 (c-indent-line syntax)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (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
340 (- (c-point 'boi) (c-point 'bol))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
341 c-state-cache)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 ;; Do all appropriate clean ups
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (let ((here (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (pos (- (point-max) (point)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
345 mbeg mend tmp)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 ;; clean up empty defun braces
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (if (and c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (memq 'empty-defun-braces c-cleanup-list)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (eq last-command-char ?\})
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 (c-intersect-lists '(defun-close class-close inline-close)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 syntax)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (skip-chars-backward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 (eq (char-before) ?\{))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
356 ;; make sure matching open brace isn't in a comment
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 (delete-region (point) (1- here)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
359 ;; clean up brace-else-brace and brace-elseif-brace
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
360 (when (and c-auto-newline
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
361 (eq last-command-char ?\{)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
362 (not (c-in-literal)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
363 (cond
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
364 ((and (memq 'brace-else-brace c-cleanup-list)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (re-search-backward "}[ \t\n]*else[ \t\n]*{" nil t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (setq mbeg (match-beginning 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368 mend (match-end 0))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
369 (eq (match-end 0) here)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
370 (delete-region mbeg mend)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
371 (insert "} else {"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
372 ((and (memq 'brace-elseif-brace c-cleanup-list)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
373 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
374 (goto-char (1- here))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
375 (setq mend (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
376 (skip-chars-backward " \t\n")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
377 (setq mbeg (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
378 (eq (char-before) ?\)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
379 (= (c-backward-token-1 1 t) 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
380 (eq (char-after) ?\()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
381 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
382 (setq tmp (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
383 (re-search-backward "}[ \t\n]*else[ \t\n]+if[ \t\n]*"
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
384 nil t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
385 (eq (match-end 0) tmp))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
386 (delete-region mbeg mend)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
387 (goto-char mbeg)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
388 (insert " "))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (goto-char (- (point-max) pos))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 ;; does a newline go after the brace?
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 (if (memq 'after newlines)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 (newline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 ;; update on c-state-cache
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 (let* ((bufpos (- (point) 2))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (which (if (eq (char-after bufpos) ?{) 'open 'close))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (c-state-cache (c-hack-state bufpos which c-state-cache)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (c-indent-line))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 ;; blink the paren
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (and (eq last-command-char ?\})
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 old-blink-paren
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 (c-backward-syntactic-ws safepos)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (funcall old-blink-paren)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 ))))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
407
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (defun c-electric-slash (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 "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
410
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
411 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
412
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
413 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
414 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
415
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
416 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
417 comment.
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
418
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
419 If a numeric ARG is supplied, point is inside a literal, or
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
420 `c-syntactic-indentation' is nil, indentation is inhibited."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
421 (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
422 (let* ((ch (char-before))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
423 (indentp (and c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
424 (not arg)
19297
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
425 (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
426 (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
427 (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
428 (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
429 (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
430 ))
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
431 ;; 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
432 (c-echo-syntactic-information-p nil))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
433 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 (if indentp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 (c-indent-line))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 (defun c-electric-star (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 "Insert a star character.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 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
440 construct, and we are on a comment-only-line, indent line as comment.
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
441 If a numeric ARG is supplied, point is inside a literal, or
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
442 `c-syntactic-indentation' is nil, indentation is inhibited."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
443 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 ;; 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
446 ;; current line, unless this star introduces a comment-only line.
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
447 (if (and c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
448 (not arg)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (memq (c-in-literal) '(c))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (eq (char-before) ?*)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (skip-chars-backward "*")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (if (eq (char-before) ?/)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (forward-char -1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 (skip-chars-backward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
458 ;; shut this up
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
459 (let (c-echo-syntactic-information-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
460 (c-indent-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
461 ))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
462
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
463 (defun c-electric-semi&comma (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
464 "Insert a comma or semicolon.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
465 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
466 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
467 the variable `c-hanging-semi&comma-criteria' for how newline insertion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 is determined.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
469
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
470 When semicolon is inserted, the line is re-indented unless a numeric
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
471 arg is supplied, point is inside a literal, or there are
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
472 non-whitespace characters on the line following the semicolon, or
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
473 `c-syntactic-indentation' is nil.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
474
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
475 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
476 following brace lists and semicolons following defuns."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
477 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (let* ((lim (c-most-enclosing-brace (c-parse-state)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 (literal (c-in-literal lim))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (here (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 ;; shut this up
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (c-echo-syntactic-information-p nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (if (or literal
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 arg
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 (not (looking-at "[ \t]*$")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 ;; do some special stuff with the character
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 (self-insert-command (prefix-numeric-value arg))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
489 ;; 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
490 ;; turned on
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
491 (if (not c-auto-newline)
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
492 (if c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
493 (c-indent-line))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 ;; clean ups
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 (let ((pos (- (point-max) (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 (if (and (or (and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (eq last-command-char ?,)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (memq 'list-close-comma c-cleanup-list))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (eq last-command-char ?\;)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (memq 'defun-close-semi c-cleanup-list)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (skip-chars-backward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (eq (char-before) ?}))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 ;; make sure matching open brace isn't in a comment
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (not (c-in-literal lim)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 (delete-region (point) here))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (goto-char (- (point-max) pos)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 ;; re-indent line
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
511 (if c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
512 (c-indent-line))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 ;; check to see if a newline should be added
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 (let ((criteria c-hanging-semi&comma-criteria)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 answer add-newline-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (while criteria
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (setq answer (funcall (car criteria)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 ;; only nil value means continue checking
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (if (not answer)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (setq criteria (cdr criteria))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (setq criteria nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 ;; only 'stop specifically says do not add a newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (setq add-newline-p (not (eq answer 'stop)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 ))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (if add-newline-p
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 (progn (newline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (c-indent-line)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 )))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 (defun c-electric-colon (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 "Insert a colon.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 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
534 or \"/ah\" string on the mode line, newlines are inserted before and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 after colons based on the value of `c-hanging-colons-alist'.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 Also, the line is re-indented unless a numeric ARG is supplied, there
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
538 are non-whitespace characters present on the line after the colon, the
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
539 colon is inserted inside a literal, or `c-syntactic-indentation' is
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
540 nil.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542 This function cleans up double colon scope operators based on the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543 value of `c-cleanup-list'."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
544 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (let* ((bod (c-point 'bod))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546 (literal (c-in-literal bod))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
547 syntax newlines is-scope-op
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 ;; shut this up
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 (c-echo-syntactic-information-p nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (if (or literal
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 arg
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (not (looking-at "[ \t]*$")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 ;; insert the colon, then do any specified cleanups
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556 (let ((pos (- (point-max) (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (here (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 (if (and c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559 (memq 'scope-operator c-cleanup-list)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560 (eq (char-before) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (skip-chars-backward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
564 (eq (char-before) ?:))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (not (c-in-literal))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 (not (eq (char-after (- (point) 2)) ?:)))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
567 (progn
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
568 (delete-region (point) (1- here))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
569 (setq is-scope-op t)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 (goto-char (- (point-max) pos)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 ;; lets do some special stuff with the colon character
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (setq syntax (c-guess-basic-syntax)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 ;; some language elements can only be determined by
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 ;; checking the following line. Lets first look for ones
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 ;; that can be found when looking on the line with the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 ;; colon
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 newlines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
578 (and c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (or (c-lookup-lists '(case-label label access-label)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 syntax c-hanging-colons-alist)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (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
582 (let ((buffer-undo-list t))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
583 (insert "\n")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
584 (unwind-protect
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
585 (c-guess-basic-syntax)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
586 (delete-char -1)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 c-hanging-colons-alist))))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
588 ;; indent the current line if it's done syntactically.
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
589 (if c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
590 (c-indent-line syntax))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 ;; does a newline go before the colon? Watch out for already
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
592 ;; non-hung colons. However, we don't unhang them because that
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 ;; would be a cleanup (and anti-social).
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (if (and (memq 'before newlines)
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
595 (not is-scope-op)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 (skip-chars-backward ": \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
598 (not (bolp))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
599 (let ((pos (- (point-max) (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601 (newline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (c-indent-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
603 (goto-char (- (point-max) pos))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
604 ;; does a newline go after the colon?
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
605 (if (and (memq 'after (cdr-safe newlines))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
606 (not is-scope-op))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
607 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (newline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 (c-indent-line)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
611
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
612 (defun c-electric-lt-gt (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
613 "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
614 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
615 of a C++ style stream operator and the buffer is in C++ mode.
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
616 Exceptions are when a numeric argument is supplied, point is inside a
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
617 literal, or `c-syntactic-indentation' is nil, in which case the line
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
618 will not be re-indented."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
619 (interactive "*P")
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
620 (let ((indentp (and c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
621 (not arg)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
622 (eq (char-before) last-command-char)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
623 (not (c-in-literal))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 ;; shut this up
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 (c-echo-syntactic-information-p nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 (if indentp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 (c-indent-line))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
629
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
630 (defun c-electric-paren (arg)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
631 "Insert a parenthesis.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
632
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
633 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
634 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
635 appropriate; see the variable `c-cleanup-list'.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
636
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
637 Also, the line is re-indented unless a numeric ARG is supplied, there
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
638 are non-whitespace characters present on the line after the
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
639 parenthesis, the parenthesis is inserted inside a literal, or
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
640 `c-syntactic-indentation' is nil."
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
641 (interactive "*P")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
642 (let (;; shut this up
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
643 (c-echo-syntactic-information-p nil))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
644 (if (or arg
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
645 (not (looking-at "[ \t]*$"))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
646 (c-in-literal (c-point 'bod)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
647 (self-insert-command (prefix-numeric-value arg))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
648 ;; do some special stuff with the character
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
649 (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
650 ;; be most disruptive. We'll blink it ourselves
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
651 ;; afterwards.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
652 (old-blink-paren blink-paren-function)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
653 blink-paren-function)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
654 (self-insert-command (prefix-numeric-value arg))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
655 (if c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
656 (c-indent-line))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
657 (when c-auto-newline
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
658 ;; Do all appropriate clean ups
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
659 (let ((here (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
660 (pos (- (point-max) (point)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
661 mbeg mend)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
662 ;; clean up brace-elseif-brace
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
663 (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
664 (eq last-command-char ?\()
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
665 (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
666 nil t)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
667 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
668 (setq mbeg (match-beginning 0)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
669 mend (match-end 0))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
670 (= mend here))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
671 (not (c-in-literal)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
672 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
673 (delete-region mbeg mend)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
674 (insert "} else if (")))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
675 ;; clean up brace-catch-brace
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
676 (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
677 (eq last-command-char ?\()
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
678 (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
679 (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
680 (setq mbeg (match-beginning 0)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
681 mend (match-end 0))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
682 (= mend here))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
683 (not (c-in-literal)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
684 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
685 (delete-region mbeg mend)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
686 (insert "} catch (")))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
687 (goto-char (- (point-max) pos))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
688 ))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
689 (if old-blink-paren
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
690 (funcall old-blink-paren))))))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
691
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 ;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 ;; originally contributed by Terry_Glanfield.Southern@rxuk.xerox.com
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696 (defun c-forward-into-nomenclature (&optional arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 "Move forward to end of a nomenclature section or word.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 With arg, to it arg times."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 (let ((case-fold-search nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701 (if (> arg 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 (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
703 (while (and (< arg 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 (re-search-backward
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 "\\(\\(\\W\\|[a-z0-9]\\)[A-Z]+\\|\\W\\w+\\)"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 (point-min) 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 (setq arg (1+ arg)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 (defun c-backward-into-nomenclature (&optional arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
712 "Move backward to beginning of a nomenclature section or word.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 With optional ARG, move that many times. If ARG is negative, move
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 forward."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 (c-forward-into-nomenclature (- arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 (defun c-scope-operator ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
720 "Insert a double colon scope operator at point.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
721 No indentation or other \"electric\" behavior is performed."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
722 (interactive "*")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (insert "::"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
725 (defun c-beginning-of-defun (&optional arg)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
726 "Move backward to the beginning of a defun.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
727 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
728 means move forward to Nth following beginning of defun.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
729 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
730
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
731 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
732 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
733 defun."
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
734 (interactive "p")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
735 (unless arg (setq arg 1))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
736 (if (< arg 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
737 (c-end-of-defun (- arg))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
738 (while (> arg 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
739 (let ((state (nreverse (c-parse-state)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
740 prevbod bod)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
741 (while (and state (not bod))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
742 (setq bod (car state)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
743 state (cdr state))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
744 (if (consp bod)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
745 (setq prevbod (car bod)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
746 bod nil)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
747 (cond
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
748 (bod (goto-char bod))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
749 (prevbod (goto-char prevbod))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
750 (t (goto-char (point-min))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
751 (setq arg 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
752 (setq arg (1- arg))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
753 (c-keep-region-active)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
754 (= arg 0)))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
755
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
756 (defun c-end-of-defun (&optional arg)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
757 "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
758 Negative argument -N means move back to Nth preceding end of defun.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
759 Returns t unless search stops due to beginning or end of buffer.
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
760
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
761 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
762 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
763 (interactive "p")
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
764 (if (not arg)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
765 (setq arg 1))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
766 (if (< arg 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
767 (c-beginning-of-defun (- arg))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
768 (while (> arg 0)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
769 (let ((pos (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
770 eol)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
771 (while (and (c-safe (down-list 1) t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
772 (not (eq (char-before) ?{)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
773 ;; skip down into the next defun-block
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
774 (forward-char -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
775 (c-forward-sexp))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
776 (c-beginning-of-defun 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
777 (setq eol (c-point 'eol))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
778 (c-forward-sexp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
779 (if (< eol (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
780 ;; Don't move to next line for one line defuns.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
781 (forward-line 1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
782 (when (<= (point) pos)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
783 (goto-char (point-max))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
784 (setq arg 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
785 (setq arg (1- arg))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
786 (c-keep-region-active)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
787 (= arg 0)))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
788
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 (defun c-beginning-of-statement (&optional count lim sentence-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 "Go to the beginning of the innermost C statement.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 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
793 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
794 preceding one, moving into nested blocks if necessary (use
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
795 \\[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
796 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
797 statements.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
799 When called from a program, this function takes 3 optional args: the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 repetition count, a buffer position limit which is the farthest back
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
801 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
802 comment."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 (interactive (list (prefix-numeric-value current-prefix-arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 nil t))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
805 (let* ((count (or count 1))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
806 here
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
807 (range (c-collect-line-comments (c-literal-limits lim))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
808 (while (and (/= count 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
809 (or (not lim) (> (point) lim)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
810 (setq here (point))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
811 (if (and (not range) sentence-flag)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
812 (save-excursion
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
813 ;; 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
814 (if (> count 0)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
815 (setq range (if (c-forward-comment -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
816 (cons (point)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
817 (progn (c-forward-comment 1) (point)))))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
818 (skip-chars-forward " \t\n")
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
819 (setq range (point))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
820 (setq range (if (c-forward-comment 1)
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
821 (cons range (point))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
822 nil)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
823 (setq range (c-collect-line-comments range))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
824 (if (and (< count 0) (= here (point-max)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
825 ;; Special case because eob might be in a literal.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
826 (setq range nil))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
827 (if range
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
828 (if (and sentence-flag
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
829 (/= (char-syntax (char-after (car range))) ?\"))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
830 (let* ((lit-type (c-literal-type range))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
831 (beg (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
832 (goto-char (car range))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
833 (looking-at (if (eq lit-type 'c)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
834 comment-start-skip
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
835 (concat "\\("
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
836 c-comment-prefix-regexp
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
837 "\\)[ \t]*")))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
838 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
839 (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
840 (end (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
841 (goto-char (- (cdr range)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
842 (if (eq lit-type 'c) 2 1)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
843 (point))))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
844 ;; 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
845 (save-restriction
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
846 (narrow-to-region beg end)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
847 (c-safe (forward-sentence (if (< count 0) 1 -1)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
848 (if (and (memq lit-type '(c c++))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
849 ;; Check if we stopped due to a comment
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
850 ;; prefix and not a sentence end.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
851 (/= (point) beg)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
852 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
853 (beginning-of-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
854 (looking-at (concat "[ \t]*\\("
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
855 c-comment-prefix-regexp
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
856 "\\)[ \t]*")))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
857 (>= (point) (match-beginning 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
858 (/= (match-beginning 1) (match-end 1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
859 (or (< (point) (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
860 (and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
861 (= (point) (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
862 ;; The comment prefix may contain
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
863 ;; characters that is regarded as end
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
864 ;; of sentence.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
865 (or (eolp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
866 (and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
867 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
868 (forward-paragraph -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
869 (< (point) (match-beginning 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
870 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
871 (beginning-of-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
872 (or (not (re-search-backward
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
873 sentence-end
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
874 (c-point 'bopl)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
875 t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
876 (< (match-end 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
877 (c-point 'eol)))))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
878 (setq count (+ count (if (< count 0) -1 1)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
879 (if (< count 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
880 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
881 ;; In block comments, if there's only
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
882 ;; horizontal ws between the text and the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
883 ;; comment ender, stop before it. Stop after
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
884 ;; the ender if there's either nothing or
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
885 ;; newlines between.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
886 (when (and (eq lit-type 'c) (eq (point) end))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
887 (widen)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
888 (skip-chars-backward " \t")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
889 (when (or (eq (point) end) (bolp))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
890 (goto-char (cdr range)))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
891 (when (and (eq (point) beg) (looking-at "[ \t]*$"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
892 ;; Stop before instead of after the comment
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
893 ;; starter if nothing follows it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
894 (widen)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
895 (goto-char (car range))))))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
896 ;; See if we should escape the literal.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
897 (if (> count 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
898 (if (< (point) here)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
899 (setq count (1- count))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
900 (goto-char (car range))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
901 (setq range nil))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
902 (if (> (point) here)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
903 (setq count (1+ count))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
904 (goto-char (cdr range))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
905 (setq range nil))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
906 (goto-char (if (> count 0) (car range) (cdr range)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
907 (setq range nil))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
908 ;; Below we do approximately the same as
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
909 ;; c-beginning-of-statement-1 and c-end-of-statement-1, and
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
910 ;; 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
911 ;; lot in cc-engine.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
912 (goto-char here)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
913 (if (> count 0)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
914 (condition-case nil
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
915 ;; Stop before `{' and after `;', `{', `}' and `};'
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
916 ;; when not followed by `}' or `)', but on the other
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
917 ;; side of the syntactic ws. Move by sexps and move
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
918 ;; into parens. Also stop before `#' when it's first
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
919 ;; on a line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
920 (let ((comment-pos (not sentence-flag))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
921 (large-enough (- (point-max)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
922 last last-below-line)
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
923 (catch 'done
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
924 (while t
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
925 (setq last (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
926 (when (and (looking-at "{\\|^#") (/= here last))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
927 (unless (and c-special-brace-lists
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
928 (eq (char-after) ?{)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
929 (c-looking-at-special-brace-list))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
930 (if (and (eq (char-after) ?#)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
931 (numberp last-below-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
932 (not (eq last-below-line here)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
933 (goto-char last-below-line))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
934 (throw 'done t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
935 (if comment-pos
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
936 (c-forward-comment large-enough)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
937 (when (c-forward-comment -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
938 ;; Record position of first comment.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
939 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
940 (c-forward-comment 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
941 (setq comment-pos (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
942 (c-forward-comment large-enough)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
943 (unless last-below-line
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
944 (if (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
945 (re-search-forward "\\(^\\|[^\\]\\)$" last t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
946 (setq last-below-line last)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
947 (cond ((bobp) ; Must handle bob specially.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
948 (if (= here last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
949 (throw 'done t)
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
950 (goto-char last)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
951 (throw 'done t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
952 ((progn (backward-char)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
953 (looking-at "[;{}]"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
954 (if (and c-special-brace-lists
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
955 (eq (char-after) ?{)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
956 (c-looking-at-special-brace-list))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
957 (skip-syntax-backward "w_") ; Speedup only.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
958 (if (or (= here last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
959 (memq (char-after last) '(?\) ?})))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
960 (if (and (eq (char-before) ?})
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
961 (eq (char-after) ?\;))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
962 (backward-char))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
963 (goto-char last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
964 (throw 'done t))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
965 ((= (char-syntax (char-after)) ?\")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
966 (forward-char)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
967 (c-backward-sexp))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
968 (t (skip-syntax-backward "w_")) ; Speedup only.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
969 )))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
970 (if (and (numberp comment-pos)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
971 (< (point) comment-pos))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
972 ;; We jumped over a comment that should be investigated.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
973 (goto-char comment-pos)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
974 (setq count (1- count))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
975 (error
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
976 (goto-char (point-min))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
977 (setq count 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
978 (condition-case nil
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
979 ;; Stop before `{', `}', and `#' when it's first on a
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
980 ;; line, but on the other side of the syntactic ws, and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
981 ;; after `;', `}' and `};'. Only stop before `{' if at
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
982 ;; top level or inside braces, though. Move by sexps
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
983 ;; and move into parens. Also stop at eol of lines
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
984 ;; starting with `#'.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
985 (let ((comment-pos (not sentence-flag))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
986 (large-enough (point-max))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
987 last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
988 (catch 'done
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
989 (while t
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
990 (setq last (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
991 (if comment-pos
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
992 (c-forward-comment large-enough)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
993 (if (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
994 (skip-chars-forward " \t\n\r\f")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
995 ;; Record position of first comment.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
996 (setq comment-pos (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
997 (c-forward-comment 1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
998 (c-forward-comment large-enough)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
999 (setq comment-pos nil)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1000 (cond ((and (eq (char-after) ?{)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1001 (not (and c-special-brace-lists
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1002 (c-looking-at-special-brace-list)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1003 (/= here last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1004 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1005 (or (not (c-safe (up-list -1) t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1006 (= (char-after) ?{))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1007 (goto-char last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1008 (throw 'done t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1009 ((and c-special-brace-lists
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1010 (eq (char-after) ?})
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1011 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1012 (and (c-safe (up-list -1) t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1013 (c-looking-at-special-brace-list))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1014 (forward-char 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1015 (skip-syntax-forward "w_")) ; Speedup only.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1016 ((and (eq (char-after) ?})
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1017 (/= here last))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1018 (goto-char last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1019 (throw 'done t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1020 ((looking-at "^#")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1021 (if (= here last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1022 (or (re-search-forward "\\(^\\|[^\\]\\)$" nil t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1023 (goto-char (point-max)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1024 (goto-char last))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1025 (throw 'done t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1026 ((looking-at ";\\|};?")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1027 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1028 (throw 'done t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1029 ((= (char-syntax (char-after)) ?\")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1030 (c-forward-sexp))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1031 (t
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1032 (forward-char 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1033 (skip-syntax-forward "w_")) ; Speedup only.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1034 )))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1035 (if (and (numberp comment-pos)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1036 (> (point) comment-pos))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1037 ;; We jumped over a comment that should be investigated.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1038 (goto-char comment-pos)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1039 (setq count (1+ count))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1040 (error
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1041 (goto-char (point-max))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1042 (setq count 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1043 ))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1044 ;; If we haven't moved we're near a buffer limit.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1045 (when (and (not (zerop count)) (= (point) here))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1046 (goto-char (if (> count 0) (point-min) (point-max)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1047 (setq count 0)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1048 ;; 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
1049 (if lim (goto-char (max (point) lim))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1050 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1051
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1052 (defun c-end-of-statement (&optional count lim sentence-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1053 "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
1054 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
1055 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
1056 \(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
1057 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
1058 of statements.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1059
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1060 When called from a program, this function takes 3 optional args: the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1061 repetition count, a buffer position limit which is the farthest back
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1062 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
1063 comment."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1064 (interactive (list (prefix-numeric-value current-prefix-arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1065 nil t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1066 (c-beginning-of-statement (- (or count 1)) lim sentence-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1067 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1068
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1069
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1070 ;; set up electric character functions to work with pending-del,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1071 ;; (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
1072 ;; the functions which delete, which gets 'supersede.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1073 (mapcar
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1074 (function
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1075 (lambda (sym)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1076 (put sym 'delete-selection t) ; for delsel (Emacs)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1077 (put sym 'pending-delete t))) ; for pending-del (XEmacs)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1078 '(c-electric-pound
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1079 c-electric-brace
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1080 c-electric-slash
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1081 c-electric-star
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1082 c-electric-semi&comma
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1083 c-electric-lt-gt
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1084 c-electric-colon
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1085 c-electric-paren))
18843
6e04c0670f55 Require cc-defs for the c-add-syntax macro.
Richard M. Stallman <rms@gnu.org>
parents: 18720
diff changeset
1086 (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
1087 (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
1088 (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
1089 (put 'c-electric-backspace 'pending-delete 'supersede) ; pending-del
18720
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
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1092 ;; 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
1093 ;; comment in C code based on its context.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1094 (defun c-comment-indent ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1095 (if (looking-at (concat "^\\(" c-comment-start-regexp "\\)"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1096 0 ;Existing comment at bol stays there.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1097 (let ((opoint (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1098 placeholder)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1099 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1100 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1101 (cond
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1102 ;; CASE 1: A comment following a solitary close-brace should
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1103 ;; have only one space.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1104 ((looking-at (concat "[ \t]*}[ \t]*\\($\\|"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1105 c-comment-start-regexp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1106 "\\)"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1107 (search-forward "}")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1108 (1+ (current-column)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1109 ;; CASE 2: 2 spaces after #endif
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1110 ((or (looking-at "^#[ \t]*endif[ \t]*")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1111 (looking-at "^#[ \t]*else[ \t]*"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1112 7)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1113 ;; 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
1114 ;; calculate the offset according to c-offsets-alist.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1115 ;; E.g. identical to hitting TAB.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1116 ((and c-indent-comments-syntactically-p
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1117 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1118 (skip-chars-forward " \t")
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1119 (or (looking-at c-comment-start-regexp)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1120 (eolp))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1121 (let ((syntax (c-guess-basic-syntax)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1122 ;; BOGOSITY ALERT: if we're looking at the eol, its
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1123 ;; because indent-for-comment hasn't put the comment-start
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1124 ;; in the buffer yet. this will screw up the syntactic
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1125 ;; analysis so we kludge in the necessary info. Another
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1126 ;; 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
1127 ;; to ignore any anchoring as specified by
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1128 ;; c-comment-only-line-offset since it doesn't apply here.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1129 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1130 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1131 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1132 (eolp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1133 (c-add-syntax 'comment-intro))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1134 (let ((c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1135 (if (consp c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1136 c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1137 (cons c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1138 c-comment-only-line-offset))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1139 (apply '+ (mapcar 'c-get-offset syntax)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1140 ;; CASE 4: If previous line is a comment-only line, use its
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1141 ;; indentation if it's greater than comment-column. Leave at
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1142 ;; least one space between the comment and the last nonblank
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1143 ;; character in any case.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1144 ((save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1145 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1146 (and (not (bobp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1147 (forward-line -1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1148 (skip-chars-forward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1149 (prog1
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1150 (looking-at c-comment-start-regexp)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1151 (setq placeholder (current-column))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1152 (goto-char opoint)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1153 (skip-chars-backward " \t")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1154 (max (if (bolp) 0 (1+ (current-column)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1155 placeholder
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1156 comment-column))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1157 ;; CASE 5: If comment-column is 0, and nothing but space
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1158 ;; before the comment, align it at 0 rather than 1.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1159 ((progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1160 (goto-char opoint)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1161 (skip-chars-backward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1162 (and (= comment-column 0) (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1163 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1164 ;; CASE 6: indent at comment column except leave at least one
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1165 ;; space.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1166 (t (max (1+ (current-column))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1167 comment-column))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1168 )))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1169
19804
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1170
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1171 ;; used by outline-minor-mode
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1172 (defun c-outline-level ()
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1173 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1174 (skip-chars-forward "\t ")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1175 (current-column)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1176
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1177
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1178 (defun c-up-conditional (count)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1179 "Move back to the containing preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1180 A prefix argument acts as a repeat count. With a negative argument,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1181 move forward to the end of the containing preprocessor conditional.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1182
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1183 `#elif' is treated like `#else' followed by `#if', so the function
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1184 stops at them when going backward, but not when going forward."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1185 (interactive "p")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1186 (c-forward-conditional (- count) -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1187 (c-keep-region-active))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1188
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1189 (defun c-up-conditional-with-else (count)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1190 "Move back to the containing preprocessor conditional, including `#else'.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1191 Just like `c-up-conditional', except it also stops at `#else'
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1192 directives."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1193 (interactive "p")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1194 (c-forward-conditional (- count) -1 t)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1195 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1196
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1197 (defun c-down-conditional (count)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1198 "Move forward into the next preprocessor conditional, leaving mark behind.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1199 A prefix argument acts as a repeat count. With a negative argument,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1200 move backward into the previous preprocessor conditional.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1201
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1202 `#elif' is treated like `#else' followed by `#if', so the function
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1203 stops at them when going forward, but not when going backward."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1204 (interactive "p")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1205 (c-forward-conditional count 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1206 (c-keep-region-active))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1207
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1208 (defun c-down-conditional-with-else (count)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1209 "Move forward into the next preprocessor conditional, including `#else'.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1210 Just like `c-down-conditional', except it also stops at `#else'
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1211 directives."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1212 (interactive "p")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1213 (c-forward-conditional count 1 t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1214 (c-keep-region-active))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1215
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1216 (defun c-backward-conditional (count &optional target-depth with-else)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1217 "Move back across a preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1218 A prefix argument acts as a repeat count. With a negative argument,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1219 move forward across a preprocessor conditional."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1220 (interactive "p")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1221 (c-forward-conditional (- count) target-depth with-else)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1222 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1223
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1224 (defun c-forward-conditional (count &optional target-depth with-else)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1225 "Move forward across a preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1226 A prefix argument acts as a repeat count. With a negative argument,
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1227 move backward across a preprocessor conditional.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1228
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1229 `#elif' is treated like `#else' followed by `#if', except that the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1230 nesting level isn't changed when tracking subconditionals.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1231
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1232 The optional argument TARGET-DEPTH specifies the wanted nesting depth
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1233 after each scan. I.e. if TARGET-DEPTH is -1, the function will move
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1234 out of the enclosing conditional. A non-integer non-nil TARGET-DEPTH
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1235 counts as -1.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1236
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1237 If the optional argument WITH-ELSE is non-nil, `#else' directives are
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1238 treated as conditional clause limits. Normally they are ignored."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1239 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1240 (let* ((forward (> count 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1241 (increment (if forward -1 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1242 (search-function (if forward 're-search-forward 're-search-backward))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1243 (new))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1244 (unless (integerp target-depth)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1245 (setq target-depth (if target-depth -1 0)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1246 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1247 (while (/= count 0)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1248 (let ((depth 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1249 ;; subdepth is the depth in "uninteresting" subtrees,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1250 ;; i.e. those that takes us farther from the target
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1251 ;; depth instead of closer.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1252 (subdepth 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1253 found)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1254 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1255 ;; Find the "next" significant line in the proper direction.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1256 (while (and (not found)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1257 ;; Rather than searching for a # sign that
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1258 ;; comes at the beginning of a line aside from
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1259 ;; whitespace, search first for a string
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1260 ;; starting with # sign. Then verify what
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1261 ;; precedes it. This is faster on account of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1262 ;; the fastmap feature of the regexp matcher.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1263 (funcall search-function
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1264 "#[ \t]*\\(if\\|elif\\|endif\\|else\\)"
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1265 nil t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1266 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1267 ;; Now verify it is really a preproc line.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1268 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\|else\\)")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1269 (let (dchange (directive (match-string 1)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1270 (cond ((string= directive "if")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1271 (setq dchange (- increment)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1272 ((string= directive "endif")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1273 (setq dchange increment))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1274 ((= subdepth 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1275 ;; When we're not in an "uninteresting"
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1276 ;; subtree, we might want to act on "elif"
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1277 ;; and "else" too.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1278 (if (cond (with-else
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1279 ;; Always move toward the target depth.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1280 (setq dchange
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1281 (if (> target-depth 0) 1 -1)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1282 ((string= directive "elif")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1283 (setq dchange (- increment))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1284 ;; Ignore the change if it'd take us
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1285 ;; into an "uninteresting" subtree.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1286 (if (eq (> dchange 0) (<= target-depth 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1287 (setq dchange nil)))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1288 (when dchange
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1289 (when (or (/= subdepth 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1290 (eq (> dchange 0) (<= target-depth 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1291 (setq subdepth (+ subdepth dchange)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1292 (setq depth (+ depth dchange))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1293 ;; If we are trying to move across, and we find an
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1294 ;; end before we find a beginning, get an error.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1295 (if (and (< depth target-depth) (< dchange 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1296 (error (if forward
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1297 "No following conditional at this level"
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1298 "No previous conditional at this level"))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1299 ;; When searching forward, start from next line so
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1300 ;; that we don't find the same line again.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1301 (if forward (forward-line 1))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1302 ;; We found something if we've arrived at the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1303 ;; target depth.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1304 (if (and dchange (= depth target-depth))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1305 (setq found (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1306 ;; else
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1307 (if forward (forward-line 1)))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1308 (or found
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1309 (error "No containing preprocessor conditional"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1310 (goto-char (setq new found)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1311 (setq count (+ count increment))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1312 (push-mark)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1313 (goto-char new))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1314 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1315
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1316
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1317 ;; commands to indent lines, regions, defuns, and expressions
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1318 (defun c-indent-command (&optional arg)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1319 "Indent current line as C code, and/or insert some whitespace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1320
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1321 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
1322 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
1323 in the line's indentation; otherwise insert some whitespace[*]. If
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1324 other than nil or t, then some whitespace[*] is inserted only within
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1325 literals (comments and strings) and inside preprocessor directives,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1326 but the line is always reindented.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1327
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1328 If `c-syntactic-indentation' is t, indentation is done according to
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1329 the syntactic context. If it's nil, the line is just indented one
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1330 step according to `c-basic-offset'. In this mode, a numeric argument
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1331 indents a number of such steps, positive or negative, and an empty
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1332 prefix argument is equivalent to -1.
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1333
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1334 If `c-syntactic-indentation' is t, then a numeric argument, regardless
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1335 of its value, means indent rigidly all the lines of the expression
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1336 starting after point so that this line becomes properly indented. The
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1337 relative indentation among the lines of the expression is preserved.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1338
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1339 [*] The amount and kind of whitespace inserted is controlled by the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1340 variable `c-insert-tab-function', which is called to do the actual
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1341 insertion of whitespace. Normally the function in this variable
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1342 just inserts a tab character, or the equivalent number of spaces,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1343 depending on the variable `indent-tabs-mode'."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1344
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1345 (interactive "p")
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1346 (let ((bod (c-point 'bod))
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1347 (indent-function
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1348 (if c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1349 (symbol-function 'c-indent-line)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1350 (lambda ()
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1351 (let ((steps (cond ((not current-prefix-arg) 1)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1352 ((equal current-prefix-arg '(4)) -1)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1353 (t arg))))
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1354 (c-shift-line-indentation (* steps c-basic-offset)))
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1355 ))))
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1356 (if (and c-syntactic-indentation current-prefix-arg)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1357 ;; If c-syntactic-indentation and got arg, always indent this
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1358 ;; line as C and shift remaining lines of expression the same
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1359 ;; amount.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1360 (let ((shift-amt (c-indent-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1361 beg end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1362 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1363 (if (eq c-tab-always-indent t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1364 (beginning-of-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1365 (setq beg (point))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1366 (c-forward-sexp 1)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1367 (setq end (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1368 (goto-char beg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1369 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1370 (setq beg (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1371 (if (> end beg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1372 (indent-code-rigidly beg end (- shift-amt) "#")))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1373 ;; Else use c-tab-always-indent to determine behavior.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1374 (cond
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1375 ;; CASE 1: indent when at column zero or in lines indentation,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1376 ;; otherwise insert a tab
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1377 ((not c-tab-always-indent)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1378 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1379 (skip-chars-backward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1380 (not (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1381 (funcall c-insert-tab-function)
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1382 (funcall indent-function)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1383 ;; CASE 2: just indent the line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1384 ((eq c-tab-always-indent t)
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1385 (funcall indent-function))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1386 ;; 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
1387 ;; line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1388 (t
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1389 (if (c-in-literal bod)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1390 (funcall c-insert-tab-function))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1391 (funcall indent-function)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1392 )))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1393
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1394 (defun c-indent-exp (&optional shutup-p)
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1395 "Indent each line in balanced expression following point syntactically.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1396 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
1397 (interactive "*P")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1398 (let ((here (point-marker))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1399 end progress-p)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1400 (set-marker-insertion-type here t)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1401 (unwind-protect
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1402 (let ((c-echo-syntactic-information-p nil) ;keep quiet for speed
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1403 (start (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1404 ;; try to be smarter about finding the range of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1405 ;; lines to indent. skip all following
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1406 ;; whitespace. failing that, try to find any
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1407 ;; opening brace on the current line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1408 (skip-chars-forward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1409 (if (memq (char-after) '(?\( ?\[ ?\{))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1410 (point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1411 (let ((state (parse-partial-sexp (point)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1412 (c-point 'eol))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1413 (and (nth 1 state)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1414 (goto-char (nth 1 state))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1415 (memq (char-after) '(?\( ?\[ ?\{))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1416 (point)))))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1417 ;; find balanced expression end
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1418 (setq end (and (c-safe (progn (c-forward-sexp 1) t))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1419 (point-marker)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1420 ;; sanity check
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1421 (and (not start)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1422 (not shutup-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1423 (error "Cannot find start of balanced expression to indent."))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1424 (and (not end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1425 (not shutup-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1426 (error "Cannot find end of balanced expression to indent."))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1427 (c-progress-init start end 'c-indent-exp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1428 (setq progress-p t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1429 (goto-char start)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1430 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1431 (while (< (point) end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1432 (if (not (looking-at "[ \t]*$"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1433 (c-indent-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1434 (c-progress-update)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1435 (forward-line 1)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1436 ;; make sure marker is deleted
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1437 (and end
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1438 (set-marker end nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1439 (and progress-p
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1440 (c-progress-fini 'c-indent-exp))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1441 (goto-char here)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1442 (set-marker here nil))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1443
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1444 (defun c-indent-defun ()
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1445 "Re-indents the current top-level function def, struct or class declaration
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1446 syntactically."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1447 (interactive "*")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1448 (let ((here (point-marker))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1449 (c-echo-syntactic-information-p nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1450 (brace (c-least-enclosing-brace (c-parse-state))))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1451 (goto-char (or brace (c-point 'bod)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1452 ;; 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
1453 ;; least enclosing brace and we were sitting on the defun's open
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1454 ;; brace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1455 (if (and (bobp) (not (eq (char-after) ?\{)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1456 (goto-char here))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1457 ;; 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
1458 ;; the open brace. I consider this an Emacs bug.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1459 (and (boundp 'defun-prompt-regexp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1460 defun-prompt-regexp
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1461 (looking-at defun-prompt-regexp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1462 (goto-char (match-end 0)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1463 ;; 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
1464 ;; meaningful error message, and 2. restore point
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1465 (unwind-protect
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1466 (c-indent-exp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1467 (goto-char here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1468 (set-marker here nil))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1469
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1470 (defun c-indent-region (start end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1471 ;; Indent every line whose first char is between START and END inclusive.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1472 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1473 (goto-char start)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1474 ;; Advance to first nonblank line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1475 (skip-chars-forward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1476 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1477 (let (endmark)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1478 (unwind-protect
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1479 (let ((c-tab-always-indent t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1480 ;; shut up any echo msgs on indiv lines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1481 (c-echo-syntactic-information-p nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1482 fence)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1483 (c-progress-init start end 'c-indent-region)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1484 (setq endmark (copy-marker end))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1485 (while (and (bolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1486 (not (eobp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1487 (< (point) endmark))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1488 ;; update progress
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1489 (c-progress-update)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1490 ;; Indent one line as with TAB.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1491 (let (nextline sexpend sexpbeg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1492 ;; skip blank lines
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1493 (skip-chars-forward " \t\n")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1494 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1495 ;; indent the current line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1496 (c-indent-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1497 (setq fence (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1498 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1499 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1500 (looking-at "[ \t]*#"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1501 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1502 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1503 ;; Find beginning of following line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1504 (setq nextline (c-point 'bonl))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1505 ;; Find first beginning-of-sexp for sexp extending past
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1506 ;; this line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1507 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1508 (while (< (point) nextline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1509 (condition-case nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1510 (progn
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1511 (c-forward-sexp 1)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1512 (setq sexpend (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1513 (error (setq sexpend nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1514 (goto-char nextline)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1515 (c-forward-syntactic-ws))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1516 (if sexpend
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1517 (progn
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1518 ;; make sure the sexp we found really starts on the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1519 ;; current line and extends past it
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1520 (goto-char sexpend)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1521 (setq sexpend (point-marker))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1522 (c-safe (c-backward-sexp 1))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1523 (setq sexpbeg (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1524 (if (and sexpbeg (< sexpbeg fence))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1525 (setq sexpbeg fence)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1526 ;; Since we move by sexps we might have missed
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1527 ;; comment-only lines.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1528 (if sexpbeg
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1529 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1530 (while (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1531 (forward-line 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1532 (skip-chars-forward " \t")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1533 (< (point) sexpbeg))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1534 (if (looking-at c-comment-start-regexp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1535 (setq sexpbeg (c-point 'bol))))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1536 ;; If that sexp ends within the region, indent it all at
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1537 ;; once, fast.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1538 (condition-case nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1539 (if (and sexpend
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1540 (> sexpend nextline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1541 (<= sexpend endmark))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1542 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1543 (goto-char sexpbeg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1544 (c-indent-exp 'shutup)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1545 (c-progress-update)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1546 (goto-char sexpend)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1547 (error
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1548 (goto-char sexpbeg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1549 (c-indent-line)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1550 ;; Move to following line and try again.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1551 (and sexpend
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1552 (markerp sexpend)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1553 (set-marker sexpend nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1554 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1555 (setq fence (point))))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1556 (set-marker endmark nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1557 (c-progress-fini 'c-indent-region)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1558 (c-echo-parsing-error)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1559 ))))
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 (defun c-mark-function ()
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1562 "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
1563 (interactive)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1564 (let ((here (point))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1565 (eod (c-point 'eod))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1566 (state (c-parse-state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1567 ;; 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
1568 ;; 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
1569 ;; 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
1570 ;; 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
1571 ;; mark the entire defun we're sitting on.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1572 ;;
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1573 ;; 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
1574 ;; just mark the statement that we're on
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1575 (if (or (and (consp (car state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1576 (= (length state) 1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1577 (null state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1578 ;; 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
1579 (if (and state
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1580 (looking-at "[ \t]*$")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1581 (= (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1582 (c-backward-syntactic-ws)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1583 (skip-chars-backward ";")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1584 (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1585 (cdar state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1586 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1587 (setq eod (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1588 (goto-char (caar state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1589 (c-beginning-of-statement-1))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1590 (if (= ?{ (save-excursion
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1591 (c-end-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1592 (char-before)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1593 ;; We must be in a defuns's introduction
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1594 (progn
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1595 (c-end-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1596 (skip-chars-backward "{")
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1597 (c-beginning-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1598 (c-forward-syntactic-ws))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1599 ;; Just mark the statement
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1600 (c-end-of-statement-1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1601 (forward-line 1)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1602 (setq eod (point))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1603 (c-beginning-of-statement-1)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1604 ;; 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
1605 ;; 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
1606 ;; 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
1607 ;; 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
1608 (while (and state)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1609 (or (consp (car state))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1610 (goto-char (car state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1611 (setq state (cdr state)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1612 (c-beginning-of-statement-1))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1613 (push-mark here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1614 (push-mark eod nil t)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1615
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1616 (defun c-indent-line-or-region ()
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1617 "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
1618 ;; 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
1619 (interactive)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1620 (if (c-region-is-active-p)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1621 (c-indent-region (region-beginning) (region-end))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1622 (c-indent-command)))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1623
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1624
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1625 ;; for progress reporting
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1626 (defvar c-progress-info nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1627
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1628 (defun c-progress-init (start end context)
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1629 (cond
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1630 ;; Be silent
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1631 ((not c-progress-interval))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1632 ;; 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
1633 ;; 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
1634 ((not (fboundp 'current-time))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1635 (message "indenting region... (this may take a while)"))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1636 ;; 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
1637 ;; initialize the counter with a vector of:
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1638 ;; [start end lastsec context]
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1639 (c-progress-info)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1640 (t (setq c-progress-info (vector start
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1641 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1642 (goto-char end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1643 (point-marker))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1644 (nth 1 (current-time))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1645 context))
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1646 (message "indenting region..."))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1647 ))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1648
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1649 (defun c-progress-update ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1650 ;; update progress
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1651 (if (not (and c-progress-info c-progress-interval))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1652 nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1653 (let ((now (nth 1 (current-time)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1654 (start (aref c-progress-info 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1655 (end (aref c-progress-info 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1656 (lastsecs (aref c-progress-info 2)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1657 ;; should we update? currently, update happens every 2 seconds,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1658 ;; what's the right value?
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1659 (if (< c-progress-interval (- now lastsecs))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1660 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1661 (message "indenting region... (%d%% complete)"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1662 (/ (* 100 (- (point) start)) (- end start)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1663 (aset c-progress-info 2 now)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1664 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1665
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1666 (defun c-progress-fini (context)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1667 ;; finished
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1668 (if (not c-progress-interval)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1669 nil
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1670 (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
1671 (eq context t))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1672 (progn
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1673 (set-marker (aref c-progress-info 1) nil)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1674 (setq c-progress-info nil)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
1675 (message "indenting region...done")))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1676
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1677
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1678
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1679 ;;; This page handles insertion and removal of backslashes for C macros.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1680
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1681 (defun c-backslash-region (from to delete-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1682 "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
1683 With no argument, inserts backslashes and aligns existing backslashes.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1684 With an argument, deletes the backslashes.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1685
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1686 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
1687 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
1688 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
1689
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1690 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
1691 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
1692 (interactive "*r\nP")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1693 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1694 (goto-char from)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1695 (let ((column c-backslash-column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1696 (endmark (make-marker)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1697 (move-marker endmark to)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1698 ;; Compute the smallest column number past the ends of all the lines.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1699 (if (not delete-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1700 (while (< (point) to)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1701 (end-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1702 (if (eq (char-before) ?\\)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1703 (progn (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1704 (skip-chars-backward " \t")))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1705 (setq column (max column (1+ (current-column))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1706 (forward-line 1)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1707 ;; 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
1708 (if (> (% column tab-width) 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1709 (let ((adjusted (* (/ (+ column tab-width -1) tab-width) tab-width)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1710 (if (< adjusted (window-width))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1711 (setq column adjusted))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1712 ;; Don't modify blank lines at start of region.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1713 (goto-char from)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1714 (while (and (< (point) endmark) (eolp))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1715 (forward-line 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1716 ;; Add or remove backslashes on all the lines.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1717 (while (< (point) endmark)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1718 (if (and (not delete-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1719 ;; Un-backslashify the last line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1720 ;; if the region ends right at the start of the next line.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1721 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1722 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1723 (< (point) endmark)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1724 (c-append-backslash column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1725 (c-delete-backslash))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1726 (forward-line 1))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1727 (move-marker endmark nil))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1728
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1729 (defun c-append-backslash (column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1730 (end-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1731 (if (eq (char-before) ?\\)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1732 (progn (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1733 (delete-horizontal-space)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1734 (indent-to column))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1735 (indent-to column)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1736 (insert "\\")))
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 (defun c-delete-backslash ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1739 (end-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1740 (or (bolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1741 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1742 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1743 (if (looking-at "\\\\")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1744 (delete-region (1+ (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1745 (progn (skip-chars-backward " \t") (point)))))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1746
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1747
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1748
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1749 ;;; Line breaking and paragraph filling.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1750
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1751 ;; The filling code is based on a simple theory; leave the intricacies
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1752 ;; of the text handling to the currently active mode for that
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1753 ;; (e.g. adaptive-fill-mode or filladapt-mode) and do as little as
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1754 ;; possible to make them work correctly wrt the comment and string
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1755 ;; separators, one-line paragraphs etc. Unfortunately, when it comes
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1756 ;; to it, there's quite a lot of special cases to handle which makes
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1757 ;; the code anything but simple. The intention is that it will work
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1758 ;; with any well-written text filling package that preserves a fill
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1759 ;; prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1760 ;;
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1761 ;; We temporarily mask comment starters and enders as necessary for
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1762 ;; the filling code to do its job on a seemingly normal text block.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1763 ;; We do _not_ mask the fill prefix, so it's up to the filling code to
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1764 ;; preserve it correctly (especially important when filling C++ style
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1765 ;; line comments). By default, we set up and use adaptive-fill-mode,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1766 ;; which is standard in all supported Emacs flavors.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1767
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1768 (defun c-guess-fill-prefix (lit-limits lit-type)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1769 ;; Determine the appropriate comment fill prefix for a block or line
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1770 ;; comment. Return a cons of the prefix string and the column where
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1771 ;; it ends. If fill-prefix is set, it'll override. Note that this
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1772 ;; function also uses the value of point in some heuristics.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1773 (let* ((here (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1774 (prefix-regexp (concat "[ \t]*\\("
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1775 c-comment-prefix-regexp
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1776 "\\)[ \t]*"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1777 (comment-start-regexp (if (eq lit-type 'c++)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1778 prefix-regexp
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1779 comment-start-skip))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1780 prefix-line comment-prefix res)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1781 (cond
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1782 (fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1783 (setq res (cons fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1784 ;; Ugly way of getting the column after the fill
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1785 ;; prefix; it'd be nice with a current-column
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1786 ;; that works on strings..
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1787 (let ((buffer-modified (buffer-modified-p))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1788 (buffer-undo-list t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1789 (start (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1790 (unwind-protect
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1791 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1792 (insert ?\n fill-prefix)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1793 (current-column))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1794 (delete-region start (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1795 (set-buffer-modified-p buffer-modified))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1796 ((eq lit-type 'c++)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1797 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1798 ;; Set fallback for comment-prefix if none is found.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1799 (setq comment-prefix "// ")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1800 (beginning-of-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1801 (if (> (point) (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1802 ;; The current line is not the comment starter, so the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1803 ;; comment has more than one line, and it can therefore be
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1804 ;; used to find the comment fill prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1805 (setq prefix-line (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1806 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1807 (if (and (= (forward-line 1) 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1808 (< (point) (cdr lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1809 ;; The line after the comment starter is inside the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1810 ;; comment, so we can use it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1811 (setq prefix-line (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1812 ;; The comment is only one line. Take the comment prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1813 ;; from it and keep the indentation.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1814 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1815 (if (looking-at prefix-regexp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1816 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1817 (forward-char 2)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1818 (skip-chars-forward " \t"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1819 (setq res
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1820 (if (eq (c-point 'boi) (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1821 ;; There is only whitespace before the comment
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1822 ;; starter; take the prefix straight from this
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1823 ;; line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1824 (cons (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1825 (c-point 'bol) (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1826 (current-column))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1827 ;; There is code before the comment starter, so we
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1828 ;; have to temporarily insert and indent a new
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1829 ;; line to get the right space/tab mix in the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1830 ;; indentation.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1831 (let ((buffer-modified (buffer-modified-p))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1832 (buffer-undo-list t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1833 (prefix-len (- (point) (car lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1834 tmp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1835 (unwind-protect
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1836 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1837 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1838 (indent-to (prog1 (current-column)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1839 (insert ?\n)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1840 (setq tmp (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1841 (forward-char prefix-len)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1842 (cons (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1843 (c-point 'bol) (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1844 (current-column)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1845 (delete-region (car lit-limits) tmp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1846 (set-buffer-modified-p buffer-modified))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1847 )))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1848 (t
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1849 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1850 (beginning-of-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1851 (if (and (> (point) (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1852 (not (and (looking-at "[ \t]*\\*/")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1853 (eq (cdr lit-limits) (match-end 0)))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1854 ;; The current line is not the comment starter and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1855 ;; contains more than just the ender, so it's good enough
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1856 ;; to be used for the comment fill prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1857 (setq prefix-line (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1858 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1859 (if (or (/= (forward-line 1) 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1860 (>= (point) (cdr lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1861 (and (looking-at "[ \t]*\\*/")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1862 (eq (cdr lit-limits) (match-end 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1863 (and (looking-at prefix-regexp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1864 (<= (1- (cdr lit-limits)) (match-end 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1865 (and (< here (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1866 (or (not (match-beginning 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1867 (looking-at "[ \t]*$"))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1868 ;; The comment is either one line or the next line
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1869 ;; contains just the comment ender. Also, if point is
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1870 ;; on the comment opener line and the following line is
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1871 ;; empty or doesn't match c-comment-prefix-regexp we
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1872 ;; assume that this is in fact a not yet closed one line
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1873 ;; comment, so we shouldn't look for the comment prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1874 ;; on the next line. In these cases we have no
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1875 ;; information about a suitable comment prefix, so we
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1876 ;; resort to c-block-comment-prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1877 (setq comment-prefix (or c-block-comment-prefix "")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1878 res (let ((buffer-modified (buffer-modified-p))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1879 (buffer-undo-list t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1880 tmp-pre tmp-post)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1881 ;; The comment doesn't give any information
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1882 ;; about the indentation column. We'll have to
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1883 ;; temporarily insert a new comment line and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1884 ;; indent it to find the correct column.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1885 (unwind-protect
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1886 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1887 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1888 (if (looking-at comment-start-regexp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1889 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1890 (forward-char 2)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1891 (skip-chars-forward " \t"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1892 (when (eq (char-syntax (char-before)) ?\ )
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1893 ;; If there's ws on the current
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1894 ;; line, we'll use it instead of
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1895 ;; what's ending comment-prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1896 (setq comment-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1897 (concat (substring comment-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1898 0 (string-match
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1899 "\\s *\\'"
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1900 comment-prefix))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1901 (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1902 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1903 (skip-chars-backward " \t")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1904 (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1905 (point)))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1906 (setq tmp-pre (point-marker))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1907 ;; We insert an extra non-whitespace
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1908 ;; character before the line break and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1909 ;; after comment-prefix in case it's
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1910 ;; "" or ends with whitespace.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1911 (insert "x\n" comment-prefix ?x)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1912 (setq tmp-post (point-marker))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1913 (c-indent-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1914 (goto-char (1- tmp-post))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1915 (cons (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1916 (c-point 'bol) (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1917 (current-column)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1918 (when tmp-post
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1919 (delete-region tmp-pre tmp-post)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1920 (set-marker tmp-pre nil)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1921 (set-marker tmp-post nil))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1922 (set-buffer-modified-p buffer-modified))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1923 ;; Otherwise the line after the comment starter is good
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1924 ;; enough to find the prefix in.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1925 (setq prefix-line (point)))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1926 (or res
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1927 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1928 ;; prefix-line is the bol of a line on which we should try
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1929 ;; to find the prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1930 (let* (fb-string fb-endpos ; Contains any fallback prefix found.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1931 (test-line
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1932 (lambda ()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1933 (when (and (looking-at prefix-regexp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1934 (< (match-end 0) (1- (cdr lit-limits))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1935 (unless fb-string
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1936 (setq fb-string (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1937 (match-beginning 0) (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1938 fb-endpos (match-end 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1939 (unless (eq (match-end 0) (c-point 'eol))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1940 (throw 'found t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1941 t))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1942 (if (catch 'found
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1943 ;; Search for a line which has text after the prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1944 ;; so that we get the proper amount of whitespace
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1945 ;; after it. We start with the current line, then
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1946 ;; search backwards, then forwards.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1947 (goto-char prefix-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1948 (when (and (funcall test-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1949 (/= (match-end 1) (match-end 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1950 ;; If the current line doesn't have text but do
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1951 ;; have whitespace after the prefix, we'll use it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1952 (throw 'found t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1953 (while (and (zerop (forward-line -1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1954 (> (point) (car lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1955 (funcall test-line))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1956 (goto-char prefix-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1957 (while (and (zerop (forward-line 1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1958 (< (point) (cdr lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1959 (funcall test-line))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1960 nil)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1961 ;; A good line with text after the prefix was found.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1962 (cons (buffer-substring-no-properties (point) (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1963 (progn (goto-char (match-end 0)) (current-column)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1964 (if fb-string
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1965 ;; A good line wasn't found, but at least we have a
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1966 ;; fallback that matches the comment prefix regexp.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1967 (cond ((string-match "\\s \\'" fb-string)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1968 ;; There are ws after the prefix, so let's use it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1969 (cons fb-string
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1970 (progn (goto-char fb-endpos) (current-column))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1971 ((progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1972 ;; Check if there's any whitespace padding
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1973 ;; on the comment start line that we can
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1974 ;; use after the prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1975 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1976 (if (looking-at comment-start-regexp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1977 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1978 (forward-char 2)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1979 (skip-chars-forward " \t"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1980 (eq (char-syntax (char-before)) ?\ ))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1981 (setq fb-string (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1982 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1983 (skip-chars-backward " \t")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1984 (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1985 (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1986 (goto-char fb-endpos)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1987 (skip-chars-backward " \t")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1988 (let ((buffer-modified (buffer-modified-p))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1989 (buffer-undo-list t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1990 (tmp (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1991 ;; Got to mess in the buffer once again to
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1992 ;; ensure the column gets correct. :P
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1993 (unwind-protect
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1994 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1995 (insert fb-string)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1996 (cons (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1997 (c-point 'bol)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1998 (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1999 (current-column)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2000 (delete-region tmp (point)))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2001 (t
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2002 ;; Last resort: Just add a single space after
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2003 ;; the prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2004 (cons (concat fb-string " ")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2005 (progn (goto-char fb-endpos)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2006 (1+ (current-column))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2007 ;; The line doesn't match the comment prefix regexp.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2008 (if comment-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2009 ;; We have a fallback for line comments that we must use.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2010 (cons (concat (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2011 prefix-line (c-point 'boi))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2012 comment-prefix)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2013 (progn (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2014 (+ (current-column) (length comment-prefix))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2015 ;; Assume we are dealing with a "free text" block
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2016 ;; comment where the lines doesn't have any comment
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2017 ;; prefix at all and we should just fill it as
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2018 ;; normal text.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2019 '("" . 0)))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2020 ))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2021
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2022 (defun c-fill-paragraph (&optional arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2023 "Like \\[fill-paragraph] but handles C and C++ style comments.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2024 If any of the current line is a comment or within a comment, fill the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2025 comment or the paragraph of it that point is in, preserving the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2026 comment indentation or line-starting decorations (see the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2027 `c-comment-prefix-regexp' and `c-block-comment-prefix' variables for
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2028 details).
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2029
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
2030 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
2031 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
2032 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
2033 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
2034
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
2035 char description[] = \"\\
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
2036 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
2037 nicely formatted output.\"\;
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
2038
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
2039 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
2040
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2041 Optional prefix ARG means justify paragraph as well."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
2042 (interactive "*P")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2043 (let (lit-limits lit-type fill
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2044 ;; beg and end limits the region to be filled. end is a marker.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2045 beg end
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2046 ;; tmp-pre and tmp-post marks strings that are temporarily
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2047 ;; inserted at the start and end of the region. tmp-pre is a
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2048 ;; cons of the positions of the prepended string. tmp-post is
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2049 ;; a marker pointing to the single character of the appended
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2050 ;; string.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2051 tmp-pre tmp-post
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2052 hang-ender-stuck)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2053 ;; Restore point on undo. It's necessary since we do a lot of
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2054 ;; hidden inserts and deletes below that should be as transparent
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2055 ;; as possible.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2056 (if (and buffer-undo-list (not (eq buffer-undo-list t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2057 (setq buffer-undo-list (cons (point) buffer-undo-list)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2058 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2059 (save-restriction
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2060 ;; Widen to catch comment limits correctly.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2061 (widen)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2062 (setq lit-limits (c-collect-line-comments (c-literal-limits nil t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2063 lit-type (c-literal-type lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2064 (forward-paragraph)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2065 (setq end (point-marker))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2066 (backward-paragraph)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2067 (setq beg (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2068 (when (and (>= (point) beg) (<= (point) end))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2069 (unwind-protect
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2070 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2071 (cond
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2072 ((eq lit-type 'c++) ; Line comment.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2073 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2074 ;; Fill to the comment or paragraph end, whichever
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2075 ;; comes first.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2076 (set-marker end (min end (cdr lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2077 (when (<= beg (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2078 ;; The region to be filled includes the comment
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2079 ;; starter, so we must check it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2080 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2081 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2082 (if (eq (point) (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2083 ;; Include the first line in the fill.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2084 (setq beg (c-point 'bol))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2085 ;; The first line contains code before the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2086 ;; comment. We must fake a line that doesn't.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2087 (setq tmp-pre t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2088 ))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2089 ((eq lit-type 'c) ; Block comment.
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
2090 (save-excursion
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2091 (when (>= end (cdr lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2092 ;; The region to be filled includes the comment ender.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2093 (goto-char (cdr lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2094 (beginning-of-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2095 (if (and (looking-at (concat "[ \t]*\\("
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2096 c-comment-prefix-regexp
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2097 "\\)\\*/"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2098 (eq (cdr lit-limits) (match-end 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2099 ;; Leave the comment ender on its own line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2100 (set-marker end (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2101 ;; The comment ender should hang. Replace all
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2102 ;; cruft between it and the last word with a 'x'
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2103 ;; and include it in the fill. We'll change it
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2104 ;; back to a space afterwards.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2105 (let ((ender-start (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2106 (goto-char (cdr lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2107 (skip-syntax-backward "^w ")
27111
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2108 (point)))
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2109 spaces)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2110 (goto-char (cdr lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2111 (setq tmp-post (point-marker))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2112 (insert ?\n)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2113 (set-marker end (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2114 (forward-line -1)
27111
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2115 (if (and (looking-at (concat "[ \t]*\\(\\("
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2116 c-comment-prefix-regexp
27111
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2117 "\\)[ \t]*\\)"))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2118 (eq ender-start (match-end 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2119 ;; The comment ender is prefixed by nothing
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2120 ;; but a comment line prefix. Remove it
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2121 ;; along with surrounding ws.
27111
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2122 (setq spaces (- (match-end 1) (match-end 2)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2123 (goto-char ender-start))
27111
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2124 (skip-chars-backward " \t\r\n")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2125 (when (/= (point) ender-start)
27111
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2126 ;; Keep one or two spaces between the text and
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2127 ;; the ender, depending on how many there are now.
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2128 (unless spaces (setq spaces (- ender-start (point))))
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2129 (setq spaces (max (min spaces 2) 1))
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2130 ; Insert the filler first to keep marks right.
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2131 (insert (make-string spaces ?x))
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2132 (delete-region (point) (+ ender-start spaces))
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2133 (setq hang-ender-stuck spaces)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2134 (when (<= beg (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2135 ;; The region to be filled includes the comment starter.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2136 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2137 (if (looking-at (concat "\\(" comment-start-skip "\\)$"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2138 ;; Begin filling with the next line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2139 (setq beg (c-point 'bonl))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2140 ;; Fake the fill prefix in the first line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2141 (setq tmp-pre t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2142 ))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2143 ((eq lit-type 'string) ; String.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2144 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2145 (when (>= end (cdr lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2146 (goto-char (1- (cdr lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2147 (setq tmp-post (point-marker))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2148 (insert ?\n)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2149 (set-marker end (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2150 (when (<= beg (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2151 (goto-char (1+ (car lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2152 (setq beg (if (looking-at "\\\\$")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2153 ;; Leave the start line if it's
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2154 ;; nothing but an escaped newline.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2155 (1+ (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2156 (point))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2157 (t (setq beg nil)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2158 (when tmp-pre
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2159 ;; Temporarily insert the fill prefix after the comment
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2160 ;; starter so that the first line looks like any other
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2161 ;; comment line in the narrowed region.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2162 (setq fill (c-guess-fill-prefix lit-limits lit-type))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2163 (unless (string-match (concat "\\`[ \t]*\\("
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2164 c-comment-prefix-regexp
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2165 "\\)[ \t]*\\'")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2166 (car fill))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2167 ;; Oops, the prefix doesn't match the comment prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2168 ;; regexp. This could produce very confusing
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2169 ;; results with adaptive fill packages together with
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2170 ;; the insert prefix magic below, since the prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2171 ;; often doesn't appear at all. So let's warn about
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2172 ;; it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2173 (message "\
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2174 Warning: `c-comment-prefix-regexp' doesn't match the comment prefix %S"
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2175 (car fill)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2176 ;; Find the right spot on the line, break it, insert
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2177 ;; the fill prefix and make sure we're back in the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2178 ;; same column by temporarily prefixing the first word
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2179 ;; with a number of 'x'.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2180 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2181 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2182 (if (looking-at (if (eq lit-type 'c++)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2183 c-comment-prefix-regexp
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2184 comment-start-skip))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2185 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2186 (forward-char 2)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2187 (skip-chars-forward " \t"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2188 (while (< (current-column) (cdr fill)) (forward-char 1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2189 (let ((col (current-column)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2190 (setq beg (1+ (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2191 tmp-pre (list (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2192 (unwind-protect
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2193 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2194 (insert ?\n (car fill))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2195 (insert (make-string (- col (current-column)) ?x)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2196 (setcdr tmp-pre (point))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2197 (when beg
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2198 (let ((fill-paragraph-function
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2199 ;; Avoid infinite recursion.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2200 (if (not (eq fill-paragraph-function 'c-fill-paragraph))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2201 fill-paragraph-function))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2202 (fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2203 (or fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2204 (when (and (eq lit-type 'c++)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2205 (not (string-match
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2206 "\\`[ \t]*//"
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2207 (or (fill-context-prefix beg end)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2208 ""))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2209 ;; Kludge: If the function that adapts the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2210 ;; fill prefix doesn't produce the required
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2211 ;; comment starter for line comments, then
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2212 ;; force it by setting fill-prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2213 (car (or fill (c-guess-fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2214 lit-limits lit-type)))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2215 ;; Preparations finally done! Now we can call the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2216 ;; real fill function.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2217 (save-restriction
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2218 (narrow-to-region beg end)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2219 (fill-paragraph arg)))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2220 (when (consp tmp-pre)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2221 (delete-region (car tmp-pre) (cdr tmp-pre)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2222 (when tmp-post
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2223 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2224 (goto-char tmp-post)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2225 (delete-char 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2226 (when hang-ender-stuck
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2227 (skip-syntax-backward "^w ")
27111
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2228 (forward-char (- hang-ender-stuck))
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2229 (insert (make-string hang-ender-stuck ?\ ))
cad48fa4c22d (c-fill-paragraph): Count number of spaces
Gerd Moellmann <gerd@gnu.org>
parents: 27021
diff changeset
2230 (delete-char hang-ender-stuck))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2231 (set-marker tmp-post nil)))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2232 (set-marker end nil))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2233 ;; Always return t. This has the effect that if filling isn't done
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2234 ;; above, it isn't done at all, and it's therefore effectively
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2235 ;; disabled in normal code.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2236 t)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2237
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2238 (defun c-do-auto-fill ()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2239 ;; Do automatic filling if not inside a context where it should be
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2240 ;; ignored.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2241 (let ((c-auto-fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2242 ;; The decision whether the line should be broken is actually
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2243 ;; done in c-indent-new-comment-line, which do-auto-fill
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2244 ;; calls to break lines. We just set this special variable
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2245 ;; so that we'll know when we're called from there. It's
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2246 ;; also used to detect whether fill-prefix is user set or
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2247 ;; generated automatically by do-auto-fill.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2248 fill-prefix))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2249 (do-auto-fill)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2250
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2251 (defun c-indent-new-comment-line (&optional soft)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2252 "Break line at point and indent, continuing comment if within one.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2253 If inside a comment and `comment-multi-line' is non-nil, the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2254 indentation and line prefix are preserved (see the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2255 `c-comment-prefix-regexp' and `c-block-comment-prefix' variables for
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2256 details). If inside a single line comment and `comment-multi-line' is
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2257 nil, a new comment of the same type is started on the next line and
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2258 indented as appropriate for comments.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2259
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2260 If a fill prefix is specified, it overrides all the above."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2261 (interactive)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2262 (let ((fill-prefix fill-prefix)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2263 (do-line-break
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2264 (lambda ()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2265 (delete-region (progn (skip-chars-backward " \t") (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2266 (progn (skip-chars-forward " \t") (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2267 (if soft (insert-and-inherit ?\n) (newline 1))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2268 ;; Already know the literal type and limits when called from
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2269 ;; c-context-line-break.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2270 (c-lit-limits (if (boundp 'c-lit-limits) c-lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2271 (c-lit-type (if (boundp 'c-lit-type) c-lit-type)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2272 (when (boundp 'c-auto-fill-prefix)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2273 ;; Called from do-auto-fill.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2274 (unless c-lit-limits
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2275 (setq c-lit-limits (c-literal-limits nil nil t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2276 (unless c-lit-type
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2277 (setq c-lit-type (c-literal-type c-lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2278 (if (memq (cond ((eq c-lit-type 'pound)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2279 ;; Come to think about it, "pound" is a bit
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2280 ;; of a misnomer, so call it "cpp" instead
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2281 ;; in user interaction.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2282 'cpp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2283 ((null c-lit-type) 'code)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2284 (t c-lit-type))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2285 c-ignore-auto-fill)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2286 (setq fill-prefix t) ; Used as flag in the cond.
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2287 (if (and (null c-auto-fill-prefix)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2288 (eq c-lit-type 'c)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2289 (<= (c-point 'bol) (car c-lit-limits)))
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2290 ;; The adaptive fill function has generated a prefix, but
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2291 ;; we're on the first line in a block comment so it'll be
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2292 ;; wrong. Ignore it to guess a better one below.
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2293 (setq fill-prefix nil)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2294 (when (and (eq c-lit-type 'c++)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2295 (not (string-match "\\`[ \t]*//" (or fill-prefix ""))))
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2296 ;; Kludge: If the function that adapted the fill prefix
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2297 ;; doesn't produce the required comment starter for line
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2298 ;; comments, then we ignore it.
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2299 (setq fill-prefix nil)))
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2300 ))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2301 (cond ((eq fill-prefix t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2302 ;; A call from do-auto-fill which should be ignored.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2303 )
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2304 (fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2305 ;; A fill-prefix overrides anything.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2306 (funcall do-line-break)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2307 (insert-and-inherit fill-prefix))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2308 ((progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2309 (unless c-lit-limits
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2310 (setq c-lit-limits (c-literal-limits nil nil t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2311 (unless c-lit-type
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2312 (setq c-lit-type (c-literal-type c-lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2313 (memq c-lit-type '(c c++)))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2314 (if (or comment-multi-line
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2315 (save-excursion
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2316 (goto-char (car c-lit-limits))
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2317 (end-of-line)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2318 (< (point) (cdr c-lit-limits))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2319 ;; Inside a comment that should be continued.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2320 (let ((fill (c-guess-fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2321 (setq c-lit-limits
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2322 (c-collect-line-comments c-lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2323 c-lit-type))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2324 (pos (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2325 (if (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2326 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2327 (> (point) (car c-lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2328 (looking-at c-comment-prefix-regexp))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2329 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2330 ;; Skip forward past the fill prefix in case
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2331 ;; we're standing in it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2332 (while (and (< (current-column) (cdr fill))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2333 (not (eolp)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2334 (forward-char 1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2335 (if (> (point) (if (and (eq c-lit-type 'c)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2336 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2337 (forward-char -2)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2338 (looking-at "\\*/")))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2339 (- (cdr c-lit-limits) 2)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2340 (cdr c-lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2341 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2342 ;; The skip takes us out of the comment;
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2343 ;; insert the fill prefix at bol instead
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2344 ;; and keep the position.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2345 (setq pos (copy-marker pos t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2346 (beginning-of-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2347 (insert-and-inherit (car fill))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2348 (if soft (insert-and-inherit ?\n) (newline 1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2349 (goto-char pos)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2350 (set-marker pos nil))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2351 (funcall do-line-break)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2352 (insert-and-inherit (car fill))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2353 (funcall do-line-break)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2354 (insert-and-inherit (car fill))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2355 ;; Inside a comment that should be broken.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2356 (let ((comment-start comment-start)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2357 (comment-end comment-end)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2358 col)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2359 (if (eq c-lit-type 'c)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2360 (unless (string-match "[ \t]*/\\*" comment-start)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2361 (setq comment-start "/* " comment-end " */"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2362 (unless (string-match "[ \t]*//" comment-start)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2363 (setq comment-start "// " comment-end "")))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2364 (setq col (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2365 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2366 (current-column)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2367 (funcall do-line-break)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2368 (when (and comment-end (not (equal comment-end "")))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2369 (forward-char -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2370 (insert-and-inherit comment-end)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2371 (forward-char 1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2372 ;; c-comment-indent may look at the current
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2373 ;; indentation, so let's start out with the same
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2374 ;; indentation as the previous one.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2375 (indent-to col)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2376 (insert-and-inherit comment-start)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2377 (indent-for-comment))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2378 (t
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2379 ;; Somewhere else in the code.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2380 (let ((col (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2381 (while (progn (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2382 (and (looking-at "^\\s *$")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2383 (= (forward-line -1) 0))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2384 (current-column))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2385 (funcall do-line-break)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2386 (indent-to col))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2387
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2388 (defalias 'c-comment-line-break-function 'c-indent-new-comment-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2389 (make-obsolete 'c-comment-line-break-function 'c-indent-new-comment-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2390
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2391 ;; advice for indent-new-comment-line for older Emacsen
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2392 (unless (boundp 'comment-line-break-function)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2393 (defadvice indent-new-comment-line (around c-line-break-advice
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2394 activate preactivate)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2395 "Call `c-indent-new-comment-line' if in CC Mode."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2396 (if (or (boundp 'c-inside-line-break-advice)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2397 (not c-buffer-is-cc-mode))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2398 ad-do-it
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2399 (let (c-inside-line-break-advice)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2400 (c-indent-new-comment-line (ad-get-arg 0))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2401
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2402 (defun c-context-line-break ()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2403 "Do a line break suitable to the context.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2404
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2405 When point is outside a comment, insert a newline and indent according
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2406 to the syntactic context.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2407
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2408 When point is inside a comment, continue it with the appropriate
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2409 comment prefix (see the `c-comment-prefix-regexp' and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2410 `c-block-comment-prefix' variables for details). The end of a
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2411 C++-style line comment doesn't count as inside the comment, though."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2412 (interactive "*")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2413 (let* ((c-lit-limits (c-literal-limits nil nil t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2414 (c-lit-type (c-literal-type c-lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2415 (if (or (eq c-lit-type 'c)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2416 (and (eq c-lit-type 'c++)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2417 (< (point)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2418 (1- (cdr (setq c-lit-limits
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2419 (c-collect-line-comments c-lit-limits)))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2420 (let ((comment-multi-line t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2421 (fill-prefix nil))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2422 (c-indent-new-comment-line))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2423 (delete-region (point) (progn (skip-chars-backward " \t") (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2424 (newline)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2425 ;; c-indent-line may look at the current indentation, so let's
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2426 ;; start out with the same indentation as the previous line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2427 (let ((col (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2428 (forward-line -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2429 (while (progn (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2430 (and (looking-at "^\\s *$")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2431 (= (forward-line -1) 0))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2432 (current-column))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2433 (indent-to col))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2434 (c-indent-line))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2435
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2436
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2437 (provide 'cc-cmds)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2438 ;;; cc-cmds.el ends here