Mercurial > emacs
annotate lisp/progmodes/cc-cmds.el @ 47142:21cac7a2dcb9
(Vblink_cursor_alist): Removed.
(Qbar, Qhbar, Qbox, Qhollow): Removed.
(syms_of_xfns): Don't intern, staticpro, or define them.
(x_specified_cursor_type): Removed.
(x_set_cursor_type): Use set_frame_cursor_types.
author | Kim F. Storm <storm@cua.dk> |
---|---|
date | Fri, 30 Aug 2002 12:04:18 +0000 |
parents | cb8f23e350ff |
children | 0d8b17d428b5 |
rev | line source |
---|---|
24282 | 1 ;;; cc-cmds.el --- user level commands for CC Mode |
18720 | 2 |
36920 | 3 ;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc. |
18720 | 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 | 7 ;; 1992-1997 Barry A. Warsaw |
18720 | 8 ;; 1987 Dave Detlefs and Stewart Clamen |
9 ;; 1985 Richard M. Stallman | |
24282 | 10 ;; Maintainer: bug-cc-mode@gnu.org |
18720 | 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 | 13 ;; Keywords: c languages oop |
14 | |
15 ;; This file is part of GNU Emacs. | |
16 | |
17 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
18 ;; it under the terms of the GNU General Public License as published by | |
19 ;; the Free Software Foundation; either version 2, or (at your option) | |
20 ;; any later version. | |
21 | |
22 ;; GNU Emacs is distributed in the hope that it will be useful, | |
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
25 ;; GNU General Public License for more details. | |
26 | |
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 | 29 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
18720 | 30 ;; Boston, MA 02111-1307, USA. |
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 | 36 (eval-when-compile |
37 (let ((load-path | |
36920 | 38 (if (and (boundp 'byte-compile-dest-file) |
39 (stringp byte-compile-dest-file)) | |
40 (cons (file-name-directory byte-compile-dest-file) load-path) | |
26817 | 41 load-path))) |
36920 | 42 (require 'cc-bytecomp))) |
43 | |
44 (cc-require 'cc-defs) | |
45 (cc-require 'cc-vars) | |
46 (cc-require 'cc-langs) | |
47 (cc-require 'cc-engine) | |
48 | |
49 ;; Silence the compiler. | |
50 (cc-bytecomp-defvar delete-key-deletes-forward) ; XEmacs 20+ | |
51 (cc-bytecomp-defun delete-forward-p) ; XEmacs 21+ | |
52 (cc-bytecomp-obsolete-fun insert-and-inherit) ; Marked obsolete in XEmacs 19 | |
53 (cc-bytecomp-defvar filladapt-mode) ; c-fill-paragraph contains a kludge | |
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 | 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 | 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 | 282 (defun c-toggle-auto-state (&optional arg) |
18720 | 283 "Toggle auto-newline feature. |
36920 | 284 Optional numeric ARG, if supplied, turns on auto-newline when |
285 positive, turns it off when negative, and just toggles it when zero or | |
286 left out. | |
18720 | 287 |
288 When the auto-newline feature is enabled (as evidenced by the `/a' or | |
289 `/ah' on the modeline after the mode name) newlines are automatically | |
290 inserted after special characters such as brace, comma, semi-colon, | |
291 and colon." | |
292 (interactive "P") | |
293 (setq c-auto-newline (c-calculate-state arg c-auto-newline)) | |
294 (c-update-modeline) | |
295 (c-keep-region-active)) | |
296 | |
36920 | 297 (defun c-toggle-hungry-state (&optional arg) |
18720 | 298 "Toggle hungry-delete-key feature. |
36920 | 299 Optional numeric ARG, if supplied, turns on hungry-delete when |
300 positive, turns it off when negative, and just toggles it when zero or | |
301 left out. | |
18720 | 302 |
303 When the hungry-delete-key feature is enabled (as evidenced by the | |
304 `/h' or `/ah' on the modeline after the mode name) the delete key | |
305 gobbles all preceding whitespace in one fell swoop." | |
306 (interactive "P") | |
307 (setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key)) | |
308 (c-update-modeline) | |
309 (c-keep-region-active)) | |
310 | |
36920 | 311 (defun c-toggle-auto-hungry-state (&optional arg) |
18720 | 312 "Toggle auto-newline and hungry-delete-key features. |
36920 | 313 Optional numeric ARG, if supplied, turns on auto-newline and |
18720 | 314 hungry-delete when positive, turns them off when negative, and just |
36920 | 315 toggles them when zero or left out. |
18720 | 316 |
317 See `c-toggle-auto-state' and `c-toggle-hungry-state' for details." | |
318 (interactive "P") | |
319 (setq c-auto-newline (c-calculate-state arg c-auto-newline)) | |
320 (setq c-hungry-delete-key (c-calculate-state arg c-hungry-delete-key)) | |
321 (c-update-modeline) | |
322 (c-keep-region-active)) | |
323 | |
324 | |
325 ;; Electric keys | |
326 | |
327 (defun c-electric-backspace (arg) | |
328 "Deletes preceding character or whitespace. | |
329 If `c-hungry-delete-key' is non-nil, as evidenced by the \"/h\" or | |
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 | 334 |
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 | 337 (if (or (not c-hungry-delete-key) |
338 arg | |
339 (c-in-literal)) | |
340 (funcall c-backspace-function (prefix-numeric-value arg)) | |
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 | 343 (if (/= (point) here) |
344 (delete-region (point) here) | |
345 (funcall c-backspace-function 1) | |
346 )))) | |
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 | 366 (defun c-electric-delete (arg) |
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 | 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 | 383 (if (or (and (fboundp 'delete-forward-p) ;XEmacs 21 |
384 (delete-forward-p)) | |
385 (and (boundp 'delete-key-deletes-forward) ;XEmacs 20 | |
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 | 388 (c-electric-backspace arg))) |
389 | |
390 (defun c-electric-pound (arg) | |
391 "Electric pound (`#') insertion. | |
392 Inserts a `#' character specially depending on the variable | |
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 | 396 (if (or arg |
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 | 405 (c-in-literal)) |
18720 | 406 ;; do nothing special |
407 (self-insert-command (prefix-numeric-value arg)) | |
408 ;; place the pound character at the left edge | |
409 (let ((pos (- (point-max) (point))) | |
410 (bolp (bolp))) | |
411 (beginning-of-line) | |
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 | 414 (and (not bolp) |
415 (goto-char (- (point-max) pos))) | |
416 ))) | |
417 | |
418 (defun c-electric-brace (arg) | |
419 "Insert a brace. | |
420 | |
421 If the auto-newline feature is turned on, as evidenced by the \"/a\" | |
422 or \"/ah\" string on the mode line, newlines are inserted before and | |
423 after braces based on the value of `c-hanging-braces-alist'. | |
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 | 428 |
429 This function does various newline cleanups based on the value of | |
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 | 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 | 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 | 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 | 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 | 566 ;; Do all appropriate clean ups |
567 (let ((here (point)) | |
568 (pos (- (point-max) (point))) | |
26817 | 569 mbeg mend tmp) |
18720 | 570 ;; clean up empty defun braces |
571 (if (and c-auto-newline | |
572 (memq 'empty-defun-braces c-cleanup-list) | |
573 (eq last-command-char ?\}) | |
574 (c-intersect-lists '(defun-close class-close inline-close) | |
575 syntax) | |
576 (progn | |
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 | 579 (eq (char-before) ?\{)) |
580 ;; make sure matching open brace isn't in a comment | |
581 (not (c-in-literal))) | |
582 (delete-region (point) (1- here))) | |
26817 | 583 ;; clean up brace-else-brace and brace-elseif-brace |
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 | 586 (cond |
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 | 595 (progn |
596 (setq mbeg (match-beginning 0) | |
597 mend (match-end 0)) | |
26817 | 598 (eq (match-end 0) here))) |
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 | 601 ((and (memq 'brace-elseif-brace c-cleanup-list) |
602 (progn | |
603 (goto-char (1- here)) | |
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 | 606 (setq mbeg (point)) |
607 (eq (char-before) ?\))) | |
608 (= (c-backward-token-1 1 t) 0) | |
609 (eq (char-after) ?\() | |
610 (progn | |
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 | 620 (eq (match-end 0) tmp)) |
621 (delete-region mbeg mend) | |
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 | 624 (goto-char (- (point-max) pos)) |
625 ) | |
626 ;; does a newline go after the brace? | |
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 | 637 |
18720 | 638 (defun c-electric-slash (arg) |
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 | 664 (self-insert-command (prefix-numeric-value arg)) |
665 (if indentp | |
36920 | 666 (indent-according-to-mode)))) |
18720 | 667 |
668 (defun c-electric-star (arg) | |
669 "Insert a star character. | |
670 If the star is the second character of a C style comment introducing | |
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 | 675 (self-insert-command (prefix-numeric-value arg)) |
676 ;; if we are in a literal, or if arg is given do not re-indent the | |
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 | 681 (eq (char-before) ?*) |
682 (save-excursion | |
683 (forward-char -1) | |
684 (skip-chars-backward "*") | |
685 (if (eq (char-before) ?/) | |
686 (forward-char -1)) | |
687 (skip-chars-backward " \t") | |
688 (bolp))) | |
36920 | 689 (let (c-echo-syntactic-information-p) ; shut this up |
690 (indent-according-to-mode)) | |
18720 | 691 )) |
692 | |
693 (defun c-electric-semi&comma (arg) | |
694 "Insert a comma or semicolon. | |
695 When the auto-newline feature is turned on, as evidenced by the \"/a\" | |
696 or \"/ah\" string on the mode line, a newline might be inserted. See | |
697 the variable `c-hanging-semi&comma-criteria' for how newline insertion | |
698 is determined. | |
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 | 703 |
704 Based on the value of `c-cleanup-list', this function cleans up commas | |
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 | 707 (let* ((lim (c-most-enclosing-brace (c-parse-state))) |
708 (literal (c-in-literal lim)) | |
709 (here (point)) | |
710 ;; shut this up | |
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 | 713 (self-insert-command (prefix-numeric-value arg)) |
714 ;; do some special stuff with the character | |
715 (self-insert-command (prefix-numeric-value arg)) | |
24282 | 716 ;; do all cleanups and newline insertions if c-auto-newline is |
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 | 721 (indent-according-to-mode)) |
18720 | 722 ;; clean ups |
723 (let ((pos (- (point-max) (point)))) | |
724 (if (and (or (and | |
725 (eq last-command-char ?,) | |
726 (memq 'list-close-comma c-cleanup-list)) | |
727 (and | |
728 (eq last-command-char ?\;) | |
729 (memq 'defun-close-semi c-cleanup-list))) | |
730 (progn | |
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 | 733 (eq (char-before) ?})) |
734 ;; make sure matching open brace isn't in a comment | |
735 (not (c-in-literal lim))) | |
736 (delete-region (point) here)) | |
737 (goto-char (- (point-max) pos))) | |
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 | 740 (indent-according-to-mode)) |
18720 | 741 ;; check to see if a newline should be added |
742 (let ((criteria c-hanging-semi&comma-criteria) | |
743 answer add-newline-p) | |
744 (while criteria | |
745 (setq answer (funcall (car criteria))) | |
746 ;; only nil value means continue checking | |
747 (if (not answer) | |
748 (setq criteria (cdr criteria)) | |
749 (setq criteria nil) | |
750 ;; only 'stop specifically says do not add a newline | |
751 (setq add-newline-p (not (eq answer 'stop))) | |
752 )) | |
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 | 755 ))))) |
756 | |
757 (defun c-electric-colon (arg) | |
758 "Insert a colon. | |
759 | |
760 If the auto-newline feature is turned on, as evidenced by the \"/a\" | |
761 or \"/ah\" string on the mode line, newlines are inserted before and | |
762 after colons based on the value of `c-hanging-colons-alist'. | |
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 | 767 |
768 This function cleans up double colon scope operators based on the | |
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 | 771 (let* ((bod (c-point 'bod)) |
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 | 774 ;; shut this up |
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 | 784 ;; insert the colon, then do any specified cleanups |
785 (self-insert-command (prefix-numeric-value arg)) | |
786 (let ((pos (- (point-max) (point))) | |
787 (here (point))) | |
788 (if (and c-auto-newline | |
789 (memq 'scope-operator c-cleanup-list) | |
790 (eq (char-before) ?:) | |
791 (progn | |
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 | 794 (eq (char-before) ?:)) |
795 (not (c-in-literal)) | |
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 | 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 | 831 ;; does a newline go before the colon? Watch out for already |
832 ;; non-hung colons. However, we don't unhang them because that | |
833 ;; would be a cleanup (and anti-social). | |
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 | 836 (save-excursion |
837 (skip-chars-backward ": \t") | |
838 (not (bolp)))) | |
839 (let ((pos (- (point-max) (point)))) | |
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 | 842 (goto-char (- (point-max) pos)))) |
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 | 848 |
849 (defun c-electric-lt-gt (arg) | |
850 "Insert a less-than, or greater-than character. | |
24282 | 851 The line will be re-indented if the character inserted is the second |
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 | 859 (eq (char-before) last-command-char) |
860 (not (c-in-literal)))) | |
861 ;; shut this up | |
862 (c-echo-syntactic-information-p nil)) | |
863 (self-insert-command (prefix-numeric-value arg)) | |
864 (if indentp | |
36920 | 865 (indent-according-to-mode)))) |
18720 | 866 |
24282 | 867 (defun c-electric-paren (arg) |
868 "Insert a parenthesis. | |
869 | |
36920 | 870 Some newline cleanups are done if appropriate; see the variable |
871 `c-cleanup-list'. | |
24282 | 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 | 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 | 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 | 881 (self-insert-command (prefix-numeric-value arg)) |
882 ;; do some special stuff with the character | |
883 (let* (;; We want to inhibit blinking the paren since this will | |
884 ;; be most disruptive. We'll blink it ourselves | |
885 ;; afterwards. | |
886 (old-blink-paren blink-paren-function) | |
887 blink-paren-function) | |
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 | 892 (when c-auto-newline |
893 ;; Do all appropriate clean ups | |
894 (let ((here (point)) | |
895 (pos (- (point-max) (point))) | |
896 mbeg mend) | |
897 ;; clean up brace-elseif-brace | |
898 (if (and (memq 'brace-elseif-brace c-cleanup-list) | |
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 | 909 (save-excursion |
910 (setq mbeg (match-beginning 0) | |
911 mend (match-end 0)) | |
912 (= mend here)) | |
913 (not (c-in-literal))) | |
914 (progn | |
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 | 936 (goto-char (- (point-max) pos)) |
937 ))) | |
938 (let (beg (end (1- (point)))) | |
939 (cond ((and (memq 'space-before-funcall c-cleanup-list) | |
940 (eq last-command-char ?\() | |
941 (save-excursion | |
942 (backward-char) | |
943 (skip-chars-backward " \t") | |
944 (setq beg (point)) | |
945 (c-on-identifier))) | |
946 (save-excursion | |
947 (delete-region beg end) | |
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 | 950 ((and (memq 'compact-empty-funcall c-cleanup-list) |
951 (eq last-command-char ?\)) | |
952 (save-excursion | |
953 (c-safe (backward-char 2)) | |
954 (when (looking-at "()") | |
955 (setq end (point)) | |
956 (skip-chars-backward " \t") | |
957 (setq beg (point)) | |
958 (c-on-identifier)))) | |
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 | 963 |
36920 | 964 (defun c-electric-continued-statement () |
965 "Reindent the current line if appropriate. | |
966 | |
967 This function is used to reindent the line after a keyword which | |
968 continues an earlier statement is typed, e.g. an \"else\" or the | |
969 \"while\" in a do-while block. | |
970 | |
971 The line is reindented if there is nothing but whitespace before the | |
972 keyword on the line, the keyword is not inserted inside a literal, and | |
973 `c-syntactic-indentation' is non-nil." | |
974 (let (;; shut this up | |
975 (c-echo-syntactic-information-p nil)) | |
976 (when (and c-syntactic-indentation | |
977 (not (eq last-command-char ?_)) | |
978 (= (save-excursion | |
979 (skip-syntax-backward "w") | |
980 (point)) | |
981 (c-point 'boi)) | |
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 | 992 |
993 | |
994 ;; better movement routines for ThisStyleOfVariablesCommonInCPlusPlus | |
995 ;; originally contributed by Terry_Glanfield.Southern@rxuk.xerox.com | |
996 (defun c-forward-into-nomenclature (&optional arg) | |
997 "Move forward to end of a nomenclature section or word. | |
998 With arg, to it arg times." | |
999 (interactive "p") | |
1000 (let ((case-fold-search nil)) | |
1001 (if (> arg 0) | |
1002 (re-search-forward "\\W*\\([A-Z]*[a-z0-9]*\\)" (point-max) t arg) | |
1003 (while (and (< arg 0) | |
1004 (re-search-backward | |
1005 "\\(\\(\\W\\|[a-z0-9]\\)[A-Z]+\\|\\W\\w+\\)" | |
1006 (point-min) 0)) | |
1007 (forward-char 1) | |
1008 (setq arg (1+ arg))))) | |
1009 (c-keep-region-active)) | |
1010 | |
1011 (defun c-backward-into-nomenclature (&optional arg) | |
1012 "Move backward to beginning of a nomenclature section or word. | |
1013 With optional ARG, move that many times. If ARG is negative, move | |
1014 forward." | |
1015 (interactive "p") | |
1016 (c-forward-into-nomenclature (- arg)) | |
1017 (c-keep-region-active)) | |
1018 | |
1019 (defun c-scope-operator () | |
1020 "Insert a double colon scope operator at point. | |
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 | 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 | 1121 (c-keep-region-active) |
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 | 1207 (c-keep-region-active) |
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 | 1337 |
1338 (defun c-beginning-of-statement (&optional count lim sentence-flag) | |
1339 "Go to the beginning of the innermost C statement. | |
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 | 1343 \\[backward-sexp] to skip over a block). If within or next to a |
1344 comment or multiline string, move by sentences instead of statements. | |
18720 | 1345 |
1346 When called from a program, this function takes 3 optional args: the | |
1347 repetition count, a buffer position limit which is the farthest back | |
36920 | 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 | 1355 (interactive (list (prefix-numeric-value current-prefix-arg) |
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 | 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 | 1372 (setq range (point)) |
1373 (setq range | |
1374 (if (eq (char-before) ?\") | |
1375 (c-safe (c-backward-sexp 1) | |
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 | 1378 (if (eq (char-after) ?\") |
1379 (setq range (cons (point) | |
1380 (progn | |
1381 (c-forward-sexp 1) | |
1382 (point)))) | |
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 | 1385 (cons range (point)) |
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 | 1393 (or (/= (char-syntax (char-after (car range))) ?\") |
1394 ;; Only visit a string if it spans more than one line. | |
1395 (save-excursion | |
1396 (goto-char (car range)) | |
1397 (skip-chars-forward "^\n" (cdr range)) | |
1398 (< (point) (cdr range))))) | |
26817 | 1399 (let* ((lit-type (c-literal-type range)) |
36920 | 1400 (line-prefix (concat "[ \t]*\\(" |
1401 c-current-comment-prefix | |
1402 "\\)[ \t]*")) | |
1403 (beg (if (eq lit-type 'string) | |
1404 (1+ (car range)) | |
1405 (save-excursion | |
1406 (goto-char (car range)) | |
1407 (max (progn | |
1408 (looking-at comment-start-skip) | |
1409 (match-end 0)) | |
1410 (progn | |
1411 (looking-at line-prefix) | |
1412 (match-end 0)))))) | |
1413 (end (- (cdr range) (if (eq lit-type 'c) 2 1))) | |
1414 (beg-of-para (if (eq lit-type 'string) | |
1415 (lambda ()) | |
1416 (lambda () | |
1417 (beginning-of-line) | |
1418 (if (looking-at line-prefix) | |
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 | 1421 ;; Move by sentence, but not past the limit of the |
1422 ;; literal, narrowed to the appropriate | |
1423 ;; paragraph(s). | |
1424 (narrow-to-region (save-excursion | |
1425 (let ((pos (min here end))) | |
1426 (goto-char pos) | |
1427 (forward-paragraph -1) | |
1428 (if (looking-at paragraph-separate) | |
1429 (forward-line)) | |
1430 (when (> (point) beg) | |
1431 (funcall beg-of-para) | |
1432 (when (>= (point) pos) | |
1433 (forward-paragraph -2) | |
1434 (funcall beg-of-para))) | |
1435 (max (point) beg))) | |
1436 end) | |
26817 | 1437 (c-safe (forward-sentence (if (< count 0) 1 -1))) |
1438 (if (and (memq lit-type '(c c++)) | |
1439 ;; Check if we stopped due to a comment | |
1440 ;; prefix and not a sentence end. | |
36920 | 1441 (/= (point) (point-min)) |
1442 (/= (point) (point-max)) | |
26817 | 1443 (save-excursion |
1444 (beginning-of-line) | |
36920 | 1445 (looking-at line-prefix)) |
26817 | 1446 (>= (point) (match-beginning 0)) |
1447 (/= (match-beginning 1) (match-end 1)) | |
1448 (or (< (point) (match-end 0)) | |
1449 (and | |
1450 (= (point) (match-end 0)) | |
1451 ;; The comment prefix may contain | |
1452 ;; characters that is regarded as end | |
1453 ;; of sentence. | |
1454 (or (eolp) | |
1455 (and | |
1456 (save-excursion | |
1457 (forward-paragraph -1) | |
1458 (< (point) (match-beginning 0))) | |
1459 (save-excursion | |
1460 (beginning-of-line) | |
1461 (or (not (re-search-backward | |
1462 sentence-end | |
1463 (c-point 'bopl) | |
1464 t)) | |
1465 (< (match-end 0) | |
1466 (c-point 'eol))))))))) | |
1467 (setq count (+ count (if (< count 0) -1 1))) | |
1468 (if (< count 0) | |
1469 (progn | |
1470 ;; In block comments, if there's only | |
1471 ;; horizontal ws between the text and the | |
1472 ;; comment ender, stop before it. Stop after | |
1473 ;; the ender if there's either nothing or | |
1474 ;; newlines between. | |
36920 | 1475 (when (and (eq lit-type 'c) |
1476 (eq (point) (point-max))) | |
26817 | 1477 (widen) |
36920 | 1478 (when (or (= (skip-chars-backward " \t") 0) |
1479 (eq (point) (point-max)) | |
1480 (bolp)) | |
26817 | 1481 (goto-char (cdr range))))) |
36920 | 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 | 1484 ;; Stop before instead of after the comment |
1485 ;; starter if nothing follows it. | |
1486 (widen) | |
36920 | 1487 (goto-char (car range)) |
1488 (if (and (eq lit-type 'string) (/= (point) here)) | |
1489 (setq count (1+ count) | |
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 | 1505 (condition-case nil |
1506 ;; Stop before `{' and after `;', `{', `}' and `};' | |
1507 ;; when not followed by `}' or `)', but on the other | |
1508 ;; side of the syntactic ws. Move by sexps and move | |
36920 | 1509 ;; into parens. Also stop before `#' when it's at boi |
26817 | 1510 ;; on a line. |
36920 | 1511 (let ((literal-pos (not sentence-flag)) |
26817 | 1512 (large-enough (- (point-max))) |
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 | 1515 (while t |
1516 (setq last (point)) | |
36920 | 1517 (when (and (or (eq (char-after) ?\{) |
1518 (and (eq (char-after) ?#) | |
1519 (eq (point) (c-point 'boi))) | |
1520 ) | |
1521 (/= here last)) | |
26817 | 1522 (unless (and c-special-brace-lists |
1523 (eq (char-after) ?{) | |
1524 (c-looking-at-special-brace-list)) | |
1525 (if (and (eq (char-after) ?#) | |
1526 (numberp last-below-line) | |
1527 (not (eq last-below-line here))) | |
1528 (goto-char last-below-line)) | |
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 | 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 | 1537 ;; Record position of first comment. |
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 | 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 | 1542 (unless last-below-line |
1543 (if (save-excursion | |
1544 (re-search-forward "\\(^\\|[^\\]\\)$" last t)) | |
1545 (setq last-below-line last))) | |
1546 (cond ((bobp) ; Must handle bob specially. | |
1547 (if (= here last) | |
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 | 1550 (throw 'done t))) |
1551 ((progn (backward-char) | |
1552 (looking-at "[;{}]")) | |
1553 (if (and c-special-brace-lists | |
1554 (eq (char-after) ?{) | |
1555 (c-looking-at-special-brace-list)) | |
1556 (skip-syntax-backward "w_") ; Speedup only. | |
1557 (if (or (= here last) | |
1558 (memq (char-after last) '(?\) ?}))) | |
1559 (if (and (eq (char-before) ?}) | |
1560 (eq (char-after) ?\;)) | |
1561 (backward-char)) | |
1562 (goto-char last) | |
1563 (throw 'done t)))) | |
1564 ((= (char-syntax (char-after)) ?\") | |
36920 | 1565 (let ((end (point))) |
1566 (forward-char) | |
1567 (c-backward-sexp) | |
1568 (save-excursion | |
1569 (skip-chars-forward "^\n" end) | |
1570 (when (< (point) end) | |
1571 ;; Break at multiline string. | |
1572 (setq literal-pos (1+ end)) | |
1573 (throw 'done t))))) | |
26817 | 1574 (t (skip-syntax-backward "w_")) ; Speedup only. |
1575 ))) | |
36920 | 1576 (if (and (numberp literal-pos) |
1577 (< (point) literal-pos)) | |
1578 ;; We jumped over a comment or string that | |
1579 ;; should be investigated. | |
1580 (goto-char literal-pos) | |
26817 | 1581 (setq count (1- count)))) |
1582 (error | |
1583 (goto-char (point-min)) | |
1584 (setq count 0))) | |
1585 (condition-case nil | |
36920 | 1586 ;; Stop before `{', `}', and `#' when it's at boi on a |
26817 | 1587 ;; line, but on the other side of the syntactic ws, and |
1588 ;; after `;', `}' and `};'. Only stop before `{' if at | |
1589 ;; top level or inside braces, though. Move by sexps | |
1590 ;; and move into parens. Also stop at eol of lines | |
36920 | 1591 ;; with `#' at the boi. |
1592 (let ((literal-pos (not sentence-flag)) | |
26817 | 1593 (large-enough (point-max)) |
1594 last) | |
1595 (catch 'done | |
1596 (while t | |
1597 (setq last (point)) | |
36920 | 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 | 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 | 1602 ;; Record position of first comment. |
36920 | 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 | 1606 (setq literal-pos nil))) |
26817 | 1607 (cond ((and (eq (char-after) ?{) |
1608 (not (and c-special-brace-lists | |
1609 (c-looking-at-special-brace-list))) | |
1610 (/= here last) | |
1611 (save-excursion | |
1612 (or (not (c-safe (up-list -1) t)) | |
1613 (= (char-after) ?{)))) | |
1614 (goto-char last) | |
1615 (throw 'done t)) | |
1616 ((and c-special-brace-lists | |
1617 (eq (char-after) ?}) | |
1618 (save-excursion | |
1619 (and (c-safe (up-list -1) t) | |
1620 (c-looking-at-special-brace-list)))) | |
1621 (forward-char 1) | |
1622 (skip-syntax-forward "w_")) ; Speedup only. | |
1623 ((and (eq (char-after) ?}) | |
1624 (/= here last)) | |
1625 (goto-char last) | |
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 | 1634 ((looking-at ";\\|};?") |
1635 (goto-char (match-end 0)) | |
1636 (throw 'done t)) | |
1637 ((= (char-syntax (char-after)) ?\") | |
36920 | 1638 (let ((beg (point))) |
1639 (c-forward-sexp) | |
1640 (save-excursion | |
1641 (skip-chars-backward "^\n" beg) | |
1642 (when (> (point) beg) | |
1643 ;; Break at multiline string. | |
1644 (setq literal-pos beg) | |
1645 (throw 'done t))))) | |
26817 | 1646 (t |
1647 (forward-char 1) | |
1648 (skip-syntax-forward "w_")) ; Speedup only. | |
1649 ))) | |
36920 | 1650 (if (and (numberp literal-pos) |
1651 (> (point) literal-pos)) | |
26817 | 1652 ;; We jumped over a comment that should be investigated. |
36920 | 1653 (goto-char literal-pos) |
26817 | 1654 (setq count (1+ count)))) |
1655 (error | |
1656 (goto-char (point-max)) | |
1657 (setq count 0))) | |
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 | 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 | 1662 (setq count 0)))) |
18720 | 1663 (c-keep-region-active)) |
1664 | |
1665 (defun c-end-of-statement (&optional count lim sentence-flag) | |
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 | 1669 \(use \\[forward-sexp] to skip over a block). If within or next to a |
1670 comment or multiline string, move by sentences instead of statements. | |
18720 | 1671 |
1672 When called from a program, this function takes 3 optional args: the | |
1673 repetition count, a buffer position limit which is the farthest back | |
36920 | 1674 to search for the syntactic context, and a flag saying whether to do |
1675 sentence motion in or near comments and multiline strings." | |
18720 | 1676 (interactive (list (prefix-numeric-value current-prefix-arg) |
1677 nil t)) | |
1678 (c-beginning-of-statement (- (or count 1)) lim sentence-flag) | |
1679 (c-keep-region-active)) | |
1680 | |
1681 | |
1682 ;; set up electric character functions to work with pending-del, | |
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 | 1685 (mapcar |
1686 (function | |
1687 (lambda (sym) | |
1688 (put sym 'delete-selection t) ; for delsel (Emacs) | |
1689 (put sym 'pending-delete t))) ; for pending-del (XEmacs) | |
1690 '(c-electric-pound | |
1691 c-electric-brace | |
1692 c-electric-slash | |
1693 c-electric-star | |
1694 c-electric-semi&comma | |
1695 c-electric-lt-gt | |
24282 | 1696 c-electric-colon |
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 | 1704 |
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 | 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 | 1776 ;; BOGOSITY ALERT: if we're looking at the eol, its |
1777 ;; because indent-for-comment hasn't put the comment-start | |
1778 ;; in the buffer yet. this will screw up the syntactic | |
1779 ;; analysis so we kludge in the necessary info. Another | |
1780 ;; kludge is that if we're at the bol, then we really want | |
1781 ;; to ignore any anchoring as specified by | |
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 | 1784 (c-add-syntax 'comment-intro)) |
1785 (let ((c-comment-only-line-offset | |
1786 (if (consp c-comment-only-line-offset) | |
1787 c-comment-only-line-offset | |
1788 (cons c-comment-only-line-offset | |
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 | 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 | 1795 ;; used by outline-minor-mode |
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 | 1802 |
1803 | |
1804 (defun c-up-conditional (count) | |
1805 "Move back to the containing preprocessor conditional, leaving mark behind. | |
1806 A prefix argument acts as a repeat count. With a negative argument, | |
1807 move forward to the end of the containing preprocessor conditional. | |
26817 | 1808 |
1809 `#elif' is treated like `#else' followed by `#if', so the function | |
1810 stops at them when going backward, but not when going forward." | |
18720 | 1811 (interactive "p") |
26817 | 1812 (c-forward-conditional (- count) -1) |
1813 (c-keep-region-active)) | |
1814 | |
1815 (defun c-up-conditional-with-else (count) | |
1816 "Move back to the containing preprocessor conditional, including `#else'. | |
1817 Just like `c-up-conditional', except it also stops at `#else' | |
1818 directives." | |
1819 (interactive "p") | |
1820 (c-forward-conditional (- count) -1 t) | |
18720 | 1821 (c-keep-region-active)) |
1822 | |
26817 | 1823 (defun c-down-conditional (count) |
1824 "Move forward into the next preprocessor conditional, leaving mark behind. | |
1825 A prefix argument acts as a repeat count. With a negative argument, | |
1826 move backward into the previous preprocessor conditional. | |
1827 | |
1828 `#elif' is treated like `#else' followed by `#if', so the function | |
1829 stops at them when going forward, but not when going backward." | |
1830 (interactive "p") | |
1831 (c-forward-conditional count 1) | |
1832 (c-keep-region-active)) | |
1833 | |
1834 (defun c-down-conditional-with-else (count) | |
1835 "Move forward into the next preprocessor conditional, including `#else'. | |
1836 Just like `c-down-conditional', except it also stops at `#else' | |
1837 directives." | |
1838 (interactive "p") | |
1839 (c-forward-conditional count 1 t) | |
1840 (c-keep-region-active)) | |
1841 | |
1842 (defun c-backward-conditional (count &optional target-depth with-else) | |
18720 | 1843 "Move back across a preprocessor conditional, leaving mark behind. |
1844 A prefix argument acts as a repeat count. With a negative argument, | |
1845 move forward across a preprocessor conditional." | |
1846 (interactive "p") | |
26817 | 1847 (c-forward-conditional (- count) target-depth with-else) |
18720 | 1848 (c-keep-region-active)) |
1849 | |
26817 | 1850 (defun c-forward-conditional (count &optional target-depth with-else) |
18720 | 1851 "Move forward across a preprocessor conditional, leaving mark behind. |
1852 A prefix argument acts as a repeat count. With a negative argument, | |
26817 | 1853 move backward across a preprocessor conditional. |
1854 | |
1855 `#elif' is treated like `#else' followed by `#if', except that the | |
1856 nesting level isn't changed when tracking subconditionals. | |
1857 | |
1858 The optional argument TARGET-DEPTH specifies the wanted nesting depth | |
1859 after each scan. I.e. if TARGET-DEPTH is -1, the function will move | |
1860 out of the enclosing conditional. A non-integer non-nil TARGET-DEPTH | |
1861 counts as -1. | |
1862 | |
1863 If the optional argument WITH-ELSE is non-nil, `#else' directives are | |
1864 treated as conditional clause limits. Normally they are ignored." | |
18720 | 1865 (interactive "p") |
1866 (let* ((forward (> count 0)) | |
1867 (increment (if forward -1 1)) | |
1868 (search-function (if forward 're-search-forward 're-search-backward)) | |
1869 (new)) | |
26817 | 1870 (unless (integerp target-depth) |
1871 (setq target-depth (if target-depth -1 0))) | |
18720 | 1872 (save-excursion |
1873 (while (/= count 0) | |
26817 | 1874 (let ((depth 0) |
1875 ;; subdepth is the depth in "uninteresting" subtrees, | |
1876 ;; i.e. those that takes us farther from the target | |
1877 ;; depth instead of closer. | |
1878 (subdepth 0) | |
1879 found) | |
18720 | 1880 (save-excursion |
1881 ;; Find the "next" significant line in the proper direction. | |
1882 (while (and (not found) | |
1883 ;; Rather than searching for a # sign that | |
1884 ;; comes at the beginning of a line aside from | |
1885 ;; whitespace, search first for a string | |
1886 ;; starting with # sign. Then verify what | |
1887 ;; precedes it. This is faster on account of | |
1888 ;; the fastmap feature of the regexp matcher. | |
1889 (funcall search-function | |
26817 | 1890 "#[ \t]*\\(if\\|elif\\|endif\\|else\\)" |
18720 | 1891 nil t)) |
1892 (beginning-of-line) | |
1893 ;; Now verify it is really a preproc line. | |
26817 | 1894 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\|else\\)") |
1895 (let (dchange (directive (match-string 1))) | |
1896 (cond ((string= directive "if") | |
1897 (setq dchange (- increment))) | |
1898 ((string= directive "endif") | |
1899 (setq dchange increment)) | |
1900 ((= subdepth 0) | |
1901 ;; When we're not in an "uninteresting" | |
1902 ;; subtree, we might want to act on "elif" | |
1903 ;; and "else" too. | |
1904 (if (cond (with-else | |
1905 ;; Always move toward the target depth. | |
1906 (setq dchange | |
1907 (if (> target-depth 0) 1 -1))) | |
1908 ((string= directive "elif") | |
1909 (setq dchange (- increment)))) | |
1910 ;; Ignore the change if it'd take us | |
1911 ;; into an "uninteresting" subtree. | |
1912 (if (eq (> dchange 0) (<= target-depth 0)) | |
1913 (setq dchange nil))))) | |
1914 (when dchange | |
1915 (when (or (/= subdepth 0) | |
1916 (eq (> dchange 0) (<= target-depth 0))) | |
1917 (setq subdepth (+ subdepth dchange))) | |
1918 (setq depth (+ depth dchange)) | |
1919 ;; If we are trying to move across, and we find an | |
1920 ;; end before we find a beginning, get an error. | |
1921 (if (and (< depth target-depth) (< dchange 0)) | |
1922 (error (if forward | |
1923 "No following conditional at this level" | |
1924 "No previous conditional at this level")))) | |
18720 | 1925 ;; When searching forward, start from next line so |
1926 ;; that we don't find the same line again. | |
1927 (if forward (forward-line 1)) | |
26817 | 1928 ;; We found something if we've arrived at the |
1929 ;; target depth. | |
1930 (if (and dchange (= depth target-depth)) | |
18720 | 1931 (setq found (point)))) |
1932 ;; else | |
26817 | 1933 (if forward (forward-line 1))))) |
18720 | 1934 (or found |
1935 (error "No containing preprocessor conditional")) | |
1936 (goto-char (setq new found))) | |
1937 (setq count (+ count increment)))) | |
1938 (push-mark) | |
1939 (goto-char new)) | |
1940 (c-keep-region-active)) | |
1941 | |
1942 | |
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 | 1945 "Indent current line as C code, and/or insert some whitespace. |
1946 | |
1947 If `c-tab-always-indent' is t, always just indent the current line. | |
1948 If nil, indent the current line only if point is at the left margin or | |
1949 in the line's indentation; otherwise insert some whitespace[*]. If | |
1950 other than nil or t, then some whitespace[*] is inserted only within | |
1951 literals (comments and strings) and inside preprocessor directives, | |
1952 but the line is always reindented. | |
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 | 1965 [*] The amount and kind of whitespace inserted is controlled by the |
1966 variable `c-insert-tab-function', which is called to do the actual | |
1967 insertion of whitespace. Normally the function in this variable | |
1968 just inserts a tab character, or the equivalent number of spaces, | |
1969 depending on the variable `indent-tabs-mode'." | |
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 | 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 | 1993 (let ((shift-amt (save-excursion |
1994 (back-to-indentation) | |
1995 (current-column))) | |
18720 | 1996 beg end) |
36920 | 1997 (c-indent-line) |
1998 (setq shift-amt (- (save-excursion | |
1999 (back-to-indentation) | |
2000 (current-column)) | |
2001 shift-amt)) | |
18720 | 2002 (save-excursion |
2003 (if (eq c-tab-always-indent t) | |
2004 (beginning-of-line)) | |
2005 (setq beg (point)) | |
24282 | 2006 (c-forward-sexp 1) |
18720 | 2007 (setq end (point)) |
2008 (goto-char beg) | |
2009 (forward-line 1) | |
2010 (setq beg (point))) | |
2011 (if (> end beg) | |
36920 | 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 | 2014 (cond |
2015 ;; CASE 1: indent when at column zero or in lines indentation, | |
2016 ;; otherwise insert a tab | |
2017 ((not c-tab-always-indent) | |
2018 (if (save-excursion | |
2019 (skip-chars-backward " \t") | |
2020 (not (bolp))) | |
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 | 2023 ;; CASE 2: just indent the line |
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 | 2026 ;; CASE 3: if in a literal, insert a tab, but always indent the |
2027 ;; line | |
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 | 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 | 2032 ))))) |
2033 | |
2034 (defun c-indent-exp (&optional shutup-p) | |
36920 | 2035 "Indent each line in the balanced expression following point syntactically. |
2036 If optional SHUTUP-P is non-nil, no errors are signalled if no | |
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 | 2039 (let ((here (point-marker)) |
36920 | 2040 end) |
26817 | 2041 (set-marker-insertion-type here t) |
18720 | 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 | 2053 ;; sanity check |
36920 | 2054 (if (not start) |
2055 (unless shutup-p | |
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 | 2059 (if (not end) |
2060 (unless shutup-p | |
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 | 2065 (goto-char here) |
2066 (set-marker here nil)))) | |
18720 | 2067 |
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 | 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 | 2083 (goto-char here) |
2084 (set-marker here nil)))) | |
2085 | |
36920 | 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 | 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 | 2095 (goto-char start) |
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 | 2100 (beginning-of-line) |
36920 | 2101 (setq c-parsing-error |
2102 (or (let ((endmark (copy-marker end)) | |
2103 (c-parsing-error nil) | |
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 | 2111 (unwind-protect |
2112 (progn | |
2113 (c-progress-init start end 'c-indent-region) | |
2114 (while (and (bolp) | |
2115 (not (eobp)) | |
2116 (< (point) endmark)) | |
2117 ;; update progress | |
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 | 2120 (skip-chars-forward " \t\n") |
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 | 2144 (set-marker endmark nil) |
2145 (c-progress-fini 'c-indent-region)) | |
2146 (c-echo-parsing-error quiet)) | |
2147 c-parsing-error)))) | |
18720 | 2148 |
36920 | 2149 (defun c-fn-region-is-active-p () |
2150 ;; Function version of the macro for use in places that aren't | |
2151 ;; compiled, e.g. in the menus. | |
2152 (c-region-is-active-p)) | |
2153 | |
24282 | 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 | 2157 ;; Emacs has a variable called mark-active, XEmacs uses region-active-p |
2158 (interactive) | |
2159 (if (c-region-is-active-p) | |
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 | 2162 |
18720 | 2163 |
2164 ;; for progress reporting | |
2165 (defvar c-progress-info nil) | |
2166 | |
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 | 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 | 2180 (save-excursion |
2181 (goto-char end) | |
2182 (point-marker)) | |
2183 (nth 1 (current-time)) | |
2184 context)) | |
36920 | 2185 (message "Indenting region...")) |
20143
69ce7b7acfd5
(c-progress-init, c-progress-fini):
Karl Heuer <kwzh@gnu.org>
parents:
20137
diff
changeset
|
2186 )) |
18720 | 2187 |
2188 (defun c-progress-update () | |
2189 ;; update progress | |
2190 (if (not (and c-progress-info c-progress-interval)) | |
2191 nil | |
2192 (let ((now (nth 1 (current-time))) | |
2193 (start (aref c-progress-info 0)) | |
2194 (end (aref c-progress-info 1)) | |
2195 (lastsecs (aref c-progress-info 2))) | |
2196 ;; should we update? currently, update happens every 2 seconds, | |
2197 ;; what's the right value? | |
2198 (if (< c-progress-interval (- now lastsecs)) | |
2199 (progn | |
36920 | 2200 (message "Indenting region... (%d%% complete)" |
18720 | 2201 (/ (* 100 (- (point) start)) (- end start))) |
2202 (aset c-progress-info 2 now))) | |
2203 ))) | |
2204 | |
2205 (defun c-progress-fini (context) | |
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 | 2214 (message "Indenting region... done"))))) |
18720 | 2215 |
2216 | |
2217 | |
2218 ;;; This page handles insertion and removal of backslashes for C macros. | |
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 | 2221 "Insert, align, or delete end-of-line backslashes on the lines in the region. |
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 | 2226 |
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 | 2231 |
18720 | 2232 You can put the region around an entire macro definition and use this |
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 | 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 | 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 | 2450 |
26817 | 2451 |
18720 | 2452 |
26817 | 2453 ;;; Line breaking and paragraph filling. |
2454 | |
36920 | 2455 (defvar c-auto-fill-prefix t) |
2456 (defvar c-lit-limits nil) | |
2457 (defvar c-lit-type nil) | |
2458 | |
26817 | 2459 ;; The filling code is based on a simple theory; leave the intricacies |
2460 ;; of the text handling to the currently active mode for that | |
2461 ;; (e.g. adaptive-fill-mode or filladapt-mode) and do as little as | |
2462 ;; possible to make them work correctly wrt the comment and string | |
2463 ;; separators, one-line paragraphs etc. Unfortunately, when it comes | |
2464 ;; to it, there's quite a lot of special cases to handle which makes | |
2465 ;; the code anything but simple. The intention is that it will work | |
2466 ;; with any well-written text filling package that preserves a fill | |
2467 ;; prefix. | |
2468 ;; | |
2469 ;; We temporarily mask comment starters and enders as necessary for | |
2470 ;; the filling code to do its job on a seemingly normal text block. | |
2471 ;; We do _not_ mask the fill prefix, so it's up to the filling code to | |
2472 ;; preserve it correctly (especially important when filling C++ style | |
2473 ;; line comments). By default, we set up and use adaptive-fill-mode, | |
2474 ;; which is standard in all supported Emacs flavors. | |
2475 | |
2476 (defun c-guess-fill-prefix (lit-limits lit-type) | |
2477 ;; Determine the appropriate comment fill prefix for a block or line | |
2478 ;; comment. Return a cons of the prefix string and the column where | |
2479 ;; it ends. If fill-prefix is set, it'll override. Note that this | |
2480 ;; function also uses the value of point in some heuristics. | |
2481 (let* ((here (point)) | |
2482 (prefix-regexp (concat "[ \t]*\\(" | |
36920 | 2483 c-current-comment-prefix |
26817 | 2484 "\\)[ \t]*")) |
2485 (comment-start-regexp (if (eq lit-type 'c++) | |
2486 prefix-regexp | |
2487 comment-start-skip)) | |
36920 | 2488 prefix-line comment-prefix res comment-text-end) |
26817 | 2489 (cond |
2490 (fill-prefix | |
2491 (setq res (cons fill-prefix | |
2492 ;; Ugly way of getting the column after the fill | |
2493 ;; prefix; it'd be nice with a current-column | |
2494 ;; that works on strings.. | |
2495 (let ((buffer-modified (buffer-modified-p)) | |
2496 (buffer-undo-list t) | |
2497 (start (point))) | |
2498 (unwind-protect | |
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 | 2501 (current-column)) |
2502 (delete-region start (point)) | |
2503 (set-buffer-modified-p buffer-modified)))))) | |
2504 ((eq lit-type 'c++) | |
2505 (save-excursion | |
2506 ;; Set fallback for comment-prefix if none is found. | |
36920 | 2507 (setq comment-prefix "// " |
2508 comment-text-end (cdr lit-limits)) | |
26817 | 2509 (beginning-of-line) |
2510 (if (> (point) (car lit-limits)) | |
2511 ;; The current line is not the comment starter, so the | |
2512 ;; comment has more than one line, and it can therefore be | |
2513 ;; used to find the comment fill prefix. | |
2514 (setq prefix-line (point)) | |
2515 (goto-char (car lit-limits)) | |
2516 (if (and (= (forward-line 1) 0) | |
2517 (< (point) (cdr lit-limits))) | |
2518 ;; The line after the comment starter is inside the | |
2519 ;; comment, so we can use it. | |
2520 (setq prefix-line (point)) | |
2521 ;; The comment is only one line. Take the comment prefix | |
2522 ;; from it and keep the indentation. | |
2523 (goto-char (car lit-limits)) | |
2524 (if (looking-at prefix-regexp) | |
2525 (goto-char (match-end 0)) | |
2526 (forward-char 2) | |
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 | 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 | 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 | 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 | 2566 (save-excursion |
2567 (beginning-of-line) | |
2568 (if (and (> (point) (car lit-limits)) | |
2569 (not (and (looking-at "[ \t]*\\*/") | |
2570 (eq (cdr lit-limits) (match-end 0))))) | |
2571 ;; The current line is not the comment starter and | |
2572 ;; contains more than just the ender, so it's good enough | |
2573 ;; to be used for the comment fill prefix. | |
2574 (setq prefix-line (point)) | |
2575 (goto-char (car lit-limits)) | |
2576 (if (or (/= (forward-line 1) 0) | |
2577 (>= (point) (cdr lit-limits)) | |
2578 (and (looking-at "[ \t]*\\*/") | |
2579 (eq (cdr lit-limits) (match-end 0))) | |
2580 (and (looking-at prefix-regexp) | |
2581 (<= (1- (cdr lit-limits)) (match-end 0))) | |
2582 (and (< here (point)) | |
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 | 2585 ;; The comment is either one line or the next line |
2586 ;; contains just the comment ender. Also, if point is | |
2587 ;; on the comment opener line and the following line is | |
36920 | 2588 ;; empty or doesn't match c-current-comment-prefix we |
26817 | 2589 ;; assume that this is in fact a not yet closed one line |
2590 ;; comment, so we shouldn't look for the comment prefix | |
2591 ;; on the next line. In these cases we have no | |
2592 ;; information about a suitable comment prefix, so we | |
2593 ;; resort to c-block-comment-prefix. | |
2594 (setq comment-prefix (or c-block-comment-prefix "") | |
2595 res (let ((buffer-modified (buffer-modified-p)) | |
2596 (buffer-undo-list t) | |
2597 tmp-pre tmp-post) | |
2598 ;; The comment doesn't give any information | |
2599 ;; about the indentation column. We'll have to | |
2600 ;; temporarily insert a new comment line and | |
2601 ;; indent it to find the correct column. | |
2602 (unwind-protect | |
2603 (progn | |
2604 (goto-char (car lit-limits)) | |
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 | 2608 (forward-char 2) |
2609 (skip-chars-forward " \t")) | |
2610 (when (eq (char-syntax (char-before)) ?\ ) | |
2611 ;; If there's ws on the current | |
2612 ;; line, we'll use it instead of | |
2613 ;; what's ending comment-prefix. | |
2614 (setq comment-prefix | |
2615 (concat (substring comment-prefix | |
2616 0 (string-match | |
2617 "\\s *\\'" | |
2618 comment-prefix)) | |
2619 (buffer-substring-no-properties | |
2620 (save-excursion | |
2621 (skip-chars-backward " \t") | |
2622 (point)) | |
2623 (point))))) | |
2624 (setq tmp-pre (point-marker)) | |
2625 ;; We insert an extra non-whitespace | |
2626 ;; character before the line break and | |
2627 ;; after comment-prefix in case it's | |
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 | 2630 (setq tmp-post (point-marker)) |
36920 | 2631 (indent-according-to-mode) |
26817 | 2632 (goto-char (1- tmp-post)) |
2633 (cons (buffer-substring-no-properties | |
2634 (c-point 'bol) (point)) | |
2635 (current-column))) | |
2636 (when tmp-post | |
2637 (delete-region tmp-pre tmp-post) | |
2638 (set-marker tmp-pre nil) | |
2639 (set-marker tmp-post nil)) | |
2640 (set-buffer-modified-p buffer-modified)))) | |
2641 ;; Otherwise the line after the comment starter is good | |
2642 ;; enough to find the prefix in. | |
2643 (setq prefix-line (point))))))) | |
2644 (or res | |
2645 (save-excursion | |
2646 ;; prefix-line is the bol of a line on which we should try | |
2647 ;; to find the prefix. | |
2648 (let* (fb-string fb-endpos ; Contains any fallback prefix found. | |
2649 (test-line | |
2650 (lambda () | |
2651 (when (and (looking-at prefix-regexp) | |
36920 | 2652 (<= (match-end 0) comment-text-end)) |
2653 (unless (eq (match-end 0) (c-point 'eol)) | |
2654 ;; The match is fine if there's text after it. | |
2655 (throw 'found (cons (buffer-substring-no-properties | |
2656 (match-beginning 0) (match-end 0)) | |
2657 (progn (goto-char (match-end 0)) | |
2658 (current-column))))) | |
26817 | 2659 (unless fb-string |
36920 | 2660 ;; This match is better than nothing, so let's |
2661 ;; remember it in case nothing better is found | |
2662 ;; on another line. | |
26817 | 2663 (setq fb-string (buffer-substring-no-properties |
2664 (match-beginning 0) (match-end 0)) | |
2665 fb-endpos (match-end 0))) | |
2666 t)))) | |
36920 | 2667 (or (catch 'found |
26817 | 2668 ;; Search for a line which has text after the prefix |
2669 ;; so that we get the proper amount of whitespace | |
2670 ;; after it. We start with the current line, then | |
2671 ;; search backwards, then forwards. | |
2672 (goto-char prefix-line) | |
2673 (when (and (funcall test-line) | |
36920 | 2674 (or (/= (match-end 1) (match-end 0)) |
2675 ;; The whitespace is sucked up by the | |
2676 ;; first [ \t]* glob if the prefix is empty. | |
2677 (and (= (match-beginning 1) (match-end 1)) | |
2678 (/= (match-beginning 0) (match-end 0))))) | |
26817 | 2679 ;; If the current line doesn't have text but do |
2680 ;; have whitespace after the prefix, we'll use it. | |
36920 | 2681 (throw 'found (cons fb-string |
2682 (progn (goto-char fb-endpos) | |
2683 (current-column))))) | |
2684 (if (eq lit-type 'c++) | |
2685 ;; For line comments we can search up to and | |
2686 ;; including the first line. | |
2687 (while (and (zerop (forward-line -1)) | |
2688 (>= (point) (car lit-limits))) | |
2689 (funcall test-line)) | |
2690 ;; For block comments we must stop before the | |
2691 ;; block starter. | |
2692 (while (and (zerop (forward-line -1)) | |
2693 (> (point) (car lit-limits))) | |
2694 (funcall test-line))) | |
26817 | 2695 (goto-char prefix-line) |
2696 (while (and (zerop (forward-line 1)) | |
2697 (< (point) (cdr lit-limits))) | |
2698 (funcall test-line)) | |
36920 | 2699 (goto-char prefix-line) |
26817 | 2700 nil) |
36920 | 2701 (when fb-string |
26817 | 2702 ;; A good line wasn't found, but at least we have a |
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 | 2711 ((progn |
2712 ;; Check if there's any whitespace padding | |
2713 ;; on the comment start line that we can | |
2714 ;; use after the prefix. | |
2715 (goto-char (car lit-limits)) | |
2716 (if (looking-at comment-start-regexp) | |
2717 (goto-char (match-end 0)) | |
2718 (forward-char 2) | |
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 | 2722 (setq fb-string (buffer-substring-no-properties |
2723 (save-excursion | |
2724 (skip-chars-backward " \t") | |
2725 (point)) | |
2726 (point))) | |
2727 (goto-char fb-endpos) | |
2728 (skip-chars-backward " \t") | |
2729 (let ((buffer-modified (buffer-modified-p)) | |
2730 (buffer-undo-list t) | |
2731 (tmp (point))) | |
2732 ;; Got to mess in the buffer once again to | |
2733 ;; ensure the column gets correct. :P | |
2734 (unwind-protect | |
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 | 2737 (cons (buffer-substring-no-properties |
2738 (c-point 'bol) | |
2739 (point)) | |
2740 (current-column))) | |
36920 | 2741 (delete-region tmp (point)) |
2742 (set-buffer-modified-p buffer-modified)))) | |
26817 | 2743 (t |
2744 ;; Last resort: Just add a single space after | |
2745 ;; the prefix. | |
2746 (cons (concat fb-string " ") | |
2747 (progn (goto-char fb-endpos) | |
36920 | 2748 (1+ (current-column))))))) |
26817 | 2749 ;; The line doesn't match the comment prefix regexp. |
2750 (if comment-prefix | |
2751 ;; We have a fallback for line comments that we must use. | |
2752 (cons (concat (buffer-substring-no-properties | |
2753 prefix-line (c-point 'boi)) | |
2754 comment-prefix) | |
2755 (progn (back-to-indentation) | |
2756 (+ (current-column) (length comment-prefix)))) | |
2757 ;; Assume we are dealing with a "free text" block | |
2758 ;; comment where the lines doesn't have any comment | |
2759 ;; prefix at all and we should just fill it as | |
2760 ;; normal text. | |
36920 | 2761 '("" . 0)))))) |
26817 | 2762 )) |
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 | 3028 (defun c-fill-paragraph (&optional arg) |
3029 "Like \\[fill-paragraph] but handles C and C++ style comments. | |
26817 | 3030 If any of the current line is a comment or within a comment, fill the |
3031 comment or the paragraph of it that point is in, preserving the | |
3032 comment indentation or line-starting decorations (see the | |
3033 `c-comment-prefix-regexp' and `c-block-comment-prefix' variables for | |
3034 details). | |
18720 | 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 | 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 | 3054 ;; Always return t. This has the effect that if filling isn't done |
3055 ;; above, it isn't done at all, and it's therefore effectively | |
3056 ;; disabled in normal code. | |
3057 t) | |
18720 | 3058 |
26817 | 3059 (defun c-do-auto-fill () |
3060 ;; Do automatic filling if not inside a context where it should be | |
3061 ;; ignored. | |
3062 (let ((c-auto-fill-prefix | |
3063 ;; The decision whether the line should be broken is actually | |
3064 ;; done in c-indent-new-comment-line, which do-auto-fill | |
3065 ;; calls to break lines. We just set this special variable | |
3066 ;; so that we'll know when we're called from there. It's | |
3067 ;; also used to detect whether fill-prefix is user set or | |
3068 ;; generated automatically by do-auto-fill. | |
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 | 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 | 3074 If inside a comment and `comment-multi-line' is non-nil, the |
3075 indentation and line prefix are preserved (see the | |
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 | 3082 |
26817 | 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 | 3088 (interactive) |
3089 (let ((fill-prefix fill-prefix) | |
3090 (do-line-break | |
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 | 3096 ;; Already know the literal type and limits when called from |
3097 ;; c-context-line-break. | |
36920 | 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 | 3101 (when (not (eq c-auto-fill-prefix t)) |
26817 | 3102 ;; Called from do-auto-fill. |
3103 (unless c-lit-limits | |
3104 (setq c-lit-limits (c-literal-limits nil nil t))) | |
3105 (unless c-lit-type | |
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 | 3108 ((null c-lit-type) 'code) |
3109 (t c-lit-type)) | |
3110 c-ignore-auto-fill) | |
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 | 3126 (cond ((eq fill-prefix t) |
3127 ;; A call from do-auto-fill which should be ignored. | |
3128 ) | |
3129 (fill-prefix | |
3130 ;; A fill-prefix overrides anything. | |
3131 (funcall do-line-break) | |
3132 (insert-and-inherit fill-prefix)) | |
3133 ((progn | |
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 | 3136 (unless c-lit-type |
3137 (setq c-lit-type (c-literal-type c-lit-limits))) | |
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 | 3145 ;; Inside a comment that should be continued. |
3146 (let ((fill (c-guess-fill-prefix | |
3147 (setq c-lit-limits | |
3148 (c-collect-line-comments c-lit-limits)) | |
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 | 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 | 3188 (funcall do-line-break) |
3189 (insert-and-inherit (car fill)))) | |
3190 ;; Inside a comment that should be broken. | |
3191 (let ((comment-start comment-start) | |
3192 (comment-end comment-end) | |
3193 col) | |
3194 (if (eq c-lit-type 'c) | |
3195 (unless (string-match "[ \t]*/\\*" comment-start) | |
3196 (setq comment-start "/* " comment-end " */")) | |
3197 (unless (string-match "[ \t]*//" comment-start) | |
3198 (setq comment-start "// " comment-end ""))) | |
3199 (setq col (save-excursion | |
3200 (back-to-indentation) | |
3201 (current-column))) | |
3202 (funcall do-line-break) | |
3203 (when (and comment-end (not (equal comment-end ""))) | |
3204 (forward-char -1) | |
3205 (insert-and-inherit comment-end) | |
3206 (forward-char 1)) | |
3207 ;; c-comment-indent may look at the current | |
3208 ;; indentation, so let's start out with the same | |
3209 ;; indentation as the previous one. | |
3210 (indent-to col) | |
3211 (insert-and-inherit comment-start) | |
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 | 3224 (t |
3225 ;; Somewhere else in the code. | |
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 | 3231 (funcall do-line-break) |
3232 (indent-to col)))))) | |
3233 | |
3234 (defalias 'c-comment-line-break-function 'c-indent-new-comment-line) | |
3235 (make-obsolete 'c-comment-line-break-function 'c-indent-new-comment-line) | |
3236 | |
3237 ;; advice for indent-new-comment-line for older Emacsen | |
3238 (unless (boundp 'comment-line-break-function) | |
36920 | 3239 (defvar c-inside-line-break-advice nil) |
26817 | 3240 (defadvice indent-new-comment-line (around c-line-break-advice |
3241 activate preactivate) | |
3242 "Call `c-indent-new-comment-line' if in CC Mode." | |
36920 | 3243 (if (or c-inside-line-break-advice |
26817 | 3244 (not c-buffer-is-cc-mode)) |
3245 ad-do-it | |
36920 | 3246 (let ((c-inside-line-break-advice t)) |
26817 | 3247 (c-indent-new-comment-line (ad-get-arg 0)))))) |
3248 | |
3249 (defun c-context-line-break () | |
3250 "Do a line break suitable to the context. | |
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 | 3261 |
3262 When point is inside a comment, continue it with the appropriate | |
3263 comment prefix (see the `c-comment-prefix-regexp' and | |
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 | 3266 (interactive "*") |
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 | 3270 (if (or (eq c-lit-type 'c) |
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 | 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 | 3286 (let ((comment-multi-line t) |
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 | 3290 (newline) |
3291 ;; c-indent-line may look at the current indentation, so let's | |
3292 ;; start out with the same indentation as the previous line. | |
3293 (let ((col (save-excursion | |
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 | 3298 (indent-to col)) |
36920 | 3299 (indent-according-to-mode)))) |
18720 | 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 | 3316 |
36920 | 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 | 3319 ;;; cc-cmds.el ends here |