annotate lisp/progmodes/cc-cmds.el @ 46827:cc564ceab7c2

(describe-function-1): Skip arglist note if function's definition is a keymap.
author John Paul Wallington <jpw@pobox.com>
date Tue, 06 Aug 2002 17:21:19 +0000
parents cb8f23e350ff
children 0d8b17d428b5
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
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
28 ;; along with GNU Emacs; see the file COPYING. If not, write to
36920
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
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
57 (defvar c-fix-backslashes t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
58
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
59 (defun c-shift-line-indentation (shift-amt)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
60 (let ((pos (- (point-max) (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
61 (c-macro-start c-macro-start)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
62 tmp-char-inserted)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
63 (if (zerop shift-amt)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
64 nil
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
65 (when (and (c-query-and-set-macro-start)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
66 (looking-at "[ \t]*\\\\$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
67 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
68 (skip-chars-backward " \t")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
69 (bolp)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
70 (insert ?x)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
71 (backward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
72 (setq tmp-char-inserted t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
73 (unwind-protect
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
74 (let ((col (current-indentation)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
75 (delete-region (c-point 'bol) (c-point 'boi))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
76 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
77 (indent-to (+ col shift-amt)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
78 (when tmp-char-inserted
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
79 (delete-char 1))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
80 ;; If initial point was within line's indentation and we're not on
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
81 ;; a line with a line continuation in a macro, position after the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
82 ;; indentation. Else stay at same point in text.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
83 (if (and (< (point) (c-point 'boi))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
84 (not tmp-char-inserted))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
85 (back-to-indentation)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
86 (if (> (- (point-max) pos) (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
87 (goto-char (- (point-max) pos))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
88
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
89 (defun c-indent-line (&optional syntax quiet ignore-point-pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
90 "Indent the current line according to the syntactic context,
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
91 if `c-syntactic-indentation' is non-nil. Optional SYNTAX is the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
92 syntactic information for the current line. Be silent about syntactic
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
93 errors if the optional argument QUIET is non-nil, even if
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
94 `c-report-syntactic-errors' is non-nil. Normally the position of
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
95 point is used to decide where the old indentation is on a lines that
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
96 is otherwise empty \(ignoring any line continuation backslash), but
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
97 that's not done if IGNORE-POINT-POS is non-nil. Returns the amount of
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
98 indentation change \(in columns)."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
99 (let ((line-cont-backslash (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
100 (end-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
101 (eq (char-before) ?\\)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
102 (c-fix-backslashes c-fix-backslashes)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
103 bs-col
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
104 shift-amt)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
105 (when (and (not ignore-point-pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
106 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
107 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
108 (looking-at (if line-cont-backslash
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
109 "\\(\\s *\\)\\\\$"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
110 "\\(\\s *\\)$")))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
111 (<= (point) (match-end 1)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
112 ;; Delete all whitespace after point if there's only whitespace
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
113 ;; on the line, so that any code that does back-to-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
114 ;; or similar gets the current column in this case. If this
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
115 ;; removes a line continuation backslash it'll be restored
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
116 ;; at the end.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
117 (unless c-auto-align-backslashes
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
118 ;; Should try to keep the backslash alignment
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
119 ;; in this case.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
120 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
121 (goto-char (match-end 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
122 (setq bs-col (1- (current-column)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
123 (delete-region (point) (match-end 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
124 (setq c-fix-backslashes t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
125 (if c-syntactic-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
126 (setq c-parsing-error
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
127 (or (let* ((c-parsing-error nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
128 (c-syntactic-context (or syntax
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
129 c-syntactic-context
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
130 (c-guess-basic-syntax)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
131 indent)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
132 (setq indent (c-get-syntactic-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
133 c-syntactic-context))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
134 (and (not (c-echo-parsing-error quiet))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
135 c-echo-syntactic-information-p
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
136 (message "syntax: %s, indent: %d"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
137 c-syntactic-context indent))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
138 (setq shift-amt (- indent (current-indentation)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
139 (c-shift-line-indentation shift-amt)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
140 (run-hooks 'c-special-indent-hook)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
141 c-parsing-error)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
142 c-parsing-error))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
143 (let ((indent 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
144 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
145 (while (and (= (forward-line -1) 0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
146 (if (looking-at "\\s *\\\\?$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
147 t
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
148 (setq indent (current-indentation))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
149 nil))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
150 (setq shift-amt (- indent (current-indentation)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
151 (c-shift-line-indentation shift-amt)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
152 (when (and c-fix-backslashes line-cont-backslash)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
153 (if bs-col
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
154 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
155 (indent-to bs-col)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
156 (insert ?\\))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
157 (when c-auto-align-backslashes
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
158 ;; Realign the line continuation backslash.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
159 (c-backslash-region (point) (point) nil t))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
160 shift-amt))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
162 (defun c-newline-and-indent (&optional newline-arg)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
163 "Inserts a newline and indents the new line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
164 This function fixes line continuation backslashes if inside a macro,
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
165 and takes care to set the indentation before calling
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
166 `indent-according-to-mode', so that lineup functions like
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
167 `c-lineup-dont-change' works better."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
168 ;; FIXME: Backslashes before eol in comments and literals aren't
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
169 ;; kept intact.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
170 (let ((c-macro-start (c-query-macro-start))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
171 ;; Avoid calling c-backslash-region from c-indent-line if it's
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
172 ;; called during the newline call, which can happen due to
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
173 ;; c-electric-continued-statement, for example. We also don't
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
174 ;; want any backslash alignment from indent-according-to-mode.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
175 (c-fix-backslashes nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
176 has-backslash insert-backslash
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
177 start col)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
178 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
179 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
180 (setq start (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
181 (while (and (looking-at "[ \t]*\\\\?$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
182 (= (forward-line -1) 0)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
183 (setq col (current-indentation)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
184 (when c-macro-start
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
185 (if (and (eolp) (eq (char-before) ?\\))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
186 (setq insert-backslash t
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
187 has-backslash t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
188 (setq has-backslash (eq (char-before (c-point 'eol)) ?\\))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
189 (newline newline-arg)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
190 (indent-to col)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
191 (when c-macro-start
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
192 (if insert-backslash
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
193 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
194 ;; The backslash stayed on the previous line. Insert one
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
195 ;; before calling c-backslash-region, so that
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
196 ;; bs-col-after-end in it works better. Fixup the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
197 ;; backslashes on the newly inserted line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
198 (insert ?\\)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
199 (backward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
200 (c-backslash-region (point) (point) nil t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
201 ;; The backslash moved to the new line, if there was any. Let
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
202 ;; c-backslash-region fix a backslash on the previous line,
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
203 ;; and the one that might be on the new line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
204 ;; c-auto-align-backslashes is intentionally ignored here;
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
205 ;; maybe the moved backslash should be left alone if it's set,
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
206 ;; but we fix both lines on the grounds that the old backslash
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
207 ;; has been moved anyway and is now in a different context.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
208 (c-backslash-region start (if has-backslash (point) start) nil t)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
209 (when c-syntactic-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
210 ;; Reindent syntactically. The indentation done above is not
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
211 ;; wasted, since c-indent-line might look at the current
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
212 ;; indentation.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
213 (let ((c-syntactic-context (c-guess-basic-syntax)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
214 ;; We temporarily insert another line break, so that the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
215 ;; lineup functions will see the line as empty. That makes
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
216 ;; e.g. c-lineup-cpp-define more intuitive since it then
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
217 ;; proceeds to the preceding line in this case.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
218 (insert ?\n)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
219 (delete-horizontal-space)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
220 (setq start (- (point-max) (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
221 (unwind-protect
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
222 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
223 (backward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
224 (indent-according-to-mode))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
225 (goto-char (- (point-max) start))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
226 (delete-char -1)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
227 (when has-backslash
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
228 ;; Must align the backslash again after reindentation. The
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
229 ;; c-backslash-region call above can't be optimized to ignore
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
230 ;; this line, since it then won't align correctly with the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
231 ;; lines below if the first line in the macro is broken.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
232 (c-backslash-region (point) (point) nil t)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
233
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
234 (defun c-show-syntactic-information (arg)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
235 "Show syntactic information for current line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
236 With universal argument, inserts the analysis as a comment on that line."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
237 (interactive "P")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
238 (let* ((c-parsing-error nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
239 (syntax (c-guess-basic-syntax)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
240 (if (not (consp arg))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
241 (message "syntactic analysis: %s" syntax)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
242 (indent-for-comment)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
243 (insert-and-inherit (format "%s" syntax))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
244 ))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
245 (c-keep-region-active))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
246
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
247 (defun c-syntactic-information-on-region (from to)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
248 "Inserts a comment with the syntactic analysis on every line in the region."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
249 (interactive "*r")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
250 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
251 (save-restriction
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
252 (narrow-to-region from to)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
253 (goto-char (point-min))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
254 (while (not (eobp))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
255 (c-show-syntactic-information '(0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
256 (forward-line)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
257
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
258
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
259 (defun c-toggle-syntactic-indentation (&optional arg)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
260 "Toggle syntactic indentation.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
261 Optional numeric ARG, if supplied, turns on syntactic indentation when
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
262 positive, turns it off when negative, and just toggles it when zero or
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
263 left out.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
264
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
265 When syntactic indentation is turned on (the default), the indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
266 functions and the electric keys indent according to the syntactic
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
267 context keys, when applicable.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
268
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
269 When it's turned off, the electric keys does no reindentation, the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
270 indentation functions indents every new line to the same level as the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
271 previous nonempty line, and \\[c-indent-command] adjusts the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
272 indentation in seps specified `c-basic-offset'. The indentation style
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
273 has no effect in this mode, nor any of the indentation associated
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
274 variables, e.g. `c-special-indent-hook'.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
275
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
276 This command sets the variable `c-syntactic-indentation'."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
277 (interactive "P")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
278 (setq c-syntactic-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
279 (c-calculate-state arg c-syntactic-indentation))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
280 (c-keep-region-active))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
281
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
282 (defun c-toggle-auto-state (&optional arg)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 "Toggle auto-newline feature.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
284 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
285 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
286 left out.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 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
289 `/ah' on the modeline after the mode name) newlines are automatically
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 inserted after special characters such as brace, comma, semi-colon,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
291 and colon."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (interactive "P")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 (c-update-modeline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
296
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
297 (defun c-toggle-hungry-state (&optional arg)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
298 "Toggle hungry-delete-key feature.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
299 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
300 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
301 left out.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
302
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
303 When the hungry-delete-key feature is enabled (as evidenced by the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
304 `/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
305 gobbles all preceding whitespace in one fell swoop."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
306 (interactive "P")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (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
308 (c-update-modeline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
311 (defun c-toggle-auto-hungry-state (&optional arg)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 "Toggle auto-newline and hungry-delete-key features.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
313 Optional numeric ARG, if supplied, turns on auto-newline and
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 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
315 toggles them when zero or left out.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 See `c-toggle-auto-state' and `c-toggle-hungry-state' for details."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (interactive "P")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 (setq c-auto-newline (c-calculate-state arg c-auto-newline))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (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
321 (c-update-modeline)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 ;; Electric keys
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (defun c-electric-backspace (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 "Deletes preceding character or whitespace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 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
330 \"/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
331 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
332 `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
333 function in the variable `c-backspace-function' is called.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 See also \\[c-electric-delete]."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
336 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337 (if (or (not c-hungry-delete-key)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 arg
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 (c-in-literal))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (funcall c-backspace-function (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (let ((here (point)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
342 (c-skip-ws-backward)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (if (/= (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 (delete-region (point) here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (funcall c-backspace-function 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 ))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347
37562
2692454f031f (c-electric-delete, c-electric-delete-forward): Split `c-electric-delete'
Eli Zaretskii <eliz@gnu.org>
parents: 37199
diff changeset
348 (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
349 "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
350 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
351 \"/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
352 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
353 `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
354 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
355 (interactive "*P")
2692454f031f (c-electric-delete, c-electric-delete-forward): Split `c-electric-delete'
Eli Zaretskii <eliz@gnu.org>
parents: 37199
diff changeset
356 (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
357 arg
2692454f031f (c-electric-delete, c-electric-delete-forward): Split `c-electric-delete'
Eli Zaretskii <eliz@gnu.org>
parents: 37199
diff changeset
358 (c-in-literal))
2692454f031f (c-electric-delete, c-electric-delete-forward): Split `c-electric-delete'
Eli Zaretskii <eliz@gnu.org>
parents: 37199
diff changeset
359 (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
360 (let ((here (point)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
361 (c-skip-ws-forward)
37562
2692454f031f (c-electric-delete, c-electric-delete-forward): Split `c-electric-delete'
Eli Zaretskii <eliz@gnu.org>
parents: 37199
diff changeset
362 (if (/= (point) here)
2692454f031f (c-electric-delete, c-electric-delete-forward): Split `c-electric-delete'
Eli Zaretskii <eliz@gnu.org>
parents: 37199
diff changeset
363 (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
364 (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
365
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (defun c-electric-delete (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 "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
368 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
369 backward as `c-electric-backspace', depending on the configuration:
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370
37562
2692454f031f (c-electric-delete, c-electric-delete-forward): Split `c-electric-delete'
Eli Zaretskii <eliz@gnu.org>
parents: 37199
diff changeset
371 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
372 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
373 `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
374 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
375
2692454f031f (c-electric-delete, c-electric-delete-forward): Split `c-electric-delete'
Eli Zaretskii <eliz@gnu.org>
parents: 37199
diff changeset
376 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
377 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
378 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
379 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
380 \(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
381 that automatically, though."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
382 (interactive "*P")
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
383 (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
384 (delete-forward-p))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
385 (and (boundp 'delete-key-deletes-forward) ;XEmacs 20
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
386 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
387 (c-electric-delete-forward arg)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (c-electric-backspace arg)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 (defun c-electric-pound (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 "Electric pound (`#') insertion.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 Inserts a `#' character specially depending on the variable
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 `c-electric-pound-behavior'. If a numeric ARG is supplied, or if
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
394 point is inside a literal or a macro, nothing special happens."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
395 (interactive "*P")
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
396 (if (or arg
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
397 (not (memq 'alignleft c-electric-pound-behavior))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
398 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
399 (skip-chars-backward " \t")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
400 (not (bolp)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
401 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
402 (and (= (forward-line -1) 0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
403 (progn (end-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
404 (eq (char-before) ?\\))))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
405 (c-in-literal))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 ;; do nothing special
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 ;; place the pound character at the left edge
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409 (let ((pos (- (point-max) (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 (bolp (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (delete-horizontal-space)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
413 (insert last-command-char)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (and (not bolp)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (goto-char (- (point-max) pos)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 (defun c-electric-brace (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 "Insert a brace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 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
422 or \"/ah\" string on the mode line, newlines are inserted before and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 after braces based on the value of `c-hanging-braces-alist'.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
425 Also, the line is re-indented unless a numeric ARG is supplied, the
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
426 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
427 nil.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
428
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
429 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
430 `c-cleanup-list'."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
431 (interactive "*P")
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
432 (let* ((safepos (c-safe-position (point) (c-parse-state)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
433 (literal (c-in-literal safepos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
434 ;; We want to inhibit blinking the paren since this will be
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
435 ;; most disruptive. We'll blink it ourselves later on.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
436 (old-blink-paren blink-paren-function)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
437 blink-paren-function)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
438 (cond
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
439 ((or literal arg)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
440 (self-insert-command (prefix-numeric-value arg)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
441 ((not (looking-at "[ \t]*\\\\?$"))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
442 (self-insert-command (prefix-numeric-value arg))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
443 (if c-syntactic-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
444 (indent-according-to-mode)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
445 (t
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
446 (let* ((syms
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
447 ;; 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
448 ;; 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
449 ;; they should be added here as well.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
450 '(class-open class-close defun-open defun-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
451 inline-open inline-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
452 brace-list-open brace-list-close
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
453 brace-list-intro brace-entry-open
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
454 block-open block-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
455 substatement-open statement-case-open
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
456 extern-lang-open extern-lang-close
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
457 namespace-open namespace-close
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
458 inexpr-class-open inexpr-class-close
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
459 ))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
460 (insertion-point (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
461 (preserve-p (and (not (bobp))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
462 (eq ?\ (char-syntax (char-before)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
463 ;; shut this up too
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
464 (c-echo-syntactic-information-p nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
465 delete-temp-newline syntax newlines)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
466 ;; only insert a newline if there is non-whitespace behind us
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
467 (when (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
468 (skip-chars-backward " \t")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
469 (not (bolp)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
470 (setq delete-temp-newline
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
471 (list (point-marker)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
472 (c-newline-and-indent)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
473 (setcdr delete-temp-newline (point-marker)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
474 (unwind-protect
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
475 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
476 (if (eq last-command-char ?{)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
477 (setq c-state-cache (cons (point) c-state-cache)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
478 (self-insert-command (prefix-numeric-value arg))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
479 (let ((c-syntactic-indentation-in-macros t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
480 ;; Turn on syntactic macro analysis to help with auto
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
481 ;; newlines only.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
482 (setq syntax (c-guess-basic-syntax)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (setq newlines
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
484 (and
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
485 c-auto-newline
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
486 (or (c-lookup-lists
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
487 syms
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
488 ;; Substitute inexpr-class and class-open or
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
489 ;; class-close with inexpr-class-open or
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
490 ;; inexpr-class-close.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
491 (if (assq 'inexpr-class syntax)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
492 (cond ((assq 'class-open syntax)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
493 '((inexpr-class-open)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
494 ((assq 'class-close syntax)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
495 '((inexpr-class-close)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
496 (t syntax))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
497 syntax)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
498 c-hanging-braces-alist)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
499 '(ignore before after))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
500 ;; Do not try to insert newlines around a special
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
501 ;; (Pike-style) brace list.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
502 (if (and c-special-brace-lists
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
503 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
504 (c-safe (if (= (char-before) ?{)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
505 (forward-char -1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
506 (c-forward-sexp -1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
507 (c-looking-at-special-brace-list))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
508 (setq newlines nil))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
509 ;; If syntax is a function symbol, then call it using the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
510 ;; defined semantics.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
511 (if (and (not (consp (cdr newlines)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
512 (functionp (cdr newlines)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
513 (let ((c-syntactic-context syntax))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
514 (setq newlines
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
515 (funcall (cdr newlines)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
516 (car newlines)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
517 insertion-point))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
518 ;; does a newline go before the open brace?
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
519 (when (memq 'before newlines)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
520 ;; we leave the newline we've put in there before,
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
521 ;; but we need to re-indent the line above
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
522 (when delete-temp-newline
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
523 (set-marker (car delete-temp-newline) nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
524 (set-marker (cdr delete-temp-newline) nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
525 (setq delete-temp-newline nil))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
526 (when c-syntactic-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
527 (let ((pos (- (point-max) (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
528 (here (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
529 (forward-line -1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
530 (indent-according-to-mode)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
531 (goto-char (- (point-max) pos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
532 ;; if the buffer has changed due to the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
533 ;; indentation, we need to recalculate syntax for
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
534 ;; the current line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
535 (if (/= (point) here)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
536 (let ((c-syntactic-indentation-in-macros t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
537 ;; Turn on syntactic macro analysis to help
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
538 ;; with auto newlines only.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
539 (setq syntax (c-guess-basic-syntax))))))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 ;; must remove the newline we just stuck in (if we really did it)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
541 (when delete-temp-newline
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
542 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
543 (delete-region (car delete-temp-newline)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
544 (cdr delete-temp-newline))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
545 (goto-char (car delete-temp-newline))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
546 (set-marker (car delete-temp-newline) nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
547 (set-marker (cdr delete-temp-newline) nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
548 ;; if there is whitespace before point, then preserve
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
549 ;; at least one space.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
550 (just-one-space)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
551 (if (not preserve-p)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
552 (delete-char -1)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
553 (if (not (memq 'before newlines))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
554 ;; since we're hanging the brace, we need to recalculate
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
555 ;; syntax.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
556 (let ((c-syntactic-indentation-in-macros t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
557 ;; Turn on syntactic macro analysis to help with auto
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
558 ;; newlines only.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
559 (setq syntax (c-guess-basic-syntax))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
560 (when c-syntactic-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
561 ;; Now adjust the line's indentation. Don't update the state
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
562 ;; cache since c-guess-basic-syntax isn't called when
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
563 ;; c-syntactic-context is set.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
564 (let* ((c-syntactic-context syntax))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
565 (indent-according-to-mode)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 ;; Do all appropriate clean ups
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 (let ((here (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
568 (pos (- (point-max) (point)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
569 mbeg mend tmp)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
570 ;; clean up empty defun braces
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
571 (if (and c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (memq 'empty-defun-braces c-cleanup-list)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (eq last-command-char ?\})
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
574 (c-intersect-lists '(defun-close class-close inline-close)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 syntax)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
576 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
577 (forward-char -1)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
578 (c-skip-ws-backward)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
579 (eq (char-before) ?\{))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
580 ;; make sure matching open brace isn't in a comment
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581 (not (c-in-literal)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 (delete-region (point) (1- here)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
583 ;; clean up brace-else-brace and brace-elseif-brace
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
584 (when (and c-auto-newline
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
585 (eq last-command-char ?\{))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
586 (cond
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
587 ((and (memq 'brace-else-brace c-cleanup-list)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
588 (re-search-backward
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
589 (concat "}"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
590 "\\([ \t\n]\\|\\\\\n\\)*"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
591 "else"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
592 "\\([ \t\n]\\|\\\\\n\\)*"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
593 "{")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
594 nil t)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (setq mbeg (match-beginning 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 mend (match-end 0))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
598 (eq (match-end 0) here)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
599 (delete-region mbeg mend)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
600 (insert-and-inherit "} else {"))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
601 ((and (memq 'brace-elseif-brace c-cleanup-list)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
602 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
603 (goto-char (1- here))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
604 (setq mend (point))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
605 (c-skip-ws-backward)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
606 (setq mbeg (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
607 (eq (char-before) ?\)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
608 (= (c-backward-token-1 1 t) 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
609 (eq (char-after) ?\()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
610 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
611 (setq tmp (point))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
612 (re-search-backward
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
613 (concat "}"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
614 "\\([ \t\n]\\|\\\\\n\\)*"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
615 "else"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
616 "\\([ \t\n]\\|\\\\\n\\)+"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
617 "if"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
618 "\\([ \t\n]\\|\\\\\n\\)*")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
619 nil t))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
620 (eq (match-end 0) tmp))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
621 (delete-region mbeg mend)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
622 (goto-char mbeg)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
623 (insert ?\ ))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
624 (goto-char (- (point-max) pos))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 )
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
626 ;; does a newline go after the brace?
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 (if (memq 'after newlines)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
628 (c-newline-and-indent))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
629 )))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
630 ;; blink the paren
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
631 (and (eq last-command-char ?\})
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
632 (not executing-kbd-macro)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
633 old-blink-paren
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
634 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
635 (c-backward-syntactic-ws safepos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
636 (funcall old-blink-paren)))))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
637
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
638 (defun c-electric-slash (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
639 "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
640
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
641 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
642
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
643 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
644 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
645
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
646 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
647 comment.
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
648
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
649 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
650 `c-syntactic-indentation' is nil, indentation is inhibited."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
651 (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
652 (let* ((ch (char-before))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
653 (literal (c-in-literal))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
654 (indentp (and c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
655 (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
656 (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
657 (or (and (eq ch ?/)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
658 (not literal))
19297
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
659 (and (eq ch ?*)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
660 literal))
19297
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
661 ))
1982f8488449 (indent-new-comment-line): Add advice for older Emacs versions if they
Richard M. Stallman <rms@gnu.org>
parents: 19252
diff changeset
662 ;; 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
663 (c-echo-syntactic-information-p nil))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
664 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 (if indentp
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
666 (indent-according-to-mode))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
667
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
668 (defun c-electric-star (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
669 "Insert a star character.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 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
671 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
672 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
673 `c-syntactic-indentation' is nil, indentation is inhibited."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
674 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
675 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 ;; 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
677 ;; 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
678 (if (and c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
679 (not arg)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
680 (eq (c-in-literal) 'c)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681 (eq (char-before) ?*)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
683 (forward-char -1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
684 (skip-chars-backward "*")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
685 (if (eq (char-before) ?/)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 (forward-char -1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 (skip-chars-backward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 (bolp)))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
689 (let (c-echo-syntactic-information-p) ; shut this up
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
690 (indent-according-to-mode))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 ))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 (defun c-electric-semi&comma (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 "Insert a comma or semicolon.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 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
696 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
697 the variable `c-hanging-semi&comma-criteria' for how newline insertion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
698 is determined.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
699
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
700 When a semicolon is inserted, the line is re-indented unless a numeric
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
701 arg is supplied, point is inside a literal, or
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
702 `c-syntactic-indentation' is nil.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
703
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
704 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
705 following brace lists and semicolons following defuns."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
706 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707 (let* ((lim (c-most-enclosing-brace (c-parse-state)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 (literal (c-in-literal lim))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 (here (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 ;; shut this up
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 (c-echo-syntactic-information-p nil))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
712 (if (or literal arg)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 ;; do some special stuff with the character
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 (self-insert-command (prefix-numeric-value arg))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
716 ;; 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
717 ;; turned on
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
718 (if (or (not c-auto-newline)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
719 (not (looking-at "[ \t]*\\\\?$")))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
720 (if c-syntactic-indentation
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
721 (indent-according-to-mode))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
722 ;; clean ups
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
723 (let ((pos (- (point-max) (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
724 (if (and (or (and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
725 (eq last-command-char ?,)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 (memq 'list-close-comma c-cleanup-list))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 (and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (eq last-command-char ?\;)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
729 (memq 'defun-close-semi c-cleanup-list)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 (forward-char -1)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
732 (c-skip-ws-backward)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 (eq (char-before) ?}))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 ;; make sure matching open brace isn't in a comment
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 (not (c-in-literal lim)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 (delete-region (point) here))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 (goto-char (- (point-max) pos)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 ;; re-indent line
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
739 (if c-syntactic-indentation
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
740 (indent-according-to-mode))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 ;; check to see if a newline should be added
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 (let ((criteria c-hanging-semi&comma-criteria)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
743 answer add-newline-p)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744 (while criteria
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 (setq answer (funcall (car criteria)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 ;; only nil value means continue checking
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
747 (if (not answer)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 (setq criteria (cdr criteria))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 (setq criteria nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 ;; only 'stop specifically says do not add a newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 (setq add-newline-p (not (eq answer 'stop)))
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 (if add-newline-p
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
754 (c-newline-and-indent))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 )))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 (defun c-electric-colon (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 "Insert a colon.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 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
761 or \"/ah\" string on the mode line, newlines are inserted before and
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 after colons based on the value of `c-hanging-colons-alist'.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
764 Also, the line is re-indented unless a numeric ARG is supplied, the
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
765 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
766 nil.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768 This function cleans up double colon scope operators based on the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
769 value of `c-cleanup-list'."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
770 (interactive "*P")
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 (let* ((bod (c-point 'bod))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 (literal (c-in-literal bod))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
773 newlines is-scope-op
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 ;; shut this up
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 (c-echo-syntactic-information-p nil))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
776 (cond
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
777 ((or literal arg)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
778 (self-insert-command (prefix-numeric-value arg)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
779 ((not (looking-at "[ \t]*\\\\?$"))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
780 (self-insert-command (prefix-numeric-value arg))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
781 (if c-syntactic-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
782 (indent-according-to-mode)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
783 (t
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
784 ;; insert the colon, then do any specified cleanups
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
785 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
786 (let ((pos (- (point-max) (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
787 (here (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
788 (if (and c-auto-newline
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
789 (memq 'scope-operator c-cleanup-list)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
790 (eq (char-before) ?:)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
791 (progn
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
792 (forward-char -1)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
793 (c-skip-ws-backward)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794 (eq (char-before) ?:))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 (not (c-in-literal))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 (not (eq (char-after (- (point) 2)) ?:)))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
797 (progn
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
798 (delete-region (point) (1- here))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
799 (setq is-scope-op t)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 (goto-char (- (point-max) pos)))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
801 ;; 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
802 (if c-syntactic-indentation
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
803 ;; Cannot use the same syntax analysis as we find below,
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
804 ;; since that's made with c-syntactic-indentation-in-macros
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
805 ;; always set to t.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
806 (indent-according-to-mode))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
807 (let* ((c-syntactic-indentation-in-macros t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
808 ;; Turn on syntactic macro analysis to help with auto newlines
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
809 ;; only.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
810 (syntax (c-guess-basic-syntax))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
811 (elem syntax))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
812 ;; Translate substatement-label to label for this operation.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
813 (while elem
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
814 (if (eq (car (car elem)) 'substatement-label)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
815 (setcar (car elem) 'label))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
816 (setq elem (cdr elem)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
817 ;; some language elements can only be determined by checking
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
818 ;; the following line. Lets first look for ones that can be
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
819 ;; found when looking on the line with the colon
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
820 (setq newlines
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
821 (and c-auto-newline
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
822 (or (c-lookup-lists '(case-label label access-label)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
823 syntax c-hanging-colons-alist)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
824 (c-lookup-lists '(member-init-intro inher-intro)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
825 (let ((buffer-undo-list t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
826 (insert ?\n)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
827 (unwind-protect
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
828 (c-guess-basic-syntax)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
829 (delete-char -1)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
830 c-hanging-colons-alist)))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
831 ;; does a newline go before the colon? Watch out for already
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
832 ;; non-hung colons. However, we don't unhang them because that
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
833 ;; would be a cleanup (and anti-social).
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
834 (if (and (memq 'before newlines)
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
835 (not is-scope-op)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
836 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
837 (skip-chars-backward ": \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
838 (not (bolp))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
839 (let ((pos (- (point-max) (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
840 (forward-char -1)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
841 (c-newline-and-indent)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
842 (goto-char (- (point-max) pos))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
843 ;; does a newline go after the colon?
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
844 (if (and (memq 'after (cdr-safe newlines))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
845 (not is-scope-op))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
846 (c-newline-and-indent))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
847 ))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
848
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
849 (defun c-electric-lt-gt (arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
850 "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
851 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
852 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
853 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
854 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
855 will not be re-indented."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
856 (interactive "*P")
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
857 (let ((indentp (and c-syntactic-indentation
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
858 (not arg)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
859 (eq (char-before) last-command-char)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
860 (not (c-in-literal))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
861 ;; shut this up
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
862 (c-echo-syntactic-information-p nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
863 (self-insert-command (prefix-numeric-value arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
864 (if indentp
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
865 (indent-according-to-mode))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
866
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
867 (defun c-electric-paren (arg)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
868 "Insert a parenthesis.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
869
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
870 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
871 `c-cleanup-list'.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
872
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
873 Also, the line is re-indented unless a numeric ARG is supplied, the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
874 parenthesis is inserted inside a literal, or `c-syntactic-indentation'
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
875 is nil."
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
876 (interactive "*P")
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
877 (let ((literal (c-in-literal (c-point 'bod)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
878 ;; shut this up
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
879 (c-echo-syntactic-information-p nil))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
880 (if (or arg literal)
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
881 (self-insert-command (prefix-numeric-value arg))
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
882 ;; do some special stuff with the character
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
883 (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
884 ;; be most disruptive. We'll blink it ourselves
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
885 ;; afterwards.
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
886 (old-blink-paren blink-paren-function)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
887 blink-paren-function)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
888 (self-insert-command (prefix-numeric-value arg))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
889 (if c-syntactic-indentation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
890 (indent-according-to-mode))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
891 (when (looking-at "[ \t]*\\\\?$")
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
892 (when c-auto-newline
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
893 ;; Do all appropriate clean ups
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
894 (let ((here (point))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
895 (pos (- (point-max) (point)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
896 mbeg mend)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
897 ;; clean up brace-elseif-brace
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
898 (if (and (memq 'brace-elseif-brace c-cleanup-list)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
899 (eq last-command-char ?\()
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
900 (re-search-backward
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
901 (concat "}"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
902 "\\([ \t\n]\\|\\\\\n\\)*"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
903 "else"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
904 "\\([ \t\n]\\|\\\\\n\\)+"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
905 "if"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
906 "\\([ \t\n]\\|\\\\\n\\)*"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
907 "(")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
908 nil t)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
909 (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
910 (setq mbeg (match-beginning 0)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
911 mend (match-end 0))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
912 (= mend here))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
913 (not (c-in-literal)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
914 (progn
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
915 (delete-region mbeg mend)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
916 (insert-and-inherit "} else if ("))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
917 ;; clean up brace-catch-brace
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
918 (goto-char here)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
919 (if (and (memq 'brace-catch-brace c-cleanup-list)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
920 (eq last-command-char ?\()
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
921 (re-search-backward
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
922 (concat "}"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
923 "\\([ \t\n]\\|\\\\\n\\)*"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
924 "catch"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
925 "\\([ \t\n]\\|\\\\\n\\)*"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
926 "(")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
927 nil t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
928 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
929 (setq mbeg (match-beginning 0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
930 mend (match-end 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
931 (= mend here))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
932 (not (c-in-literal)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
933 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
934 (delete-region mbeg mend)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
935 (insert-and-inherit "} catch ("))))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
936 (goto-char (- (point-max) pos))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
937 )))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
938 (let (beg (end (1- (point))))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
939 (cond ((and (memq 'space-before-funcall c-cleanup-list)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
940 (eq last-command-char ?\()
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
941 (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
942 (backward-char)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
943 (skip-chars-backward " \t")
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
944 (setq beg (point))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
945 (c-on-identifier)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
946 (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
947 (delete-region beg end)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
948 (goto-char beg)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
949 (insert ?\ )))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
950 ((and (memq 'compact-empty-funcall c-cleanup-list)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
951 (eq last-command-char ?\))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
952 (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
953 (c-safe (backward-char 2))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
954 (when (looking-at "()")
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
955 (setq end (point))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
956 (skip-chars-backward " \t")
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
957 (setq beg (point))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
958 (c-on-identifier))))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
959 (delete-region beg end))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
960 (and (not executing-kbd-macro)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
961 old-blink-paren
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
962 (funcall old-blink-paren))))))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
963
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
964 (defun c-electric-continued-statement ()
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
965 "Reindent the current line if appropriate.
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
966
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
967 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
968 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
969 \"while\" in a do-while block.
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
970
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
971 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
972 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
973 `c-syntactic-indentation' is non-nil."
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
974 (let (;; shut this up
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
975 (c-echo-syntactic-information-p nil))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
976 (when (and c-syntactic-indentation
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
977 (not (eq last-command-char ?_))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
978 (= (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
979 (skip-syntax-backward "w")
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
980 (point))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
981 (c-point 'boi))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
982 (not (c-in-literal (c-point 'bod))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
983 ;; Have to temporarily insert a space so that
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
984 ;; c-guess-basic-syntax recognizes the keyword. Follow the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
985 ;; space with a nonspace to avoid messing up any whitespace
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
986 ;; sensitive meddling that might be done, e.g. by
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
987 ;; `c-backslash-region'.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
988 (insert-and-inherit " x")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
989 (unwind-protect
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
990 (indent-according-to-mode)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
991 (delete-char -2)))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
992
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
993
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
994 ;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
995 ;; originally contributed by Terry_Glanfield.Southern@rxuk.xerox.com
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
996 (defun c-forward-into-nomenclature (&optional arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
997 "Move forward to end of a nomenclature section or word.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
998 With arg, to it arg times."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
999 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1000 (let ((case-fold-search nil))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1001 (if (> arg 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1002 (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
1003 (while (and (< arg 0)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1004 (re-search-backward
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1005 "\\(\\(\\W\\|[a-z0-9]\\)[A-Z]+\\|\\W\\w+\\)"
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1006 (point-min) 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1007 (forward-char 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1008 (setq arg (1+ arg)))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1009 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1010
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1011 (defun c-backward-into-nomenclature (&optional arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1012 "Move backward to beginning of a nomenclature section or word.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1013 With optional ARG, move that many times. If ARG is negative, move
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1014 forward."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1015 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1016 (c-forward-into-nomenclature (- arg))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1017 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1018
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1019 (defun c-scope-operator ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1020 "Insert a double colon scope operator at point.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1021 No indentation or other \"electric\" behavior is performed."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1022 (interactive "*")
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1023 (insert-and-inherit "::"))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1024
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1025 (defun c-beginning-of-defun (&optional arg)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1026 "Move backward to the beginning of a defun.
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1027 Every top level declaration that contains a brace paren block is
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1028 considered to be a defun.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1029
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1030 With a positive argument, move backward that many defuns. A negative
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1031 argument -N means move forward to the Nth following beginning. Return
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1032 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
1033
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1034 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
1035 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
1036 defun."
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1037
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1038 (interactive "p")
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1039 (or arg (setq arg 1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1040
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1041 (if (< arg 0)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1042 (when (c-end-of-defun (- arg))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1043 (c-forward-syntactic-ws)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1044 t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1045
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1046 (catch 'exit
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1047 (while (> arg 0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1048 ;; Note: Partial code duplication in `c-end-of-defun' and
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1049 ;; `c-declaration-limits'.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1050
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1051 (let ((paren-state (c-parse-state)) lim pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1052 (unless (c-safe
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1053 (goto-char (c-least-enclosing-brace paren-state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1054 ;; If we moved to the outermost enclosing paren
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1055 ;; then we can use c-safe-position to set the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1056 ;; limit. Can't do that otherwise since the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1057 ;; earlier paren pair on paren-state might very
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1058 ;; well be part of the declaration we should go
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1059 ;; to.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1060 (setq lim (c-safe-position (point) paren-state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1061 t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1062 ;; At top level. Make sure we aren't inside a literal.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1063 (setq pos (c-literal-limits
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1064 (c-safe-position (point) paren-state)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1065 (if pos (goto-char (car pos))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1066
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1067 (while (let ((start (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1068 (c-beginning-of-decl-1 lim)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1069 (if (= (point) start)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1070 ;; Didn't move. Might be due to bob or unbalanced
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1071 ;; parens. Try to continue if it's the latter.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1072 (unless (c-safe (goto-char
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1073 (c-down-list-backward (point))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1074 ;; Didn't work, so it's bob then.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1075 (goto-char (point-min))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1076 (throw 'exit nil)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1077
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1078 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1079 ;; Check if the declaration contains a brace
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1080 ;; block. If not, we try another one.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1081 (setq pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1082 (not (and (c-syntactic-re-search-forward
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1083 "[;{]" nil t 1 t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1084 (or (eq (char-before) ?{)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1085 (and c-recognize-knr-p
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1086 ;; Might have stopped on the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1087 ;; ';' in a K&R argdecl. In
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1088 ;; that case the declaration
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1089 ;; should contain a block.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1090 (c-in-knr-argdecl pos)))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1091 (setq lim nil))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1092
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1093 ;; Check if `c-beginning-of-decl-1' put us after the block
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1094 ;; in a declaration that doesn't end there. We're searching
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1095 ;; back and forth over the block here, which can be
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1096 ;; expensive.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1097 (setq pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1098 (if (and c-opt-block-decls-with-vars-key
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1099 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1100 (c-backward-syntactic-ws)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1101 (eq (char-before) ?}))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1102 (eq (car (c-beginning-of-decl-1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1103 'previous)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1104 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1105 (c-end-of-decl-1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1106 (> (point) pos)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1107 nil
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1108 (goto-char pos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1109
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1110 (setq pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1111 ;; Try to be line oriented; position point at the closest
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1112 ;; preceding boi that isn't inside a comment, but if we hit
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1113 ;; the previous declaration then we use the current point
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1114 ;; instead.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1115 (while (and (/= (point) (c-point 'boi))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1116 (c-forward-comment -1)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1117 (if (/= (point) (c-point 'boi))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1118 (goto-char pos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1119
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1120 (setq arg (1- arg)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1121 (c-keep-region-active)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1122 (= arg 0)))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1123
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1124 (defun c-end-of-defun (&optional arg)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1125 "Move forward to the end of a top level declaration.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1126 With argument, do it that many times. Negative argument -N means move
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1127 back to Nth preceding end. Returns t unless search stops due to
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1128 beginning or end of buffer.
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1129
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1130 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
1131 the open-parenthesis that starts a defun; see `beginning-of-defun'."
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1132
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1133 (interactive "p")
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1134 (or arg (setq arg 1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1135
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1136 (if (< arg 0)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1137 (when (c-beginning-of-defun (- arg))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1138 (c-backward-syntactic-ws)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1139 t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1140
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1141 (catch 'exit
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1142 (while (> arg 0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1143 ;; Note: Partial code duplication in `c-beginning-of-defun'
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1144 ;; and `c-declaration-limits'.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1145
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1146 (let ((paren-state (c-parse-state)) lim pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1147 (unless (c-safe
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1148 (goto-char (c-least-enclosing-brace paren-state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1149 ;; If we moved to the outermost enclosing paren
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1150 ;; then we can use c-safe-position to set the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1151 ;; limit. Can't do that otherwise since the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1152 ;; earlier paren pair on paren-state might very
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1153 ;; well be part of the declaration we should go
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1154 ;; to.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1155 (setq lim (c-safe-position (point) paren-state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1156 t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1157 ;; At top level. Make sure we aren't inside a literal.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1158 (setq pos (car-safe (c-literal-limits
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1159 (c-safe-position (point) paren-state))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1160 (if pos (goto-char pos)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1161
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1162 ;; Have to move to the start first so that `c-end-of-decl-1'
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1163 ;; has the correct start position.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1164 (setq pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1165 (when (memq (car (c-beginning-of-decl-1 lim))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1166 '(previous macro))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1167 ;; We moved back over the previous defun or a macro. Move
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1168 ;; to the next token; it's the start of the next
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1169 ;; declaration. We can also be directly after the block
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1170 ;; in a `c-opt-block-decls-with-vars-key' declaration, but
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1171 ;; then we won't move significantly far here.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1172 (goto-char pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1173 (c-forward-token-1 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1174
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1175 (while (let ((start (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1176 (c-end-of-decl-1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1177 (if (= (point) start)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1178 ;; Didn't move. Might be due to eob or unbalanced
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1179 ;; parens. Try to continue if it's the latter.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1180 (if (c-safe (goto-char (c-up-list-forward (point))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1181 t
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1182 ;; Didn't work, so it's eob then.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1183 (goto-char (point-max))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1184 (throw 'exit nil))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1185
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1186 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1187 ;; Check if the declaration contains a brace
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1188 ;; block. If not, we try another one.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1189 (setq pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1190 (goto-char start)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1191 (not (c-syntactic-re-search-forward "{" pos t 1 t))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1192
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1193 (setq pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1194 ;; Try to be line oriented; position point after the next
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1195 ;; newline that isn't inside a comment, but if we hit the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1196 ;; next declaration then we use the current point instead.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1197 (while (and (not (bolp))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1198 (not (looking-at "\\s *$"))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1199 (c-forward-comment 1)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1200 (cond ((bolp))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1201 ((looking-at "\\s *$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1202 (forward-line 1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1203 (t
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1204 (goto-char pos)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1205
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1206 (setq arg (1- arg)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1207 (c-keep-region-active)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1208 (= arg 0)))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1209
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1210 (defun c-declaration-limits (near)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1211 ;; Return a cons of the beginning and end positions of the current
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1212 ;; top level declaration or macro. If point is not inside any then
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1213 ;; nil is returned, unless NEAR is non-nil in which case the closest
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1214 ;; following one is chosen instead (if there is any). The end
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1215 ;; position is at the next line, providing there is one before the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1216 ;; declaration.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1217 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1218
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1219 ;; Note: Some code duplication in `c-beginning-of-defun' and
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1220 ;; `c-end-of-defun'.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1221 (catch 'exit
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1222 (let ((start (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1223 (paren-state (c-parse-state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1224 lim pos end-pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1225 (unless (c-safe
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1226 (goto-char (c-least-enclosing-brace paren-state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1227 ;; If we moved to the outermost enclosing paren then we
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1228 ;; can use c-safe-position to set the limit. Can't do
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1229 ;; that otherwise since the earlier paren pair on
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1230 ;; paren-state might very well be part of the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1231 ;; declaration we should go to.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1232 (setq lim (c-safe-position (point) paren-state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1233 t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1234 ;; At top level. Make sure we aren't inside a literal.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1235 (setq pos (c-literal-limits
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1236 (c-safe-position (point) paren-state)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1237 (if pos (goto-char (car pos))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1238
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1239 (when (c-beginning-of-macro)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1240 (throw 'exit
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1241 (cons (point)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1242 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1243 (c-end-of-macro)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1244 (forward-line 1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1245 (point)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1246
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1247 (setq pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1248 (when (or (eq (car (c-beginning-of-decl-1 lim)) 'previous)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1249 (= pos (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1250 ;; We moved back over the previous defun. Skip to the next
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1251 ;; one. Not using c-forward-syntactic-ws here since we
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1252 ;; should not skip a macro. We can also be directly after
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1253 ;; the block in a `c-opt-block-decls-with-vars-key'
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1254 ;; declaration, but then we won't move significantly far
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1255 ;; here.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1256 (goto-char pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1257 (while (c-forward-comment 10))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1258
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1259 (when (and near (c-beginning-of-macro))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1260 (throw 'exit
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1261 (cons (point)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1262 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1263 (c-end-of-macro)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1264 (forward-line 1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1265 (point))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1266
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1267 (if (eobp) (throw 'exit nil))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1268
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1269 ;; Check if `c-beginning-of-decl-1' put us after the block in a
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1270 ;; declaration that doesn't end there. We're searching back and
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1271 ;; forth over the block here, which can be expensive.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1272 (setq pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1273 (if (and c-opt-block-decls-with-vars-key
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1274 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1275 (c-backward-syntactic-ws)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1276 (eq (char-before) ?}))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1277 (eq (car (c-beginning-of-decl-1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1278 'previous)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1279 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1280 (c-end-of-decl-1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1281 (and (> (point) pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1282 (setq end-pos (point)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1283 nil
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1284 (goto-char pos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1285
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1286 (if (and (not near) (> (point) start))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1287 nil
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1288
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1289 ;; Try to be line oriented; position the limits at the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1290 ;; closest preceding boi, and after the next newline, that
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1291 ;; isn't inside a comment, but if we hit a neighboring
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1292 ;; declaration then we instead use the exact declaration
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1293 ;; limit in that direction.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1294 (cons (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1295 (setq pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1296 (while (and (/= (point) (c-point 'boi))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1297 (c-forward-comment -1)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1298 (if (/= (point) (c-point 'boi))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1299 pos
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1300 (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1301 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1302 (if end-pos
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1303 (goto-char end-pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1304 (c-end-of-decl-1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1305 (setq pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1306 (while (and (not (bolp))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1307 (not (looking-at "\\s *$"))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1308 (c-forward-comment 1)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1309 (cond ((bolp)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1310 (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1311 ((looking-at "\\s *$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1312 (forward-line 1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1313 (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1314 (t
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1315 pos)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1316 ))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1317
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1318 (defun c-mark-function ()
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1319 "Put mark at end of the current top-level declaration or macro, point at beginning.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1320 If point is not inside any then the closest following one is chosen.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1321
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1322 As opposed to \\[c-beginning-of-defun] and \\[c-end-of-defun], this
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1323 function does not require the declaration to contain a brace block."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1324 (interactive)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1325
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1326 ;; We try to be line oriented, unless there are several
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1327 ;; declarations on the same line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1328 (if (looking-at c-syntactic-eol)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1329 (c-backward-token-1 1 nil (c-point 'bol)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1330
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1331 (let ((decl-limits (c-declaration-limits t)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1332 (if (not decl-limits)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1333 (error "Cannot find any declaration")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1334 (goto-char (car decl-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1335 (push-mark (cdr decl-limits) nil t))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1336
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1337
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1338 (defun c-beginning-of-statement (&optional count lim sentence-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1339 "Go to the beginning of the innermost C statement.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1340 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
1341 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
1342 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
1343 \\[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
1344 comment or multiline string, move by sentences instead of statements.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1345
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1346 When called from a program, this function takes 3 optional args: the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1347 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
1348 to search for the syntactic context, and a flag saying whether to do
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1349 sentence motion in or near comments and multiline strings.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1350
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1351 Note that `c-beginning-of-statement-1' is usually better to use from
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1352 programs. It has much more well defined semantics than this one,
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1353 which is intended for interactive use and might therefore change to be
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1354 more \"DWIM:ey\"."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1355 (interactive (list (prefix-numeric-value current-prefix-arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1356 nil t))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1357 (let* ((count (or count 1))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1358 here
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1359 (range (c-collect-line-comments (c-literal-limits lim))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1360 (while (and (/= count 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1361 (or (not lim) (> (point) lim)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1362 (setq here (point))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1363 (if (and (not range) sentence-flag)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1364 (save-excursion
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1365 ;; 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
1366 (if (> count 0)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1367 (if (c-forward-comment-lc -1)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1368 (setq range (cons (point)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1369 (progn (c-forward-comment-lc 1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1370 (point))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1371 (c-skip-ws-backward)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1372 (setq range (point))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1373 (setq range
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1374 (if (eq (char-before) ?\")
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1375 (c-safe (c-backward-sexp 1)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1376 (cons (point) range)))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1377 (c-skip-ws-forward)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1378 (if (eq (char-after) ?\")
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1379 (setq range (cons (point)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1380 (progn
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1381 (c-forward-sexp 1)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1382 (point))))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1383 (setq range (point))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1384 (setq range (if (c-forward-comment-lc 1)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1385 (cons range (point))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1386 nil))))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1387 (setq range (c-collect-line-comments range))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1388 (if (and (< count 0) (= here (point-max)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1389 ;; Special case because eob might be in a literal.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1390 (setq range nil))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1391 (if range
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1392 (if (and sentence-flag
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1393 (or (/= (char-syntax (char-after (car range))) ?\")
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1394 ;; 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
1395 (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1396 (goto-char (car range))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1397 (skip-chars-forward "^\n" (cdr range))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1398 (< (point) (cdr range)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1399 (let* ((lit-type (c-literal-type range))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1400 (line-prefix (concat "[ \t]*\\("
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1401 c-current-comment-prefix
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1402 "\\)[ \t]*"))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1403 (beg (if (eq lit-type 'string)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1404 (1+ (car range))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1405 (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1406 (goto-char (car range))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1407 (max (progn
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1408 (looking-at comment-start-skip)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1409 (match-end 0))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1410 (progn
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1411 (looking-at line-prefix)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1412 (match-end 0))))))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1413 (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
1414 (beg-of-para (if (eq lit-type 'string)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1415 (lambda ())
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1416 (lambda ()
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1417 (beginning-of-line)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1418 (if (looking-at line-prefix)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1419 (goto-char (match-end 0)))))))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1420 (save-restriction
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1421 ;; 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
1422 ;; literal, narrowed to the appropriate
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1423 ;; paragraph(s).
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1424 (narrow-to-region (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1425 (let ((pos (min here end)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1426 (goto-char pos)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1427 (forward-paragraph -1)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1428 (if (looking-at paragraph-separate)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1429 (forward-line))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1430 (when (> (point) beg)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1431 (funcall beg-of-para)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1432 (when (>= (point) pos)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1433 (forward-paragraph -2)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1434 (funcall beg-of-para)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1435 (max (point) beg)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1436 end)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1437 (c-safe (forward-sentence (if (< count 0) 1 -1)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1438 (if (and (memq lit-type '(c c++))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1439 ;; Check if we stopped due to a comment
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1440 ;; prefix and not a sentence end.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1441 (/= (point) (point-min))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1442 (/= (point) (point-max))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1443 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1444 (beginning-of-line)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1445 (looking-at line-prefix))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1446 (>= (point) (match-beginning 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1447 (/= (match-beginning 1) (match-end 1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1448 (or (< (point) (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1449 (and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1450 (= (point) (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1451 ;; The comment prefix may contain
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1452 ;; characters that is regarded as end
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1453 ;; of sentence.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1454 (or (eolp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1455 (and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1456 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1457 (forward-paragraph -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1458 (< (point) (match-beginning 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1459 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1460 (beginning-of-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1461 (or (not (re-search-backward
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1462 sentence-end
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1463 (c-point 'bopl)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1464 t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1465 (< (match-end 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1466 (c-point 'eol)))))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1467 (setq count (+ count (if (< count 0) -1 1)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1468 (if (< count 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1469 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1470 ;; In block comments, if there's only
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1471 ;; horizontal ws between the text and the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1472 ;; comment ender, stop before it. Stop after
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1473 ;; the ender if there's either nothing or
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1474 ;; newlines between.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1475 (when (and (eq lit-type 'c)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1476 (eq (point) (point-max)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1477 (widen)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1478 (when (or (= (skip-chars-backward " \t") 0)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1479 (eq (point) (point-max))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1480 (bolp))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1481 (goto-char (cdr range)))))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1482 (when (and (eq (point) (point-min))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1483 (looking-at "[ \t]*\\\\?$"))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1484 ;; Stop before instead of after the comment
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1485 ;; starter if nothing follows it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1486 (widen)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1487 (goto-char (car range))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1488 (if (and (eq lit-type 'string) (/= (point) here))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1489 (setq count (1+ count)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1490 range nil))))))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1491 ;; See if we should escape the literal.
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1492 (if (> count 0)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1493 (if (< (point) here)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1494 (setq count (1- count))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1495 (goto-char (car range))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1496 (setq range nil))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1497 (if (> (point) here)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1498 (setq count (1+ count))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1499 (goto-char (cdr range))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1500 (setq range nil))))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1501 (goto-char (if (> count 0) (car range) (cdr range)))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1502 (setq range nil))
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1503 (goto-char here)
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1504 (if (> count 0)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1505 (condition-case nil
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1506 ;; Stop before `{' and after `;', `{', `}' and `};'
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1507 ;; when not followed by `}' or `)', but on the other
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1508 ;; 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
1509 ;; 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
1510 ;; on a line.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1511 (let ((literal-pos (not sentence-flag))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1512 (large-enough (- (point-max)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1513 last last-below-line)
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1514 (catch 'done
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1515 (while t
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1516 (setq last (point))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1517 (when (and (or (eq (char-after) ?\{)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1518 (and (eq (char-after) ?#)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1519 (eq (point) (c-point 'boi)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1520 )
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1521 (/= here last))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1522 (unless (and c-special-brace-lists
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1523 (eq (char-after) ?{)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1524 (c-looking-at-special-brace-list))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1525 (if (and (eq (char-after) ?#)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1526 (numberp last-below-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1527 (not (eq last-below-line here)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1528 (goto-char last-below-line))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1529 (throw 'done t)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1530 ;; Don't know why I added the following, but it
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1531 ;; doesn't work when point is preceded by a line
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1532 ;; style comment. /mast
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1533 ;;(c-skip-ws-backward)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1534 (if literal-pos
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1535 (c-forward-comment-lc large-enough)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1536 (when (c-forward-comment-lc -1)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1537 ;; Record position of first comment.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1538 (save-excursion
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1539 (c-forward-comment-lc 1)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1540 (setq literal-pos (point)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1541 (c-forward-comment-lc large-enough)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1542 (unless last-below-line
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1543 (if (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1544 (re-search-forward "\\(^\\|[^\\]\\)$" last t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1545 (setq last-below-line last)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1546 (cond ((bobp) ; Must handle bob specially.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1547 (if (= here last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1548 (throw 'done t)
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1549 (goto-char last)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1550 (throw 'done t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1551 ((progn (backward-char)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1552 (looking-at "[;{}]"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1553 (if (and c-special-brace-lists
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1554 (eq (char-after) ?{)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1555 (c-looking-at-special-brace-list))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1556 (skip-syntax-backward "w_") ; Speedup only.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1557 (if (or (= here last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1558 (memq (char-after last) '(?\) ?})))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1559 (if (and (eq (char-before) ?})
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1560 (eq (char-after) ?\;))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1561 (backward-char))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1562 (goto-char last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1563 (throw 'done t))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1564 ((= (char-syntax (char-after)) ?\")
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1565 (let ((end (point)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1566 (forward-char)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1567 (c-backward-sexp)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1568 (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1569 (skip-chars-forward "^\n" end)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1570 (when (< (point) end)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1571 ;; Break at multiline string.
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1572 (setq literal-pos (1+ end))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1573 (throw 'done t)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1574 (t (skip-syntax-backward "w_")) ; Speedup only.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1575 )))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1576 (if (and (numberp literal-pos)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1577 (< (point) literal-pos))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1578 ;; We jumped over a comment or string that
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1579 ;; should be investigated.
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1580 (goto-char literal-pos)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1581 (setq count (1- count))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1582 (error
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1583 (goto-char (point-min))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1584 (setq count 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1585 (condition-case nil
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1586 ;; 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
1587 ;; 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
1588 ;; after `;', `}' and `};'. Only stop before `{' if at
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1589 ;; top level or inside braces, though. Move by sexps
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1590 ;; 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
1591 ;; with `#' at the boi.
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1592 (let ((literal-pos (not sentence-flag))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1593 (large-enough (point-max))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1594 last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1595 (catch 'done
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1596 (while t
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1597 (setq last (point))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1598 (if literal-pos
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1599 (c-forward-comment-lc large-enough)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1600 (if (progn
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1601 (c-skip-ws-forward)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1602 ;; Record position of first comment.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1603 (setq literal-pos (point))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1604 (c-forward-comment-lc 1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1605 (c-forward-comment-lc large-enough)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1606 (setq literal-pos nil)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1607 (cond ((and (eq (char-after) ?{)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1608 (not (and c-special-brace-lists
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1609 (c-looking-at-special-brace-list)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1610 (/= here last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1611 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1612 (or (not (c-safe (up-list -1) t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1613 (= (char-after) ?{))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1614 (goto-char last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1615 (throw 'done t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1616 ((and c-special-brace-lists
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1617 (eq (char-after) ?})
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1618 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1619 (and (c-safe (up-list -1) t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1620 (c-looking-at-special-brace-list))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1621 (forward-char 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1622 (skip-syntax-forward "w_")) ; Speedup only.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1623 ((and (eq (char-after) ?})
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1624 (/= here last))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1625 (goto-char last)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1626 (throw 'done t))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1627 ; ((and (eq (char-after) ?#)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1628 ; (= (point) (c-point 'boi)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1629 ; (if (= here last)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1630 ; (or (re-search-forward "\\(^\\|[^\\]\\)$" nil t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1631 ; (goto-char (point-max)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1632 ; (goto-char last))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1633 ; (throw 'done t))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1634 ((looking-at ";\\|};?")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1635 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1636 (throw 'done t))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1637 ((= (char-syntax (char-after)) ?\")
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1638 (let ((beg (point)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1639 (c-forward-sexp)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1640 (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1641 (skip-chars-backward "^\n" beg)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1642 (when (> (point) beg)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1643 ;; Break at multiline string.
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1644 (setq literal-pos beg)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1645 (throw 'done t)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1646 (t
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1647 (forward-char 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1648 (skip-syntax-forward "w_")) ; Speedup only.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1649 )))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1650 (if (and (numberp literal-pos)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1651 (> (point) literal-pos))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1652 ;; 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
1653 (goto-char literal-pos)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1654 (setq count (1+ count))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1655 (error
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1656 (goto-char (point-max))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1657 (setq count 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1658 ))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1659 ;; 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
1660 (when (and (not (zerop count)) (= (point) here))
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
1661 (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
1662 (setq count 0))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1663 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1664
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1665 (defun c-end-of-statement (&optional count lim sentence-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1666 "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
1667 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
1668 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
1669 \(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
1670 comment or multiline string, move by sentences instead of statements.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1671
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1672 When called from a program, this function takes 3 optional args: the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1673 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
1674 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
1675 sentence motion in or near comments and multiline strings."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1676 (interactive (list (prefix-numeric-value current-prefix-arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1677 nil t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1678 (c-beginning-of-statement (- (or count 1)) lim sentence-flag)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1679 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1680
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1681
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1682 ;; set up electric character functions to work with pending-del,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1683 ;; (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
1684 ;; the functions which delete, which gets 'supersede.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1685 (mapcar
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1686 (function
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1687 (lambda (sym)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1688 (put sym 'delete-selection t) ; for delsel (Emacs)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1689 (put sym 'pending-delete t))) ; for pending-del (XEmacs)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1690 '(c-electric-pound
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1691 c-electric-brace
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1692 c-electric-slash
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1693 c-electric-star
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1694 c-electric-semi&comma
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1695 c-electric-lt-gt
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1696 c-electric-colon
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
1697 c-electric-paren))
18843
6e04c0670f55 Require cc-defs for the c-add-syntax macro.
Richard M. Stallman <rms@gnu.org>
parents: 18720
diff changeset
1698 (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
1699 (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
1700 (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
1701 (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
1702 (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
1703 (put 'c-electric-delete-forward 'pending-delete 'supersede) ; pending-del
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1704
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1705
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1706 (defun c-calc-comment-indent (entry)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1707 (if (symbolp entry)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1708 (setq entry (or (assq entry c-indent-comment-alist)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1709 (assq 'other c-indent-comment-alist)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1710 '(default . (column . nil)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1711 (let ((action (car (cdr entry)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1712 (value (cdr (cdr entry)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1713 (col (current-column)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1714 (cond ((eq action 'space)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1715 (+ col value))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1716 ((eq action 'column)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1717 (unless value (setq value comment-column))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1718 (if (bolp)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1719 ;; Do not pad with one space if we're at bol.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1720 value
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1721 (max (1+ col) value)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1722 ((eq action 'align)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1723 (or (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1724 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1725 (unless (bobp)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1726 (backward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1727 (let ((lim (c-literal-limits (c-point 'bol) t)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1728 (when (consp lim)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1729 (goto-char (car lim))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1730 (when (looking-at "/[/*]")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1731 ;; Found comment to align with.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1732 (if (bolp)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1733 ;; Do not pad with one space if we're at bol.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1734 0
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1735 (max (1+ col) (current-column))))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1736 ;; Recurse to handle value as a new spec.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1737 (c-calc-comment-indent (cdr entry)))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1738
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1739 ;; To avoid warning about assignment without reference wrt
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1740 ;; c-add-syntax below.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1741 (cc-bytecomp-defvar syntactic-relpos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1742
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1743 (defun c-comment-indent ()
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1744 "Used by `indent-for-comment' to create and indent comments.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1745 See `c-indent-comment-alist' for a description."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1746 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1747 (end-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1748 (let* ((eot (let ((lim (c-literal-limits (c-point 'bol) t)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1749 (or (when (consp lim)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1750 (goto-char (car lim))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1751 (when (looking-at "/[/*]")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1752 (skip-chars-backward " \t")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1753 (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1754 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1755 (skip-chars-backward " \t")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1756 (point)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1757 (line-type
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1758 (cond ((looking-at "^/[/*]")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1759 'anchored-comment)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1760 ((progn (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1761 (eq (point) eot))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1762 'empty-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1763 ((progn (back-to-indentation)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1764 (and (eq (char-after) ?})
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1765 (eq (point) (1- eot))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1766 'end-block)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1767 ((and (looking-at "#[ \t]*\\(endif\\|else\\)")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1768 (eq (match-end 0) eot))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1769 'cpp-end-block)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1770 (t
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1771 'other))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1772 (if (and (memq line-type '(anchored-comment empty-line))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1773 c-indent-comments-syntactically-p)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1774 (let ((syntax (c-guess-basic-syntax))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1775 syntactic-relpos)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1776 ;; BOGOSITY ALERT: if we're looking at the eol, its
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1777 ;; because indent-for-comment hasn't put the comment-start
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1778 ;; in the buffer yet. this will screw up the syntactic
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1779 ;; analysis so we kludge in the necessary info. Another
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1780 ;; 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
1781 ;; to ignore any anchoring as specified by
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1782 ;; c-comment-only-line-offset since it doesn't apply here.
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1783 (if (eolp)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1784 (c-add-syntax 'comment-intro))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1785 (let ((c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1786 (if (consp c-comment-only-line-offset)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1787 c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1788 (cons c-comment-only-line-offset
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1789 c-comment-only-line-offset))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1790 (c-get-syntactic-indentation syntax)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1791 (goto-char eot)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1792 (c-calc-comment-indent line-type)))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1793
19804
37e25ff5a7f1 (c-beginning-of-statement): Fixes in sentence movement to properly
Richard M. Stallman <rms@gnu.org>
parents: 19378
diff changeset
1794
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1795 ;; used by outline-minor-mode
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1796 (defun c-outline-level ()
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1797 (let (buffer-invisibility-spec);; This so that `current-column' DTRT
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1798 ;; in otherwise-hidden text.
37199
22964e38f4c2 (c-outline-level):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 36920
diff changeset
1799 (save-excursion
22964e38f4c2 (c-outline-level):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 36920
diff changeset
1800 (skip-chars-forward "\t ")
22964e38f4c2 (c-outline-level):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 36920
diff changeset
1801 (current-column))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1802
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1803
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1804 (defun c-up-conditional (count)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1805 "Move back to the containing preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1806 A prefix argument acts as a repeat count. With a negative argument,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1807 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
1808
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1809 `#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
1810 stops at them when going backward, but not when going forward."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1811 (interactive "p")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1812 (c-forward-conditional (- count) -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1813 (c-keep-region-active))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1814
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1815 (defun c-up-conditional-with-else (count)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1816 "Move back to the containing preprocessor conditional, including `#else'.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1817 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
1818 directives."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1819 (interactive "p")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1820 (c-forward-conditional (- count) -1 t)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1821 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1822
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1823 (defun c-down-conditional (count)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1824 "Move forward into the next preprocessor conditional, leaving mark behind.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1825 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
1826 move backward into the previous preprocessor conditional.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1827
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1828 `#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
1829 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
1830 (interactive "p")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1831 (c-forward-conditional count 1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1832 (c-keep-region-active))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1833
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1834 (defun c-down-conditional-with-else (count)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1835 "Move forward into the next preprocessor conditional, including `#else'.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1836 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
1837 directives."
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1838 (interactive "p")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1839 (c-forward-conditional count 1 t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1840 (c-keep-region-active))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1841
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1842 (defun c-backward-conditional (count &optional target-depth with-else)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1843 "Move back across a preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1844 A prefix argument acts as a repeat count. With a negative argument,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1845 move forward across a preprocessor conditional."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1846 (interactive "p")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1847 (c-forward-conditional (- count) target-depth with-else)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1848 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1849
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1850 (defun c-forward-conditional (count &optional target-depth with-else)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1851 "Move forward across a preprocessor conditional, leaving mark behind.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1852 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
1853 move backward across a preprocessor conditional.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1854
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1855 `#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
1856 nesting level isn't changed when tracking subconditionals.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1857
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1858 The optional argument TARGET-DEPTH specifies the wanted nesting depth
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1859 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
1860 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
1861 counts as -1.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1862
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1863 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
1864 treated as conditional clause limits. Normally they are ignored."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1865 (interactive "p")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1866 (let* ((forward (> count 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1867 (increment (if forward -1 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1868 (search-function (if forward 're-search-forward 're-search-backward))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1869 (new))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1870 (unless (integerp target-depth)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1871 (setq target-depth (if target-depth -1 0)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1872 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1873 (while (/= count 0)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1874 (let ((depth 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1875 ;; subdepth is the depth in "uninteresting" subtrees,
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1876 ;; i.e. those that takes us farther from the target
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1877 ;; depth instead of closer.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1878 (subdepth 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1879 found)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1880 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1881 ;; Find the "next" significant line in the proper direction.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1882 (while (and (not found)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1883 ;; Rather than searching for a # sign that
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1884 ;; comes at the beginning of a line aside from
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1885 ;; whitespace, search first for a string
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1886 ;; starting with # sign. Then verify what
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1887 ;; precedes it. This is faster on account of
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1888 ;; the fastmap feature of the regexp matcher.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1889 (funcall search-function
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1890 "#[ \t]*\\(if\\|elif\\|endif\\|else\\)"
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1891 nil t))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1892 (beginning-of-line)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1893 ;; Now verify it is really a preproc line.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1894 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\|else\\)")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1895 (let (dchange (directive (match-string 1)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1896 (cond ((string= directive "if")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1897 (setq dchange (- increment)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1898 ((string= directive "endif")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1899 (setq dchange increment))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1900 ((= subdepth 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1901 ;; When we're not in an "uninteresting"
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1902 ;; subtree, we might want to act on "elif"
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1903 ;; and "else" too.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1904 (if (cond (with-else
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1905 ;; Always move toward the target depth.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1906 (setq dchange
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1907 (if (> target-depth 0) 1 -1)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1908 ((string= directive "elif")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1909 (setq dchange (- increment))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1910 ;; Ignore the change if it'd take us
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1911 ;; into an "uninteresting" subtree.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1912 (if (eq (> dchange 0) (<= target-depth 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1913 (setq dchange nil)))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1914 (when dchange
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1915 (when (or (/= subdepth 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1916 (eq (> dchange 0) (<= target-depth 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1917 (setq subdepth (+ subdepth dchange)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1918 (setq depth (+ depth dchange))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1919 ;; 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
1920 ;; end before we find a beginning, get an error.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1921 (if (and (< depth target-depth) (< dchange 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1922 (error (if forward
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1923 "No following conditional at this level"
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1924 "No previous conditional at this level"))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1925 ;; When searching forward, start from next line so
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1926 ;; that we don't find the same line again.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1927 (if forward (forward-line 1))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1928 ;; We found something if we've arrived at the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1929 ;; target depth.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1930 (if (and dchange (= depth target-depth))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1931 (setq found (point))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1932 ;; else
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
1933 (if forward (forward-line 1)))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1934 (or found
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1935 (error "No containing preprocessor conditional"))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1936 (goto-char (setq new found)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1937 (setq count (+ count increment))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1938 (push-mark)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1939 (goto-char new))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1940 (c-keep-region-active))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1941
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1942
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1943 ;; 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
1944 (defun c-indent-command (&optional arg)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1945 "Indent current line as C code, and/or insert some whitespace.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1946
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1947 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
1948 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
1949 in the line's indentation; otherwise insert some whitespace[*]. If
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1950 other than nil or t, then some whitespace[*] is inserted only within
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1951 literals (comments and strings) and inside preprocessor directives,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1952 but the line is always reindented.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1953
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1954 If `c-syntactic-indentation' is t, indentation is done according to
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1955 the syntactic context. A numeric argument, regardless of its value,
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1956 means indent rigidly all the lines of the expression starting after
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1957 point so that this line becomes properly indented. The relative
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1958 indentation among the lines of the expression is preserved.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1959
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1960 If `c-syntactic-indentation' is nil, the line is just indented one
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1961 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
1962 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
1963 prefix argument is equivalent to -1.
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1964
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1965 [*] The amount and kind of whitespace inserted is controlled by the
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1966 variable `c-insert-tab-function', which is called to do the actual
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1967 insertion of whitespace. Normally the function in this variable
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1968 just inserts a tab character, or the equivalent number of spaces,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1969 depending on the variable `indent-tabs-mode'."
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1970
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1971 (interactive "p")
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1972 (let ((indent-function
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1973 (if c-syntactic-indentation
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1974 (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
1975 (lambda ()
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1976 (let ((c-macro-start c-macro-start)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1977 (steps (cond ((not current-prefix-arg) 1)
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1978 ((equal current-prefix-arg '(4)) -1)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1979 (t arg))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1980 (c-shift-line-indentation (* steps c-basic-offset))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1981 (when (and c-auto-align-backslashes
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1982 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1983 (end-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1984 (eq (char-before) ?\\))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1985 (c-query-and-set-macro-start))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1986 ;; Realign the line continuation backslash if inside a macro.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
1987 (c-backslash-region (point) (point) nil t)))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1988 ))))
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
1989 (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
1990 ;; 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
1991 ;; 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
1992 ;; amount.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1993 (let ((shift-amt (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1994 (back-to-indentation)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1995 (current-column)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1996 beg end)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1997 (c-indent-line)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1998 (setq shift-amt (- (save-excursion
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
1999 (back-to-indentation)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2000 (current-column))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2001 shift-amt))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2002 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2003 (if (eq c-tab-always-indent t)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2004 (beginning-of-line))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2005 (setq beg (point))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
2006 (c-forward-sexp 1)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2007 (setq end (point))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2008 (goto-char beg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2009 (forward-line 1)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2010 (setq beg (point)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2011 (if (> end beg)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2012 (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
2013 ;; Else use c-tab-always-indent to determine behavior.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2014 (cond
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2015 ;; CASE 1: indent when at column zero or in lines indentation,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2016 ;; otherwise insert a tab
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2017 ((not c-tab-always-indent)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2018 (if (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2019 (skip-chars-backward " \t")
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2020 (not (bolp)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2021 (funcall c-insert-tab-function)
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2022 (funcall indent-function)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2023 ;; CASE 2: just indent the line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2024 ((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
2025 (funcall indent-function))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2026 ;; 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
2027 ;; line
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2028 (t
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2029 (if (c-in-literal)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2030 (funcall c-insert-tab-function))
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
2031 (funcall indent-function)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2032 )))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2033
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2034 (defun c-indent-exp (&optional shutup-p)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2035 "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
2036 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
2037 balanced expression is found."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
2038 (interactive "*P")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2039 (let ((here (point-marker))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2040 end)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2041 (set-marker-insertion-type here t)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2042 (unwind-protect
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2043 (let ((start (save-restriction
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2044 ;; Find the closest following open paren that
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2045 ;; ends on another line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2046 (narrow-to-region (point-min) (c-point 'eol))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2047 (let (beg (end (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2048 (while (and (setq beg (c-down-list-forward end))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2049 (setq end (c-up-list-forward beg))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2050 (and beg
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2051 (eq (char-syntax (char-before beg)) ?\()
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2052 (1- beg))))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2053 ;; sanity check
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2054 (if (not start)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2055 (unless shutup-p
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2056 (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
2057 (goto-char start)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2058 (setq end (c-safe (scan-sexps (point) 1)))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2059 (if (not end)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2060 (unless shutup-p
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2061 (error "Cannot find end of balanced expression to indent"))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2062 (forward-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2063 (if (< (point) end)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2064 (c-indent-region (point) end)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2065 (goto-char here)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2066 (set-marker here nil))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2067
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2068 (defun c-indent-defun ()
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2069 "Indent the current top-level declaration or macro syntactically.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2070 In the macro case this also has the effect of realigning any line
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2071 continuation backslashes, unless `c-auto-align-backslashes' is nil."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
2072 (interactive "*")
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2073 (let ((here (point-marker)) decl-limits)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2074 ;; We try to be line oriented, unless there are several
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2075 ;; declarations on the same line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2076 (if (looking-at c-syntactic-eol)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2077 (c-backward-token-1 1 nil (c-point 'bol))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2078 (c-forward-token-1 0 nil (c-point 'eol)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2079 (unwind-protect
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2080 (if (setq decl-limits (c-declaration-limits nil))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2081 (c-indent-region (car decl-limits)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2082 (cdr decl-limits)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2083 (goto-char here)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2084 (set-marker here nil))))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2085
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2086 (defun c-indent-region (start end &optional quiet)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2087 "Indent syntactically every line whose first char is between START
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2088 and END inclusive. If the optional argument QUIET is non-nil then no
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2089 syntactic errors are reported, even if `c-report-syntactic-errors' is
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2090 non-nil."
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2091 (save-excursion
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2092 (goto-char end)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2093 (skip-chars-backward " \t\n\r")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2094 (setq end (point))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2095 (goto-char start)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2096 ;; Advance to first nonblank line.
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2097 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2098 (skip-chars-forward " \t\n\r")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2099 (setq start (point))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2100 (beginning-of-line)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2101 (setq c-parsing-error
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2102 (or (let ((endmark (copy-marker end))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2103 (c-parsing-error nil)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2104 ;; shut up any echo msgs on indiv lines
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2105 (c-echo-syntactic-information-p nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2106 (in-macro (and c-auto-align-backslashes
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2107 (save-excursion (c-beginning-of-macro))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2108 start))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2109 (c-fix-backslashes nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2110 syntax)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2111 (unwind-protect
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2112 (progn
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2113 (c-progress-init start end 'c-indent-region)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2114 (while (and (bolp)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2115 (not (eobp))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2116 (< (point) endmark))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2117 ;; update progress
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2118 (c-progress-update)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2119 ;; skip empty lines
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2120 (skip-chars-forward " \t\n")
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2121 (beginning-of-line)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2122 ;; Get syntax and indent.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2123 (setq syntax (c-guess-basic-syntax))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2124 (if (and c-auto-align-backslashes
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2125 (assq 'cpp-macro syntax))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2126 ;; Record macro start.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2127 (setq in-macro (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2128 (if in-macro
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2129 (if (looking-at "\\s *\\\\$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2130 (forward-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2131 (c-indent-line syntax t t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2132 (if (progn (end-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2133 (not (eq (char-before) ?\\)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2134 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2135 ;; Fixup macro backslashes.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2136 (forward-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2137 (c-backslash-region in-macro (point) nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2138 (setq in-macro nil))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2139 (forward-line)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2140 (c-indent-line syntax t t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2141 (forward-line)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2142 (if in-macro
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2143 (c-backslash-region in-macro (c-point 'bopl) nil t)))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2144 (set-marker endmark nil)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2145 (c-progress-fini 'c-indent-region))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2146 (c-echo-parsing-error quiet))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2147 c-parsing-error))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2148
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2149 (defun c-fn-region-is-active-p ()
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2150 ;; 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
2151 ;; compiled, e.g. in the menus.
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2152 (c-region-is-active-p))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2153
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
2154 (defun c-indent-line-or-region ()
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2155 "When the region is active, indent it syntactically. Otherwise
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2156 indent the current line syntactically."
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
2157 ;; 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
2158 (interactive)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
2159 (if (c-region-is-active-p)
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
2160 (c-indent-region (region-beginning) (region-end))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2161 (c-indent-line)))
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
2162
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2163
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2164 ;; for progress reporting
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2165 (defvar c-progress-info nil)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2166
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2167 (defun c-progress-init (start end context)
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2168 (cond
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2169 ;; Be silent
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2170 ((not c-progress-interval))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2171 ;; 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
2172 ;; 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
2173 ((not (fboundp 'current-time))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2174 (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
2175 ;; 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
2176 ;; initialize the counter with a vector of:
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2177 ;; [start end lastsec context]
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2178 (c-progress-info)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2179 (t (setq c-progress-info (vector start
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2180 (save-excursion
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2181 (goto-char end)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2182 (point-marker))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2183 (nth 1 (current-time))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2184 context))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2185 (message "Indenting region..."))
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2186 ))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2187
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2188 (defun c-progress-update ()
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2189 ;; update progress
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2190 (if (not (and c-progress-info c-progress-interval))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2191 nil
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2192 (let ((now (nth 1 (current-time)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2193 (start (aref c-progress-info 0))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2194 (end (aref c-progress-info 1))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2195 (lastsecs (aref c-progress-info 2)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2196 ;; should we update? currently, update happens every 2 seconds,
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2197 ;; what's the right value?
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2198 (if (< c-progress-interval (- now lastsecs))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2199 (progn
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2200 (message "Indenting region... (%d%% complete)"
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2201 (/ (* 100 (- (point) start)) (- end start)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2202 (aset c-progress-info 2 now)))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2203 )))
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2204
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2205 (defun c-progress-fini (context)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2206 ;; finished
20143
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2207 (if (not c-progress-interval)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2208 nil
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2209 (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
2210 (eq context t))
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2211 (progn
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2212 (set-marker (aref c-progress-info 1) nil)
69ce7b7acfd5 (c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents: 20137
diff changeset
2213 (setq c-progress-info nil)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2214 (message "Indenting region... done")))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2215
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2216
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2217
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2218 ;;; This page handles insertion and removal of backslashes for C macros.
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2219
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2220 (defun c-backslash-region (from to delete-flag &optional line-mode)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2221 "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
2222 With no argument, inserts backslashes and aligns existing backslashes.
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2223 With an argument, deletes the backslashes. The backslash alignment is
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2224 done according to the settings in `c-backslash-column',
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2225 `c-backslash-max-column' and `c-auto-align-backslashes'.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2226
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2227 This function does not modify blank lines at the start of the region.
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2228 If the region ends at the start of a line and the macro doesn't
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2229 continue below it, the backslash (if any) at the end of the previous
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2230 line is deleted.
24282
5b0864259a4b Installed CC Mode 5.25.
Barry A. Warsaw <barry@zope.org>
parents: 21107
diff changeset
2231
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2232 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
2233 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
2234 (interactive "*r\nP")
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2235 (let ((endmark (make-marker))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2236 ;; Keep the backslash trimming functions from changing the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2237 ;; whitespace around point, since in this case it's only the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2238 ;; position of point that tells the indentation of the line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2239 (point-pos (if (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2240 (skip-chars-backward " \t")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2241 (and (bolp) (looking-at "[ \t]*\\\\?$")))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2242 (point-marker)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2243 (point-min)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2244 column longest-line-col bs-col-after-end)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2245 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2246 (goto-char to)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2247 (if (and (not line-mode) (bobp))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2248 ;; Nothing to do if to is at bob, since we should back up
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2249 ;; and there's no line to back up to.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2250 nil
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2251 (when (and (not line-mode) (bolp))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2252 ;; Do not back up the to line if line-mode is set, to make
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2253 ;; e.g. c-newline-and-indent consistent regardless whether
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2254 ;; the (newline) call leaves point at bol or not.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2255 (backward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2256 (setq to (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2257 (if delete-flag
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2258 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2259 (set-marker endmark (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2260 (goto-char from)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2261 (c-delete-backslashes-forward endmark point-pos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2262 ;; Set bs-col-after-end to the column of any backslash
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2263 ;; following the region, or nil if there is none.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2264 (setq bs-col-after-end
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2265 (and (progn (end-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2266 (eq (char-before) ?\\))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2267 (= (forward-line 1) 0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2268 (progn (end-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2269 (eq (char-before) ?\\))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2270 (1- (current-column))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2271 (when line-mode
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2272 ;; Back up the to line if line-mode is set, since the line
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2273 ;; after the newly inserted line break should not be
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2274 ;; touched in c-newline-and-indent.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2275 (setq to (max from (or (c-safe (c-point 'eopl)) from)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2276 (unless bs-col-after-end
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2277 ;; Set bs-col-after-end to non-nil in any case, since we
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2278 ;; do not want to delete the backslash at the last line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2279 (setq bs-col-after-end t)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2280 (if (and line-mode
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2281 (not c-auto-align-backslashes))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2282 (goto-char from)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2283 ;; Compute the smallest column number past the ends of all
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2284 ;; the lines.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2285 (setq longest-line-col 0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2286 (goto-char to)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2287 (if bs-col-after-end
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2288 ;; Include one more line in the max column
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2289 ;; calculation, since the to line will be backslashed
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2290 ;; too.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2291 (forward-line 1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2292 (end-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2293 (while (and (>= (point) from)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2294 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2295 (if (eq (char-before) ?\\)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2296 (forward-char -1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2297 (skip-chars-backward " \t")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2298 (setq longest-line-col (max longest-line-col
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2299 (1+ (current-column))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2300 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2301 (not (bobp))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2302 (backward-char))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2303 ;; Try to align with surrounding backslashes.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2304 (goto-char from)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2305 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2306 (if (and (not (bobp))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2307 (progn (backward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2308 (eq (char-before) ?\\)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2309 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2310 (setq column (1- (current-column)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2311 (if (numberp bs-col-after-end)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2312 ;; Both a preceding and a following backslash.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2313 ;; Choose the greatest of them.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2314 (setq column (max column bs-col-after-end)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2315 (goto-char from))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2316 ;; No preceding backslash. Try to align with one
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2317 ;; following the region. Disregard the backslash at the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2318 ;; to line since it's likely to be bogus (e.g. when
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2319 ;; called from c-newline-and-indent).
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2320 (if (numberp bs-col-after-end)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2321 (setq column bs-col-after-end))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2322 ;; Don't modify blank lines at start of region.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2323 (goto-char from)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2324 (while (and (< (point) to) (bolp) (eolp))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2325 (forward-line 1)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2326 (if (and column (< column longest-line-col))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2327 ;; Don't try to align with surrounding backslashes if
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2328 ;; any line is too long.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2329 (setq column nil))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2330 (unless column
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2331 ;; Impose minimum limit and tab width alignment only if
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2332 ;; we can't align with surrounding backslashes.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2333 (if (> (% longest-line-col tab-width) 0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2334 (setq longest-line-col
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2335 (* (/ (+ longest-line-col tab-width -1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2336 tab-width)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2337 tab-width)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2338 (setq column (max c-backslash-column
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2339 longest-line-col)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2340 ;; Always impose maximum limit.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2341 (setq column (min column c-backslash-max-column)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2342 (if bs-col-after-end
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2343 ;; Add backslashes on all lines if the macro continues
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2344 ;; after the to line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2345 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2346 (set-marker endmark to)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2347 (c-append-backslashes-forward endmark column point-pos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2348 ;; Add backslashes on all lines except the last, and
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2349 ;; remove any on the last line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2350 (if (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2351 (goto-char to)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2352 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2353 (if (not (bobp))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2354 (set-marker endmark (1- (point)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2355 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2356 (c-append-backslashes-forward endmark column point-pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2357 ;; The function above leaves point on the line
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2358 ;; following endmark.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2359 (set-marker endmark (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2360 (set-marker endmark to))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2361 (c-delete-backslashes-forward endmark point-pos)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2362 (set-marker endmark nil)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2363 (if (markerp point-pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2364 (set-marker point-pos nil))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2365
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2366 (defun c-append-backslashes-forward (to-mark column point-pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2367 (let ((state (parse-partial-sexp (c-point 'bol) (point))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2368 (if column
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2369 (while
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2370 (and
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2371 (<= (point) to-mark)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2372
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2373 (let ((start (point)) (inserted nil) end col)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2374 (end-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2375 (unless (eq (char-before) ?\\)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2376 (insert ?\\)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2377 (setq inserted t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2378 (setq state (parse-partial-sexp
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2379 start (point) nil nil state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2380 (backward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2381 (setq col (current-column))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2382
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2383 ;; Avoid unnecessary changes of the buffer.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2384 (cond ((and (not inserted) (nth 3 state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2385 ;; Don't realign backslashes in string literals
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2386 ;; since that would change them.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2387 )
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2388
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2389 ((< col column)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2390 (delete-region
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2391 (point)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2392 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2393 (skip-chars-backward
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2394 " \t" (if (>= (point) point-pos) point-pos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2395 (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2396 (indent-to column))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2397
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2398 ((and (= col column)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2399 (memq (char-before) '(?\ ?\t))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2400
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2401 ((progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2402 (setq end (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2403 (or (/= (skip-chars-backward
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2404 " \t" (if (>= (point) point-pos) point-pos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2405 -1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2406 (/= (char-after) ?\ )))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2407 (delete-region (point) end)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2408 (indent-to column 1)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2409
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2410 (= (forward-line 1) 0))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2411
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2412 ;; Make sure there are backslashes with at least one space in
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2413 ;; front of them.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2414 (while
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2415 (and
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2416 (<= (point) to-mark)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2417
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2418 (let ((start (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2419 (end-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2420 (setq state (parse-partial-sexp
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2421 start (point) nil nil state))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2422
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2423 (if (eq (char-before) ?\\)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2424 (unless (nth 3 state)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2425 (backward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2426 (unless (and (memq (char-before) '(?\ ?\t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2427 (/= (point) point-pos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2428 (insert ?\ )))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2429
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2430 (if (and (memq (char-before) '(?\ ?\t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2431 (/= (point) point-pos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2432 (insert ?\\)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2433 (insert ?\ ?\\)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2434
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2435 (= (forward-line 1) 0)))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2436
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2437 (defun c-delete-backslashes-forward (to-mark point-pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2438 (while
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2439 (and (<= (point) to-mark)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2440 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2441 (end-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2442 (if (eq (char-before) ?\\)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2443 (delete-region
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2444 (point)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2445 (progn (backward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2446 (skip-chars-backward " \t" (if (>= (point) point-pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2447 point-pos))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2448 (point))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2449 (= (forward-line 1) 0)))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2450
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2451
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2452
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2453 ;;; Line breaking and paragraph filling.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2454
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2455 (defvar c-auto-fill-prefix t)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2456 (defvar c-lit-limits nil)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2457 (defvar c-lit-type nil)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2458
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2459 ;; 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
2460 ;; 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
2461 ;; (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
2462 ;; 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
2463 ;; separators, one-line paragraphs etc. Unfortunately, when it comes
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2464 ;; 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
2465 ;; 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
2466 ;; 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
2467 ;; prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2468 ;;
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2469 ;; We temporarily mask comment starters and enders as necessary for
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2470 ;; 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
2471 ;; 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
2472 ;; preserve it correctly (especially important when filling C++ style
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2473 ;; 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
2474 ;; which is standard in all supported Emacs flavors.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2475
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2476 (defun c-guess-fill-prefix (lit-limits lit-type)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2477 ;; 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
2478 ;; 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
2479 ;; 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
2480 ;; function also uses the value of point in some heuristics.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2481 (let* ((here (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2482 (prefix-regexp (concat "[ \t]*\\("
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2483 c-current-comment-prefix
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2484 "\\)[ \t]*"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2485 (comment-start-regexp (if (eq lit-type 'c++)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2486 prefix-regexp
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2487 comment-start-skip))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2488 prefix-line comment-prefix res comment-text-end)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2489 (cond
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2490 (fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2491 (setq res (cons fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2492 ;; Ugly way of getting the column after the fill
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2493 ;; prefix; it'd be nice with a current-column
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2494 ;; that works on strings..
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2495 (let ((buffer-modified (buffer-modified-p))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2496 (buffer-undo-list t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2497 (start (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2498 (unwind-protect
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2499 (progn
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2500 (insert-and-inherit "\n" fill-prefix)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2501 (current-column))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2502 (delete-region start (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2503 (set-buffer-modified-p buffer-modified))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2504 ((eq lit-type 'c++)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2505 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2506 ;; 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
2507 (setq comment-prefix "// "
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2508 comment-text-end (cdr lit-limits))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2509 (beginning-of-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2510 (if (> (point) (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2511 ;; The current line is not the comment starter, so the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2512 ;; 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
2513 ;; used to find the comment fill prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2514 (setq prefix-line (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2515 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2516 (if (and (= (forward-line 1) 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2517 (< (point) (cdr lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2518 ;; The line after the comment starter is inside the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2519 ;; comment, so we can use it.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2520 (setq prefix-line (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2521 ;; The comment is only one line. Take the comment prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2522 ;; from it and keep the indentation.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2523 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2524 (if (looking-at prefix-regexp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2525 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2526 (forward-char 2)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2527 (skip-chars-forward " \t"))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2528 (let (str col)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2529 (if (eq (c-point 'boi) (car lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2530 ;; There is only whitespace before the comment
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2531 ;; starter; take the prefix straight from this line.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2532 (setq str (buffer-substring-no-properties
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2533 (c-point 'bol) (point))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2534 col (current-column))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2535 ;; There is code before the comment starter, so we
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2536 ;; have to temporarily insert and indent a new line to
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2537 ;; get the right space/tab mix in the indentation.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2538 (let ((buffer-modified (buffer-modified-p))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2539 (buffer-undo-list t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2540 (prefix-len (- (point) (car lit-limits)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2541 tmp)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2542 (unwind-protect
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2543 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2544 (goto-char (car lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2545 (indent-to (prog1 (current-column)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2546 (insert ?\n)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2547 (setq tmp (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2548 (forward-char prefix-len)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2549 (setq str (buffer-substring-no-properties
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2550 (c-point 'bol) (point))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2551 col (current-column)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2552 (delete-region (car lit-limits) tmp)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2553 (set-buffer-modified-p buffer-modified))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2554 (setq res
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2555 (if (or (string-match "\\s \\'" str) (not (eolp)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2556 (cons str col)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2557 ;; The prefix ends the line with no whitespace
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2558 ;; after it. Default to a single space.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2559 (cons (concat str " ") (1+ col))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2560 )))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2561 (t
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2562 (setq comment-text-end
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2563 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2564 (goto-char (- (cdr lit-limits) 2))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2565 (if (looking-at "\\*/") (point) (cdr lit-limits))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2566 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2567 (beginning-of-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2568 (if (and (> (point) (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2569 (not (and (looking-at "[ \t]*\\*/")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2570 (eq (cdr lit-limits) (match-end 0)))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2571 ;; The current line is not the comment starter and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2572 ;; 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
2573 ;; to be used for the comment fill prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2574 (setq prefix-line (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2575 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2576 (if (or (/= (forward-line 1) 0)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2577 (>= (point) (cdr lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2578 (and (looking-at "[ \t]*\\*/")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2579 (eq (cdr lit-limits) (match-end 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2580 (and (looking-at prefix-regexp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2581 (<= (1- (cdr lit-limits)) (match-end 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2582 (and (< here (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2583 (or (not (match-beginning 0))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2584 (looking-at "[ \t]*\\\\?$"))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2585 ;; The comment is either one line or the next line
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2586 ;; contains just the comment ender. Also, if point is
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2587 ;; 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
2588 ;; 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
2589 ;; 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
2590 ;; comment, so we shouldn't look for the comment prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2591 ;; on the next line. In these cases we have no
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2592 ;; information about a suitable comment prefix, so we
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2593 ;; resort to c-block-comment-prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2594 (setq comment-prefix (or c-block-comment-prefix "")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2595 res (let ((buffer-modified (buffer-modified-p))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2596 (buffer-undo-list t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2597 tmp-pre tmp-post)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2598 ;; The comment doesn't give any information
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2599 ;; about the indentation column. We'll have to
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2600 ;; temporarily insert a new comment line and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2601 ;; indent it to find the correct column.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2602 (unwind-protect
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2603 (progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2604 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2605 (if (looking-at comment-start-regexp)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2606 (goto-char (min (match-end 0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2607 comment-text-end))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2608 (forward-char 2)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2609 (skip-chars-forward " \t"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2610 (when (eq (char-syntax (char-before)) ?\ )
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2611 ;; If there's ws on the current
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2612 ;; line, we'll use it instead of
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2613 ;; what's ending comment-prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2614 (setq comment-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2615 (concat (substring comment-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2616 0 (string-match
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2617 "\\s *\\'"
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2618 comment-prefix))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2619 (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2620 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2621 (skip-chars-backward " \t")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2622 (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2623 (point)))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2624 (setq tmp-pre (point-marker))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2625 ;; We insert an extra non-whitespace
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2626 ;; character before the line break and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2627 ;; after comment-prefix in case it's
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2628 ;; "" or ends with whitespace.
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2629 (insert-and-inherit "x\n" comment-prefix "x")
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2630 (setq tmp-post (point-marker))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2631 (indent-according-to-mode)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2632 (goto-char (1- tmp-post))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2633 (cons (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2634 (c-point 'bol) (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2635 (current-column)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2636 (when tmp-post
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2637 (delete-region tmp-pre tmp-post)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2638 (set-marker tmp-pre nil)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2639 (set-marker tmp-post nil))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2640 (set-buffer-modified-p buffer-modified))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2641 ;; Otherwise the line after the comment starter is good
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2642 ;; enough to find the prefix in.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2643 (setq prefix-line (point)))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2644 (or res
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2645 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2646 ;; 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
2647 ;; to find the prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2648 (let* (fb-string fb-endpos ; Contains any fallback prefix found.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2649 (test-line
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2650 (lambda ()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2651 (when (and (looking-at prefix-regexp)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2652 (<= (match-end 0) comment-text-end))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2653 (unless (eq (match-end 0) (c-point 'eol))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2654 ;; 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
2655 (throw 'found (cons (buffer-substring-no-properties
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2656 (match-beginning 0) (match-end 0))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2657 (progn (goto-char (match-end 0))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2658 (current-column)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2659 (unless fb-string
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2660 ;; This match is better than nothing, so let's
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2661 ;; remember it in case nothing better is found
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2662 ;; on another line.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2663 (setq fb-string (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2664 (match-beginning 0) (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2665 fb-endpos (match-end 0)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2666 t))))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2667 (or (catch 'found
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2668 ;; Search for a line which has text after the prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2669 ;; so that we get the proper amount of whitespace
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2670 ;; after it. We start with the current line, then
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2671 ;; search backwards, then forwards.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2672 (goto-char prefix-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2673 (when (and (funcall test-line)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2674 (or (/= (match-end 1) (match-end 0))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2675 ;; The whitespace is sucked up by the
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2676 ;; first [ \t]* glob if the prefix is empty.
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2677 (and (= (match-beginning 1) (match-end 1))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2678 (/= (match-beginning 0) (match-end 0)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2679 ;; If the current line doesn't have text but do
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2680 ;; 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
2681 (throw 'found (cons fb-string
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2682 (progn (goto-char fb-endpos)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2683 (current-column)))))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2684 (if (eq lit-type 'c++)
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2685 ;; For line comments we can search up to and
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2686 ;; including the first line.
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2687 (while (and (zerop (forward-line -1))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2688 (>= (point) (car lit-limits)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2689 (funcall test-line))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2690 ;; For block comments we must stop before the
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2691 ;; block starter.
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2692 (while (and (zerop (forward-line -1))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2693 (> (point) (car lit-limits)))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2694 (funcall test-line)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2695 (goto-char prefix-line)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2696 (while (and (zerop (forward-line 1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2697 (< (point) (cdr lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2698 (funcall test-line))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2699 (goto-char prefix-line)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2700 nil)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2701 (when fb-string
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2702 ;; 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
2703 ;; fallback that matches the comment prefix regexp.
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2704 (cond ((or (string-match "\\s \\'" fb-string)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2705 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2706 (goto-char fb-endpos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2707 (not (eolp))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2708 ;; There are ws or text after the prefix, so
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2709 ;; let's use it.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2710 (cons fb-string (current-column)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2711 ((progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2712 ;; Check if there's any whitespace padding
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2713 ;; on the comment start line that we can
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2714 ;; use after the prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2715 (goto-char (car lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2716 (if (looking-at comment-start-regexp)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2717 (goto-char (match-end 0))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2718 (forward-char 2)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2719 (skip-chars-forward " \t"))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2720 (or (not (eolp))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2721 (eq (char-syntax (char-before)) ?\ )))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2722 (setq fb-string (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2723 (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2724 (skip-chars-backward " \t")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2725 (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2726 (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2727 (goto-char fb-endpos)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2728 (skip-chars-backward " \t")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2729 (let ((buffer-modified (buffer-modified-p))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2730 (buffer-undo-list t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2731 (tmp (point)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2732 ;; Got to mess in the buffer once again to
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2733 ;; ensure the column gets correct. :P
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2734 (unwind-protect
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2735 (progn
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2736 (insert-and-inherit fb-string)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2737 (cons (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2738 (c-point 'bol)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2739 (point))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2740 (current-column)))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2741 (delete-region tmp (point))
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2742 (set-buffer-modified-p buffer-modified))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2743 (t
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2744 ;; Last resort: Just add a single space after
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2745 ;; the prefix.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2746 (cons (concat fb-string " ")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2747 (progn (goto-char fb-endpos)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2748 (1+ (current-column)))))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2749 ;; The line doesn't match the comment prefix regexp.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2750 (if comment-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2751 ;; 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
2752 (cons (concat (buffer-substring-no-properties
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2753 prefix-line (c-point 'boi))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2754 comment-prefix)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2755 (progn (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2756 (+ (current-column) (length comment-prefix))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2757 ;; Assume we are dealing with a "free text" block
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2758 ;; comment where the lines doesn't have any comment
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2759 ;; prefix at all and we should just fill it as
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2760 ;; normal text.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
2761 '("" . 0))))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2762 ))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
2763
44802
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2764 (defun c-mask-comment (fill-paragraph apply-outside-literal fun &rest args)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2765 ;; Calls FUN with ARGS ar arguments. If point is inside a comment,
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2766 ;; the comment starter and ender are masked and the buffer is
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2767 ;; narrowed to make it look like a normal paragraph during the call.
44802
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2768 ;;
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2769 ;; FILL-PARAGRAPH is non-nil if called for paragraph filling. The
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2770 ;; position of point is then less significant when doing masking and
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2771 ;; narrowing.
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2772 (let (fill
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2773 ;; beg and end limits the region to narrow. end is a marker.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2774 beg end
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2775 ;; tmp-pre and tmp-post mark strings that are temporarily
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2776 ;; inserted at the start and end of the region. tmp-pre is a
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2777 ;; cons of the positions of the prepended string. tmp-post is
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2778 ;; a marker pointing to the single character of the appended
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2779 ;; string.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2780 tmp-pre tmp-post
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2781 ;; If hang-ender-stuck isn't nil, the comment ender is
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2782 ;; hanging. In that case it's set to the number of spaces
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2783 ;; that should be between the text and the ender.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2784 hang-ender-stuck
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2785 (here (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2786 (c-lit-limits c-lit-limits)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2787 (c-lit-type c-lit-type))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2788 ;; Restore point on undo. It's necessary since we do a lot of
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2789 ;; hidden inserts and deletes below that should be as transparent
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2790 ;; as possible.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2791 (if (and buffer-undo-list (not (eq buffer-undo-list t)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2792 (setq buffer-undo-list (cons (point) buffer-undo-list)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2793 (save-restriction
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2794 ;; Widen to catch comment limits correctly.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2795 (widen)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2796 (unless c-lit-limits
44802
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2797 (setq c-lit-limits (c-literal-limits nil fill-paragraph)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2798 (setq c-lit-limits (c-collect-line-comments c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2799 (unless c-lit-type
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2800 (setq c-lit-type (c-literal-type c-lit-limits))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2801 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2802 (unless (c-safe (backward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2803 (forward-paragraph)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2804 (>= (point) here))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2805 (goto-char here)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2806 (forward-paragraph))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2807 (setq end (point-marker)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2808 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2809 (unless (c-safe (forward-char)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2810 (backward-paragraph)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2811 (<= (point) here))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2812 (goto-char here)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2813 (backward-paragraph))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2814 (setq beg (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2815 (unwind-protect
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2816 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2817 (cond
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2818 ((eq c-lit-type 'c++) ; Line comment.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2819 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2820 ;; Limit to the comment or paragraph end, whichever
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2821 ;; comes first.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2822 (set-marker end (min end (cdr c-lit-limits)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2823 (when (<= beg (car c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2824 ;; The region includes the comment starter, so we must
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2825 ;; check it.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2826 (goto-char (car c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2827 (back-to-indentation)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2828 (if (eq (point) (car c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2829 ;; Include the first line in the region.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2830 (setq beg (c-point 'bol))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2831 ;; The first line contains code before the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2832 ;; comment. We must fake a line that doesn't.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2833 (setq tmp-pre t)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2834 ))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2835 ((eq c-lit-type 'c) ; Block comment.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2836 (when (>= end (cdr c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2837 ;; The region includes the comment ender which we might
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2838 ;; want to keep together with the last word.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2839 (unless (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2840 (goto-char (cdr c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2841 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2842 (and (looking-at (concat "[ \t]*\\("
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2843 c-current-comment-prefix
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2844 "\\)\\*/"))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2845 (eq (cdr c-lit-limits) (match-end 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2846 ;; Leave the comment ender on its own line.
44802
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2847 (set-marker end (point))))
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2848 (when fill-paragraph
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2849 ;; The comment ender should hang. Replace all cruft
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2850 ;; between it and the last word with one or two 'x'
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2851 ;; and include it in the region. We'll change them
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2852 ;; back to spaces afterwards.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2853 (let* ((ender-start (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2854 (goto-char (cdr c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2855 (skip-syntax-backward "^w ")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2856 (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2857 (point-rel (- ender-start here))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2858 spaces)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2859 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2860 (goto-char (cdr c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2861 (setq tmp-post (point-marker))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2862 (insert ?\n)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2863 (set-marker end (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2864 (forward-line -1)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2865 (if (and (looking-at (concat "[ \t]*\\(\\("
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2866 c-current-comment-prefix
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2867 "\\)[ \t]*\\)"))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2868 (eq ender-start (match-end 0)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2869 ;; The comment ender is prefixed by nothing
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2870 ;; but a comment line prefix. Remove it
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2871 ;; along with surrounding ws.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2872 (setq spaces (- (match-end 1) (match-end 2)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2873 (goto-char ender-start))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2874 (skip-chars-backward " \t\r\n")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2875 (if (/= (point) ender-start)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2876 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2877 (if (<= here (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2878 ;; Don't adjust point below if it's
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2879 ;; before the string we replace.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2880 (setq point-rel -1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2881 ;; Keep one or two spaces between the text and
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2882 ;; the ender, depending on how many there are now.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2883 (unless spaces
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2884 (setq spaces (- ender-start (point))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2885 (setq spaces
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2886 (max (min spaces
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2887 (if sentence-end-double-space 2 1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2888 1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2889 ;; Insert the filler first to keep marks right.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2890 (insert-char ?x spaces t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2891 (delete-region (point) (+ ender-start spaces))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2892 (setq hang-ender-stuck spaces)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2893 (setq point-rel
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2894 (and (>= point-rel 0)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2895 (- (point) (min point-rel spaces)))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2896 (setq point-rel nil)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2897 (if point-rel
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2898 ;; Point was in the middle of the string we
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2899 ;; replaced above, so put it back in the same
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2900 ;; relative position, counting from the end.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2901 (goto-char point-rel))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2902 ))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2903 (when (<= beg (car c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2904 ;; The region includes the comment starter.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2905 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2906 (goto-char (car c-lit-limits))
44802
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2907 (if (looking-at (concat "\\(" comment-start-skip "\\)$"))
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2908 ;; Begin with the next line.
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2909 (setq beg (c-point 'bonl))
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2910 ;; Fake the fill prefix in the first line.
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2911 (setq tmp-pre t)))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2912 ((eq c-lit-type 'string) ; String.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2913 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2914 (when (>= end (cdr c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2915 (goto-char (1- (cdr c-lit-limits)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2916 (setq tmp-post (point-marker))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2917 (insert ?\n)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2918 (set-marker end (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2919 (when (<= beg (car c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2920 (goto-char (1+ (car c-lit-limits)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2921 (setq beg (if (looking-at "\\\\$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2922 ;; Leave the start line if it's
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2923 ;; nothing but an escaped newline.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2924 (1+ (match-end 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2925 (point))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2926 (t (setq beg nil)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2927 (when tmp-pre
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2928 ;; Temporarily insert the fill prefix after the comment
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2929 ;; starter so that the first line looks like any other
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2930 ;; comment line in the narrowed region.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2931 (setq fill (c-guess-fill-prefix c-lit-limits c-lit-type))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2932 (unless (string-match (concat "\\`[ \t]*\\("
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2933 c-current-comment-prefix
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2934 "\\)[ \t]*\\'")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2935 (car fill))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2936 ;; Oops, the prefix doesn't match the comment prefix
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2937 ;; regexp. This could produce very confusing
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2938 ;; results with adaptive fill packages together with
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2939 ;; the insert prefix magic below, since the prefix
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2940 ;; often doesn't appear at all. So let's warn about
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2941 ;; it.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2942 (message "\
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2943 Warning: Regexp from `c-comment-prefix-regexp' doesn't match the comment prefix %S"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2944 (car fill)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2945 ;; Find the right spot on the line, break it, insert
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2946 ;; the fill prefix and make sure we're back in the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2947 ;; same column by temporarily prefixing the first word
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2948 ;; with a number of 'x'.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2949 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2950 (goto-char (car c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2951 (if (looking-at (if (eq c-lit-type 'c++)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2952 c-current-comment-prefix
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2953 comment-start-skip))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2954 (goto-char (match-end 0))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2955 (forward-char 2)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2956 (skip-chars-forward " \t"))
44799
4c09bfb5fbbf (c-mask-comment): More fixes when used from `c-do-auto-fill' and point
Martin Stjernholm <mast@lysator.liu.se>
parents: 44755
diff changeset
2957 (while (and (< (current-column) (cdr fill))
4c09bfb5fbbf (c-mask-comment): More fixes when used from `c-do-auto-fill' and point
Martin Stjernholm <mast@lysator.liu.se>
parents: 44755
diff changeset
2958 (not (eolp)))
4c09bfb5fbbf (c-mask-comment): More fixes when used from `c-do-auto-fill' and point
Martin Stjernholm <mast@lysator.liu.se>
parents: 44755
diff changeset
2959 (forward-char 1))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2960 (let ((col (current-column)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2961 (setq beg (1+ (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2962 tmp-pre (list (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2963 (unwind-protect
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2964 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2965 (insert-and-inherit "\n" (car fill))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2966 (insert-char ?x (- col (current-column)) t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2967 (setcdr tmp-pre (point))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2968 (if beg
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2969 (let ((fill-prefix
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2970 (or fill-prefix
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2971 ;; Kludge: If the function that adapts the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2972 ;; fill prefix doesn't produce the required
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2973 ;; comment starter for line comments, then
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2974 ;; force it by setting fill-prefix.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2975 (when (and (eq c-lit-type 'c++)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2976 ;; Kludge the kludge:
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2977 ;; filladapt-mode doesn't have
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2978 ;; this problem, but it doesn't
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2979 ;; override fill-context-prefix
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2980 ;; currently (version 2.12).
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2981 (not (and (boundp 'filladapt-mode)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2982 filladapt-mode))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2983 (not (string-match
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2984 "\\`[ \t]*//"
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2985 (or (fill-context-prefix beg end)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2986 ""))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2987 (car (or fill (c-guess-fill-prefix
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2988 c-lit-limits c-lit-type))))))
44802
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2989 ;; Save the relative position of point if it's
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2990 ;; outside the region we're going to narrow. Want
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2991 ;; to restore it in that case, but otherwise it
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2992 ;; should be moved according to the called
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2993 ;; function.
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2994 (point-rel (cond ((< (point) beg) (- (point) beg))
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
2995 ((> (point) end) (- (point) end)))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2996 ;; Preparations finally done! Now we can call the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2997 ;; actual function.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2998 (prog1
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
2999 (save-restriction
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3000 (narrow-to-region beg end)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3001 (apply fun args))
44802
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
3002 (if point-rel
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
3003 ;; Restore point if it was outside the region.
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
3004 (if (< point-rel 0)
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
3005 (goto-char (+ beg point-rel))
cb8f23e350ff (c-mask-comment): A better way to ensure point doesn't move around
Martin Stjernholm <mast@lysator.liu.se>
parents: 44799
diff changeset
3006 (goto-char (+ end point-rel))))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3007 (when apply-outside-literal
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3008 (apply fun args))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3009 (when (consp tmp-pre)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3010 (delete-region (car tmp-pre) (cdr tmp-pre)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3011 (when tmp-post
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3012 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3013 (goto-char tmp-post)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3014 (delete-char 1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3015 (when hang-ender-stuck
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3016 ;; Preserve point even if it's in the middle of the string
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3017 ;; we replace; save-excursion doesn't work in that case.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3018 (setq here (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3019 (goto-char tmp-post)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3020 (skip-syntax-backward "^w ")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3021 (forward-char (- hang-ender-stuck))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3022 (insert-char ?\ hang-ender-stuck t)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3023 (delete-char hang-ender-stuck)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3024 (goto-char here))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3025 (set-marker tmp-post nil))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3026 (set-marker end nil))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3027
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3028 (defun c-fill-paragraph (&optional arg)
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3029 "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
3030 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
3031 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
3032 comment indentation or line-starting decorations (see the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3033 `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
3034 details).
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3035
21107
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
3036 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
3037 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
3038 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
3039 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
3040
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
3041 char description[] = \"\\
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
3042 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
3043 nicely formatted output.\"\;
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
3044
d67e858e738b (c-fill-paragraph): Bind fill-paragraph-function to
Richard M. Stallman <rms@gnu.org>
parents: 20912
diff changeset
3045 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
3046
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3047 Optional prefix ARG means justify paragraph as well."
20912
a0748eef9a76 (c-beginning-of-statement)
Richard M. Stallman <rms@gnu.org>
parents: 20143
diff changeset
3048 (interactive "*P")
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3049 (let ((fill-paragraph-function
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3050 ;; Avoid infinite recursion.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3051 (if (not (eq fill-paragraph-function 'c-fill-paragraph))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3052 fill-paragraph-function)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3053 (c-mask-comment t nil 'fill-paragraph arg))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3054 ;; 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
3055 ;; 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
3056 ;; disabled in normal code.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3057 t)
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3058
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3059 (defun c-do-auto-fill ()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3060 ;; 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
3061 ;; ignored.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3062 (let ((c-auto-fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3063 ;; The decision whether the line should be broken is actually
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3064 ;; 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
3065 ;; calls to break lines. We just set this special variable
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3066 ;; 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
3067 ;; 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
3068 ;; generated automatically by do-auto-fill.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3069 fill-prefix))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3070 (c-mask-comment nil t 'do-auto-fill)))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3071
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3072 (defun c-indent-new-comment-line (&optional soft allow-auto-fill)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3073 "Break line at point and indent, continuing comment or macro if within one.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3074 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
3075 indentation and line prefix are preserved (see the
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3076 `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
3077 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
3078 nil, a new comment of the same type is started on the next line and
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3079 indented as appropriate for comments. If inside a macro, a line
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3080 continuation backslash is inserted and aligned as appropriate, and the
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3081 new line is indented according to `c-syntactic-indentation'.
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3082
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3083 If a fill prefix is specified, it overrides all the above."
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3084 ;; allow-auto-fill is used from c-context-line-break to allow auto
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3085 ;; filling to break the line more than once. Since this function is
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3086 ;; used from auto-fill itself, that's normally disabled to avoid
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3087 ;; unnecessary recursion.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3088 (interactive)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3089 (let ((fill-prefix fill-prefix)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3090 (do-line-break
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3091 (lambda ()
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3092 (delete-horizontal-space)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3093 (if soft
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3094 (insert-and-inherit ?\n)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3095 (newline (if allow-auto-fill nil 1)))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3096 ;; Already know the literal type and limits when called from
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3097 ;; c-context-line-break.
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
3098 (c-lit-limits c-lit-limits)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3099 (c-lit-type c-lit-type)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3100 (c-macro-start c-macro-start))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
3101 (when (not (eq c-auto-fill-prefix t))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3102 ;; Called from do-auto-fill.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3103 (unless c-lit-limits
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3104 (setq c-lit-limits (c-literal-limits nil nil t)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3105 (unless c-lit-type
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3106 (setq c-lit-type (c-literal-type c-lit-limits)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3107 (if (memq (cond ((c-query-and-set-macro-start) 'cpp)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3108 ((null c-lit-type) 'code)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3109 (t c-lit-type))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3110 c-ignore-auto-fill)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3111 (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
3112 (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
3113 (eq c-lit-type 'c)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
3114 (<= (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
3115 ;; 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
3116 ;; 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
3117 ;; 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
3118 (setq fill-prefix nil)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
3119 (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
3120 (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
3121 ;; 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
3122 ;; 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
3123 ;; comments, then we ignore it.
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
3124 (setq fill-prefix nil)))
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
3125 ))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3126 (cond ((eq fill-prefix t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3127 ;; A call from do-auto-fill which should be ignored.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3128 )
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3129 (fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3130 ;; A fill-prefix overrides anything.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3131 (funcall do-line-break)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3132 (insert-and-inherit fill-prefix))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3133 ((progn
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3134 (unless c-lit-limits
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3135 (setq c-lit-limits (c-literal-limits)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3136 (unless c-lit-type
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3137 (setq c-lit-type (c-literal-type c-lit-limits)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3138 (memq c-lit-type '(c c++)))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3139 ;; Some sort of comment.
30406
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
3140 (if (or comment-multi-line
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
3141 (save-excursion
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
3142 (goto-char (car c-lit-limits))
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
3143 (end-of-line)
4fe5cb975331 (c-indent-new-comment-line): Added a kludge
Gerd Moellmann <gerd@gnu.org>
parents: 27111
diff changeset
3144 (< (point) (cdr c-lit-limits))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3145 ;; Inside a comment that should be continued.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3146 (let ((fill (c-guess-fill-prefix
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3147 (setq c-lit-limits
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3148 (c-collect-line-comments c-lit-limits))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3149 c-lit-type))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3150 (pos (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3151 (comment-text-end
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3152 (or (and (eq c-lit-type 'c)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3153 (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3154 (goto-char (- (cdr c-lit-limits) 2))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3155 (if (looking-at "\\*/") (point))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3156 (cdr c-lit-limits))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3157 ;; Skip forward past the fill prefix in case
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3158 ;; we're standing in it.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3159 ;;
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3160 ;; FIXME: This doesn't work well in cases like
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3161 ;;
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3162 ;; /* Bla bla bla bla bla
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3163 ;; bla bla
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3164 ;;
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3165 ;; If point is on the 'B' then the line will be
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3166 ;; broken after "Bla b".
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3167 (while (and (< (current-column) (cdr fill))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3168 (not (eolp)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3169 (forward-char 1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3170 (if (and (> (point) comment-text-end)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3171 (> (c-point 'bol) (car c-lit-limits)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3172 (progn
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3173 ;; The skip takes us out of the (block)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3174 ;; comment; insert the fill prefix at bol
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3175 ;; instead and keep the position.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3176 (setq pos (copy-marker pos t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3177 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3178 (insert-and-inherit (car fill))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3179 (if soft (insert-and-inherit ?\n) (newline 1))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3180 (goto-char pos)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3181 (set-marker pos nil))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3182 ;; Don't break in the middle of a comment starter
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3183 ;; or ender.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3184 (cond ((> (point) comment-text-end)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3185 (goto-char comment-text-end))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3186 ((< (point) (+ (car c-lit-limits) 2))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3187 (goto-char (+ (car c-lit-limits) 2))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3188 (funcall do-line-break)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3189 (insert-and-inherit (car fill))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3190 ;; Inside a comment that should be broken.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3191 (let ((comment-start comment-start)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3192 (comment-end comment-end)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3193 col)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3194 (if (eq c-lit-type 'c)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3195 (unless (string-match "[ \t]*/\\*" comment-start)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3196 (setq comment-start "/* " comment-end " */"))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3197 (unless (string-match "[ \t]*//" comment-start)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3198 (setq comment-start "// " comment-end "")))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3199 (setq col (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3200 (back-to-indentation)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3201 (current-column)))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3202 (funcall do-line-break)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3203 (when (and comment-end (not (equal comment-end "")))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3204 (forward-char -1)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3205 (insert-and-inherit comment-end)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3206 (forward-char 1))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3207 ;; c-comment-indent may look at the current
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3208 ;; indentation, so let's start out with the same
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3209 ;; indentation as the previous one.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3210 (indent-to col)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3211 (insert-and-inherit comment-start)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3212 (indent-for-comment))))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3213 ((c-query-and-set-macro-start)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3214 ;; In a macro.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3215 (unless (looking-at "[ \t]*\\\\$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3216 ;; Do not clobber the alignment of the line continuation
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3217 ;; slash; c-backslash-region might look at it.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3218 (delete-horizontal-space))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3219 ;; Got an asymmetry here: In normal code this command
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3220 ;; doesn't indent the next line syntactically, and otoh a
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3221 ;; normal syntactically indenting newline doesn't continue
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3222 ;; the macro.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3223 (c-newline-and-indent (if allow-auto-fill nil 1)))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3224 (t
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3225 ;; Somewhere else in the code.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3226 (let ((col (save-excursion
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3227 (beginning-of-line)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3228 (while (and (looking-at "[ \t]*\\\\?$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3229 (= (forward-line -1) 0)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3230 (current-indentation))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3231 (funcall do-line-break)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3232 (indent-to col))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3233
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3234 (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
3235 (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
3236
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3237 ;; advice for indent-new-comment-line for older Emacsen
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3238 (unless (boundp 'comment-line-break-function)
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
3239 (defvar c-inside-line-break-advice nil)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3240 (defadvice indent-new-comment-line (around c-line-break-advice
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3241 activate preactivate)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3242 "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
3243 (if (or c-inside-line-break-advice
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3244 (not c-buffer-is-cc-mode))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3245 ad-do-it
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
3246 (let ((c-inside-line-break-advice t))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3247 (c-indent-new-comment-line (ad-get-arg 0))))))
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3248
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3249 (defun c-context-line-break ()
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3250 "Do a line break suitable to the context.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3251
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3252 When point is outside a comment or macro, insert a newline and indent
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3253 according to the syntactic context, unless `c-syntactic-indentation'
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3254 is nil, in which case the new line is indented as the previous
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3255 non-empty line instead.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3256
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3257 When point is inside the content of a preprocessor directive, a line
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3258 continuation backslash is inserted before the line break and aligned
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3259 appropriately. The end of the cpp directive doesn't count as inside
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3260 it.
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3261
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3262 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
3263 comment prefix (see the `c-comment-prefix-regexp' and
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3264 `c-block-comment-prefix' variables for details). The end of a
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3265 C++-style line comment doesn't count as inside it."
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3266 (interactive "*")
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3267 (let* ((c-lit-limits (c-literal-limits nil nil t))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3268 (c-lit-type (c-literal-type c-lit-limits))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3269 (c-macro-start c-macro-start))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3270 (if (or (eq c-lit-type 'c)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3271 (and (eq c-lit-type 'c++)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3272 (< (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3273 (skip-chars-forward " \t")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3274 (point))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3275 (1- (cdr (setq c-lit-limits
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3276 (c-collect-line-comments c-lit-limits))))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3277 (and (or (not (looking-at "\\s *$"))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3278 (eq (char-before) ?\\))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3279 (c-query-and-set-macro-start)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3280 (<= (save-excursion
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3281 (goto-char c-macro-start)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3282 (if (looking-at "#[ \t]*[a-zA-Z0-9!]+")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3283 (goto-char (match-end 0)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3284 (point))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3285 (point))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3286 (let ((comment-multi-line t)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3287 (fill-prefix nil))
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3288 (c-indent-new-comment-line nil t))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3289 (delete-horizontal-space)
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3290 (newline)
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3291 ;; 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
3292 ;; start out with the same indentation as the previous line.
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3293 (let ((col (save-excursion
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3294 (forward-line -1)
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3295 (while (and (looking-at "[ \t]*\\\\?$")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3296 (= (forward-line -1) 0)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3297 (current-indentation))))
26817
03befb219d03 Installed version 5.26
Gerd Moellmann <gerd@gnu.org>
parents: 24529
diff changeset
3298 (indent-to col))
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
3299 (indent-according-to-mode))))
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3300
44728
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3301 (defun c-context-open-line ()
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3302 "Insert a line break suitable to the context and leave point before it.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3303 This is the `c-context-line-break' equivalent to `open-line', which is
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3304 normally bound to C-o. See `c-context-line-break' for the details."
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3305 (interactive "*")
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3306 (let ((here (point)))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3307 (unwind-protect
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3308 (progn
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3309 ;; Temporarily insert a non-whitespace char to keep any
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3310 ;; preceding whitespace intact.
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3311 (insert ?x)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3312 (c-context-line-break))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3313 (goto-char here)
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3314 (delete-char 1))))
7a3ac6c387fe CC Mode update to version 5.29. This is for testing; it's not a released
Martin Stjernholm <mast@lysator.liu.se>
parents: 38422
diff changeset
3315
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3316
36920
32a4317c6aa5 Update to version 5.28.
Gerd Moellmann <gerd@gnu.org>
parents: 34304
diff changeset
3317 (cc-provide 'cc-cmds)
38422
7a94f1c588c4 Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents: 38357
diff changeset
3318
18720
fc6d08b9bbe2 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
3319 ;;; cc-cmds.el ends here