annotate lisp/progmodes/cc-cmds.el @ 44079:bf72a8fa9d17

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