Mercurial > emacs
annotate lisp/obsolete/c-mode.el @ 42960:3d42a88083b3
*** empty log message ***
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Fri, 25 Jan 2002 14:11:11 +0000 |
parents | 5223683cd329 |
children | bd315b9fa3f0 |
rev | line source |
---|---|
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1 ;;; c-mode.el --- C code editing commands for Emacs |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
2 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
3 ;; Copyright (C) 1985, 86, 87, 92, 94, 95 Free Software Foundation, Inc. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
4 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
5 ;; Maintainer: FSF |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
6 ;; Keywords: c |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
7 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
8 ;; This file is part of GNU Emacs. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
9 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
10 ;; GNU Emacs is free software; you can redistribute it and/or modify |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
11 ;; it under the terms of the GNU General Public License as published by |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
12 ;; the Free Software Foundation; either version 2, or (at your option) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
13 ;; any later version. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
14 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
15 ;; GNU Emacs is distributed in the hope that it will be useful, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
18 ;; GNU General Public License for more details. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
19 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
20 ;; You should have received a copy of the GNU General Public License |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
23 ;; Boston, MA 02111-1307, USA. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
24 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
25 ;;; Commentary: |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
26 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
27 ;; A smart editing mode for C code. It knows a lot about C syntax and tries |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
28 ;; to position the cursor according to C layout conventions. You can |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
29 ;; change the details of the layout style with option variables. Load it |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
30 ;; and do M-x describe-mode for details. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
31 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
32 ;;; Code: |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
33 (defgroup old-c nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
34 "Old C code editing commands for Emacs." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
35 ;; This group should have no parent. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
36 ;; We don't want it to be loaded except on explicit request. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
37 :prefix "c-") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
38 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
39 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
40 (defvar c-mode-abbrev-table nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
41 "Abbrev table in use in C mode.") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
42 (define-abbrev-table 'c-mode-abbrev-table ()) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
43 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
44 (defvar c-mode-map (make-sparse-keymap) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
45 "Keymap used in C mode.") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
46 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
47 (define-key c-mode-map "{" 'electric-c-brace) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
48 (define-key c-mode-map "}" 'electric-c-brace) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
49 (define-key c-mode-map ";" 'electric-c-semi) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
50 (define-key c-mode-map "#" 'electric-c-sharp-sign) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
51 (define-key c-mode-map ":" 'electric-c-terminator) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
52 (define-key c-mode-map "\e\C-h" 'mark-c-function) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
53 (define-key c-mode-map "\e\C-q" 'indent-c-exp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
54 (define-key c-mode-map "\ea" 'c-beginning-of-statement) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
55 (define-key c-mode-map "\ee" 'c-end-of-statement) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
56 (define-key c-mode-map "\C-c\C-n" 'c-forward-conditional) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
57 (define-key c-mode-map "\C-c\C-p" 'c-backward-conditional) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
58 (define-key c-mode-map "\C-c\C-u" 'c-up-conditional) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
59 (define-key c-mode-map "\177" 'backward-delete-char-untabify) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
60 (define-key c-mode-map "\t" 'c-indent-command) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
61 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
62 (define-key c-mode-map [menu-bar] (make-sparse-keymap)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
63 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
64 ;; "C-mode" is not strictly the right punctuation--it should be "C |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
65 ;; mode"--but that would look like two menu items. "C-mode" is the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
66 ;; best alternative I can think of. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
67 (define-key c-mode-map [menu-bar c] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
68 (cons "C-mode" (make-sparse-keymap "C-mode"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
69 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
70 (define-key c-mode-map [menu-bar c comment-region] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
71 '("Comment Out Region" . comment-region)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
72 (define-key c-mode-map [menu-bar c c-macro-expand] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
73 '("Macro Expand Region" . c-macro-expand)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
74 (define-key c-mode-map [menu-bar c c-backslash-region] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
75 '("Backslashify" . c-backslash-region)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
76 (define-key c-mode-map [menu-bar c indent-exp] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
77 '("Indent Expression" . indent-c-exp)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
78 (define-key c-mode-map [menu-bar c indent-line] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
79 '("Indent Line" . c-indent-command)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
80 (define-key c-mode-map [menu-bar c fill] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
81 '("Fill Comment Paragraph" . c-fill-paragraph)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
82 (define-key c-mode-map [menu-bar c cpp-highlight-buffer] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
83 '("Highlight Conditionals" . cpp-highlight-buffer)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
84 (define-key c-mode-map [menu-bar c up] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
85 '("Up Conditional" . c-up-conditional)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
86 (define-key c-mode-map [menu-bar c backward] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
87 '("Backward Conditional" . c-backward-conditional)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
88 (define-key c-mode-map [menu-bar c forward] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
89 '("Forward Conditional" . c-forward-conditional)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
90 (define-key c-mode-map [menu-bar c backward-stmt] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
91 '("Backward Statement" . c-beginning-of-statement)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
92 (define-key c-mode-map [menu-bar c forward-stmt] |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
93 '("Forward Statement" . c-end-of-statement)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
94 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
95 (put 'comment-region 'menu-enable 'mark-active) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
96 (put 'c-macro-expand 'menu-enable 'mark-active) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
97 (put 'c-backslash-region 'menu-enable 'mark-active) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
98 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
99 (autoload 'c-macro-expand "cmacexp" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
100 "Display the result of expanding all C macros occurring in the region. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
101 The expansion is entirely correct because it uses the C preprocessor." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
102 t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
103 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
104 (defvar c-mode-syntax-table nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
105 "Syntax table in use in C-mode buffers.") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
106 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
107 (if c-mode-syntax-table |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
108 () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
109 (setq c-mode-syntax-table (make-syntax-table)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
110 (modify-syntax-entry ?\\ "\\" c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
111 (modify-syntax-entry ?/ ". 14" c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
112 (modify-syntax-entry ?* ". 23" c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
113 (modify-syntax-entry ?+ "." c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
114 (modify-syntax-entry ?- "." c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
115 (modify-syntax-entry ?= "." c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
116 (modify-syntax-entry ?% "." c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
117 (modify-syntax-entry ?< "." c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
118 (modify-syntax-entry ?> "." c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
119 (modify-syntax-entry ?& "." c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
120 (modify-syntax-entry ?| "." c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
121 (modify-syntax-entry ?\' "\"" c-mode-syntax-table)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
122 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
123 (defcustom c-indent-level 2 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
124 "*Indentation of C statements with respect to containing block." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
125 :type 'integer |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
126 :group 'old-c) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
127 (defcustom c-brace-imaginary-offset 0 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
128 "*Imagined indentation of a C open brace that actually follows a statement." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
129 :type 'integer |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
130 :group 'old-c) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
131 (defcustom c-brace-offset 0 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
132 "*Extra indentation for braces, compared with other text in same context." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
133 :type 'integer |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
134 :group 'old-c) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
135 (defcustom c-argdecl-indent 5 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
136 "*Indentation level of declarations of C function arguments." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
137 :type 'integer |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
138 :group 'old-c) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
139 (defcustom c-label-offset -2 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
140 "*Offset of C label lines and case statements relative to usual indentation." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
141 :type 'integer |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
142 :group 'old-c) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
143 (defcustom c-continued-statement-offset 2 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
144 "*Extra indent for lines not starting new statements." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
145 :type 'integer |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
146 :group 'old-c) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
147 (defcustom c-continued-brace-offset 0 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
148 "*Extra indent for substatements that start with open-braces. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
149 This is in addition to `c-continued-statement-offset'." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
150 :type 'integer |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
151 :group 'old-c) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
152 (defconst c-style-alist |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
153 '(("GNU" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
154 (c-indent-level . 2) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
155 (c-argdecl-indent . 5) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
156 (c-brace-offset . 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
157 (c-continued-brace-offset . 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
158 (c-label-offset . -2) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
159 (c-continued-statement-offset . 2)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
160 ("K&R" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
161 (c-indent-level . 5) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
162 (c-argdecl-indent . 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
163 (c-brace-offset . 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
164 (c-continued-brace-offset . -5) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
165 (c-label-offset . -5) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
166 (c-continued-statement-offset . 5)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
167 ("BSD" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
168 (c-indent-level . 4) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
169 (c-argdecl-indent . 4) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
170 (c-brace-offset . 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
171 (c-continued-brace-offset . -4) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
172 (c-label-offset . -4) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
173 (c-continued-statement-offset . 4)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
174 ("C++" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
175 (c-indent-level . 4) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
176 (c-argdecl-indent . 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
177 (c-brace-offset . 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
178 (c-continued-brace-offset . -4) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
179 (c-label-offset . -4) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
180 (c-continued-statement-offset . 4) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
181 (c-auto-newline . t)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
182 ("Whitesmith" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
183 (c-indent-level . 4) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
184 (c-argdecl-indent . 4) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
185 (c-brace-offset . 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
186 (c-continued-brace-offset . 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
187 (c-label-offset . -4) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
188 (c-continued-statement-offset . 4)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
189 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
190 (defcustom c-auto-newline nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
191 "*Non-nil means automatically newline before and after braces, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
192 and after colons and semicolons, inserted in C code. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
193 If you do not want a leading newline before braces then use: |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
194 (define-key c-mode-map \"{\" 'electric-c-semi)" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
195 :type 'boolean |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
196 :group 'old-c) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
197 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
198 (defcustom c-tab-always-indent t |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
199 "*Non-nil means TAB in C mode should always reindent the current line, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
200 regardless of where in the line point is when the TAB command is used." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
201 :type 'boolean |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
202 :group 'old-c) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
203 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
204 ;;; Regular expression used internally to recognize labels in switch |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
205 ;;; statements. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
206 (defconst c-switch-label-regexp "case[ \t'/(]\\|default[ \t]*:") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
207 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
208 ;; This is actually the expression for C++ mode, but it's used for C too. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
209 (defvar c-imenu-generic-expression |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
210 `((nil |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
211 ,(concat |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
212 "^" ; beginning of line is required |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
213 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
214 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
215 "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right? |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
216 |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
217 "\\(" ; last type spec including */& |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
218 "[a-zA-Z0-9_:]+" |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
219 "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
220 "\\)?" ; if there is a last type spec |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
221 "\\(" ; name; take that into the imenu entry |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
222 "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor... |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
223 ; (may not contain * because then |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
224 ; "a::operator char*" would become "char*"!) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
225 "\\|" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
226 "\\([a-zA-Z0-9_:~]*::\\)?operator" |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
227 "[^a-zA-Z1-9_][^(]*" ; ...or operator |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
228 " \\)" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
229 "[ \t]*([^)]*)[ \t\n]*[^ ;]" ; require something other than a ; after |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
230 ; the (...) to avoid prototypes. Can't |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
231 ; catch cases with () inside the parentheses |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
232 ; surrounding the parameters |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
233 ; (like "int foo(int a=bar()) {...}" |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
234 |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
235 ) 6) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
236 ("Class" |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
237 ,(concat |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
238 "^" ; beginning of line is required |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
239 "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
240 "class[ \t]+" |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
241 "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
242 "[ \t]*[:{]" |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
243 ) 2) |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
244 ;; Example of generic expression for finding prototypes, structs, unions, enums. |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
245 ;; Uncomment if you want to find these too. It will be a bit slower gathering |
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
246 ;; the indexes. |
41652 | 247 ;;; ("Prototypes" |
248 ;;; (, | |
249 ;;; (concat | |
250 ;;; "^" ; beginning of line is required | |
251 ;;; "\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a "template <...>" | |
252 ;;; "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; type specs; there can be no | |
253 ;;; "\\([a-zA-Z0-9_:]+[ \t]+\\)?" ; more than 3 tokens, right? | |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
254 |
41652 | 255 ;;; "\\(" ; last type spec including */& |
256 ;;; "[a-zA-Z0-9_:]+" | |
257 ;;; "\\([ \t]*[*&]+[ \t]*\\|[ \t]+\\)" ; either pointer/ref sign or whitespace | |
258 ;;; "\\)?" ; if there is a last type spec | |
259 ;;; "\\(" ; name; take that into the imenu entry | |
260 ;;; "[a-zA-Z0-9_:~]+" ; member function, ctor or dtor... | |
261 ;;; ; (may not contain * because then | |
262 ;;; ; "a::operator char*" would become "char*"!) | |
263 ;;; "\\|" | |
264 ;;; "\\([a-zA-Z0-9_:~]*::\\)?operator" | |
265 ;;; "[^a-zA-Z1-9_][^(]*" ; ...or operator | |
266 ;;; " \\)" | |
267 ;;; "[ \t]*([^)]*)[ \t\n]*;" ; require ';' after | |
268 ;;; ; the (...) Can't | |
269 ;;; ; catch cases with () inside the parentheses | |
270 ;;; ; surrounding the parameters | |
271 ;;; ; (like "int foo(int a=bar());" | |
272 ;;; )) 6) | |
273 ;;; ("Struct" | |
274 ;;; (, (concat | |
275 ;;; "^" ; beginning of line is required | |
276 ;;; "\\(static[ \t]+\\)?" ; there may be static or const. | |
277 ;;; "\\(const[ \t]+\\)?" | |
278 ;;; "struct[ \t]+" | |
279 ;;; "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get | |
280 ;;; "[ \t]*[{]" | |
281 ;;; )) 3) | |
282 ;;; ("Enum" | |
283 ;;; (, (concat | |
284 ;;; "^" ; beginning of line is required | |
285 ;;; "\\(static[ \t]+\\)?" ; there may be static or const. | |
286 ;;; "\\(const[ \t]+\\)?" | |
287 ;;; "enum[ \t]+" | |
288 ;;; "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get | |
289 ;;; "[ \t]*[{]" | |
290 ;;; )) 3) | |
291 ;;; ("Union" | |
292 ;;; (, (concat | |
293 ;;; "^" ; beginning of line is required | |
294 ;;; "\\(static[ \t]+\\)?" ; there may be static or const. | |
295 ;;; "\\(const[ \t]+\\)?" | |
296 ;;; "union[ \t]+" | |
297 ;;; "\\([a-zA-Z0-9_]+\\)" ; this is the string we want to get | |
298 ;;; "[ \t]*[{]" | |
299 ;;; )) 3) | |
41608
45db352a0971
Converted backquote to the new style.
Sam Steingold <sds@gnu.org>
parents:
34454
diff
changeset
|
300 ) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
301 "Imenu generic expression for C mode. See `imenu-generic-expression'.") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
302 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
303 (defun c-mode () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
304 "Major mode for editing C code. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
305 Expression and list commands understand all C brackets. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
306 Tab indents for C code. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
307 Comments are delimited with /* ... */. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
308 Paragraphs are separated by blank lines only. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
309 Delete converts tabs to spaces as it moves back. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
310 \\{c-mode-map} |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
311 Variables controlling indentation style: |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
312 c-tab-always-indent |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
313 Non-nil means TAB in C mode should always reindent the current line, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
314 regardless of where in the line point is when the TAB command is used. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
315 c-auto-newline |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
316 Non-nil means automatically newline before and after braces, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
317 and after colons and semicolons, inserted in C code. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
318 c-indent-level |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
319 Indentation of C statements within surrounding block. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
320 The surrounding block's indentation is the indentation |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
321 of the line on which the open-brace appears. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
322 c-continued-statement-offset |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
323 Extra indentation given to a substatement, such as the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
324 then-clause of an if or body of a while. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
325 c-continued-brace-offset |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
326 Extra indentation given to a brace that starts a substatement. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
327 This is in addition to c-continued-statement-offset. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
328 c-brace-offset |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
329 Extra indentation for line if it starts with an open brace. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
330 c-brace-imaginary-offset |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
331 An open brace following other text is treated as if it were |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
332 this far to the right of the start of its line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
333 c-argdecl-indent |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
334 Indentation level of declarations of C function arguments. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
335 c-label-offset |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
336 Extra indentation for line that is a label, or case or default. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
337 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
338 Settings for K&R and BSD indentation styles are |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
339 c-indent-level 5 8 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
340 c-continued-statement-offset 5 8 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
341 c-brace-offset -5 -8 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
342 c-argdecl-indent 0 8 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
343 c-label-offset -5 -8 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
344 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
345 Turning on C mode calls the value of the variable c-mode-hook with no args, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
346 if that value is non-nil." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
347 (interactive) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
348 (kill-all-local-variables) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
349 (use-local-map c-mode-map) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
350 (setq major-mode 'c-mode) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
351 (setq mode-name "C") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
352 (setq local-abbrev-table c-mode-abbrev-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
353 (set-syntax-table c-mode-syntax-table) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
354 (make-local-variable 'paragraph-start) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
355 (setq paragraph-start (concat "$\\|" page-delimiter)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
356 (make-local-variable 'paragraph-separate) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
357 (setq paragraph-separate paragraph-start) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
358 (make-local-variable 'paragraph-ignore-fill-prefix) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
359 (setq paragraph-ignore-fill-prefix t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
360 (make-local-variable 'fill-paragraph-function) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
361 (setq fill-paragraph-function 'c-fill-paragraph) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
362 (make-local-variable 'indent-line-function) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
363 (setq indent-line-function 'c-indent-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
364 (make-local-variable 'indent-region-function) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
365 (setq indent-region-function 'c-indent-region) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
366 (make-local-variable 'require-final-newline) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
367 (setq require-final-newline t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
368 (make-local-variable 'outline-regexp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
369 (setq outline-regexp "[^#\n\^M]") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
370 (make-local-variable 'outline-level) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
371 (setq outline-level 'c-outline-level) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
372 (make-local-variable 'comment-start) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
373 (setq comment-start "/* ") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
374 (make-local-variable 'comment-end) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
375 (setq comment-end " */") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
376 (make-local-variable 'comment-start-skip) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
377 (setq comment-start-skip "/\\*+ *") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
378 (make-local-variable 'comment-indent-function) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
379 (setq comment-indent-function 'c-comment-indent) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
380 (make-local-variable 'comment-multi-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
381 (setq comment-multi-line t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
382 (make-local-variable 'parse-sexp-ignore-comments) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
383 (setq parse-sexp-ignore-comments t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
384 (make-local-variable 'imenu-generic-expression) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
385 (setq imenu-generic-expression c-imenu-generic-expression) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
386 (setq imenu-case-fold-search nil) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
387 (run-hooks 'c-mode-hook)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
388 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
389 (defun c-outline-level () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
390 ;; This so that `current-column' DTRT in otherwise-hidden text. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
391 (let (buffer-invisibility-spec) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
392 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
393 (skip-chars-forward "\t ") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
394 (current-column)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
395 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
396 ;; This is used by indent-for-comment |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
397 ;; to decide how much to indent a comment in C code |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
398 ;; based on its context. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
399 (defun c-comment-indent () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
400 (if (looking-at "^/\\*") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
401 0 ;Existing comment at bol stays there. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
402 (let ((opoint (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
403 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
404 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
405 (cond ((looking-at "[ \t]*}[ \t]*\\($\\|/\\*\\)") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
406 ;; A comment following a solitary close-brace |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
407 ;; should have only one space. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
408 (search-forward "}") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
409 (1+ (current-column))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
410 ((or (looking-at "^#[ \t]*endif[ \t]*") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
411 (looking-at "^#[ \t]*else[ \t]*")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
412 7) ;2 spaces after #endif |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
413 ((progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
414 (goto-char opoint) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
415 (skip-chars-backward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
416 (and (= comment-column 0) (bolp))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
417 ;; If comment-column is 0, and nothing but space |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
418 ;; before the comment, align it at 0 rather than 1. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
419 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
420 (t |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
421 (max (1+ (current-column)) ;Else indent at comment column |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
422 comment-column))))))) ; except leave at least one space. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
423 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
424 (defun c-fill-paragraph (&optional arg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
425 "Like \\[fill-paragraph] but handle C comments. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
426 If any of the current line is a comment or within a comment, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
427 fill the comment or the paragraph of it that point is in, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
428 preserving the comment indentation or line-starting decorations." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
429 (interactive "P") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
430 (let* (comment-start-place |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
431 (first-line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
432 ;; Check for obvious entry to comment. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
433 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
434 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
435 (skip-chars-forward " \t\n") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
436 (and (looking-at comment-start-skip) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
437 (setq comment-start-place (point)))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
438 (if (and (eq major-mode 'c++-mode) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
439 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
440 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
441 (looking-at ".*//"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
442 (let (fill-prefix |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
443 (paragraph-start |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
444 ;; Lines containing just a comment start or just an end |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
445 ;; should not be filled into paragraphs they are next to. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
446 (concat |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
447 paragraph-start |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
448 "\\|[ \t]*/\\*[ \t]*$\\|[ \t]*\\*/[ \t]*$\\|[ \t/*]*$")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
449 (paragraph-separate |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
450 (concat |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
451 paragraph-separate |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
452 "\\|[ \t]*/\\*[ \t]*$\\|[ \t]*\\*/[ \t]*$\\|[ \t/*]*$"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
453 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
454 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
455 ;; Move up to first line of this comment. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
456 (while (and (not (bobp)) (looking-at "[ \t]*//")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
457 (forward-line -1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
458 (if (not (looking-at ".*//")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
459 (forward-line 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
460 ;; Find the comment start in this line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
461 (re-search-forward "[ \t]*//[ \t]*") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
462 ;; Set the fill-prefix to be what all lines except the first |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
463 ;; should start with. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
464 (let ((endcol (current-column))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
465 (skip-chars-backward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
466 (setq fill-prefix |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
467 (concat (make-string (- (current-column) 2) ?\ ) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
468 "//" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
469 (make-string (- endcol (current-column)) ?\ )))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
470 (save-restriction |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
471 ;; Narrow down to just the lines of this comment. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
472 (narrow-to-region (point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
473 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
474 (forward-line 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
475 (while (looking-at "[ \t]*//") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
476 (forward-line 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
477 (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
478 (insert fill-prefix) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
479 (fill-paragraph arg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
480 (delete-region (point-min) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
481 (+ (point-min) (length fill-prefix)))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
482 (if (or first-line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
483 ;; t if we enter a comment between start of function and this line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
484 (eq (calculate-c-indent) t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
485 ;; t if this line contains a comment starter. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
486 (setq first-line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
487 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
488 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
489 (prog1 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
490 (re-search-forward comment-start-skip |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
491 (save-excursion (end-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
492 (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
493 t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
494 (setq comment-start-place (point)))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
495 ;; Inside a comment: fill one comment paragraph. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
496 (let ((fill-prefix |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
497 ;; The prefix for each line of this paragraph |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
498 ;; is the appropriate part of the start of this line, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
499 ;; up to the column at which text should be indented. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
500 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
501 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
502 (if (looking-at "[ \t]*/\\*.*\\*/") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
503 (progn (re-search-forward comment-start-skip) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
504 (make-string (current-column) ?\ )) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
505 (if first-line (forward-line 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
506 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
507 (let ((line-width (progn (end-of-line) (current-column)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
508 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
509 (prog1 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
510 (buffer-substring |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
511 (point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
512 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
513 ;; How shall we decide where the end of the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
514 ;; fill-prefix is? |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
515 ;; calculate-c-indent-within-comment bases its value |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
516 ;; on the indentation of previous lines; if they're |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
517 ;; indented specially, it could return a column |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
518 ;; that's well into the current line's text. So |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
519 ;; we'll take at most that many space, tab, or * |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
520 ;; characters, and use that as our fill prefix. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
521 (let ((max-prefix-end |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
522 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
523 (move-to-column |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
524 (calculate-c-indent-within-comment t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
525 t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
526 (point)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
527 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
528 (skip-chars-forward " \t*" max-prefix-end) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
529 ;; Don't include part of comment terminator |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
530 ;; in the fill-prefix. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
531 (and (eq (following-char) ?/) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
532 (eq (preceding-char) ?*) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
533 (backward-char 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
534 (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
535 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
536 ;; If the comment is only one line followed by a blank |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
537 ;; line, calling move-to-column above may have added |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
538 ;; some spaces and tabs to the end of the line; the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
539 ;; fill-paragraph function will then delete it and the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
540 ;; newline following it, so we'll lose a blank line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
541 ;; when we shouldn't. So delete anything |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
542 ;; move-to-column added to the end of the line. We |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
543 ;; record the line width instead of the position of the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
544 ;; old line end because move-to-column might break a |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
545 ;; tab into spaces, and the new characters introduced |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
546 ;; there shouldn't be deleted. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
547 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
548 ;; If you can see a better way to do this, please make |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
549 ;; the change. This seems very messy to me. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
550 (delete-region (progn (move-to-column line-width) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
551 (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
552 (progn (end-of-line) (point)))))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
553 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
554 (paragraph-start |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
555 ;; Lines containing just a comment start or just an end |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
556 ;; should not be filled into paragraphs they are next to. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
557 (concat |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
558 paragraph-start |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
559 "\\|[ \t]*/\\*[ \t]*$\\|[ \t]*\\*/[ \t]*$\\|[ \t/*]*$")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
560 (paragraph-separate |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
561 (concat |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
562 paragraph-separate |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
563 "\\|[ \t]*/\\*[ \t]*$\\|[ \t]*\\*/[ \t]*$\\|[ \t/*]*$")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
564 (chars-to-delete 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
565 (save-restriction |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
566 ;; Don't fill the comment together with the code following it. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
567 ;; So temporarily exclude everything before the comment start, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
568 ;; and everything after the line where the comment ends. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
569 ;; If comment-start-place is non-nil, the comment starter is there. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
570 ;; Otherwise, point is inside the comment. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
571 (narrow-to-region (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
572 (if comment-start-place |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
573 (goto-char comment-start-place) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
574 (search-backward "/*")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
575 ;; Protect text before the comment start |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
576 ;; by excluding it. Add spaces to bring back |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
577 ;; proper indentation of that point. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
578 (let ((column (current-column))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
579 (prog1 (point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
580 (setq chars-to-delete column) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
581 (insert-char ?\ column)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
582 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
583 (if comment-start-place |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
584 (goto-char (+ comment-start-place 2))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
585 (search-forward "*/" nil 'move) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
586 (forward-line 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
587 (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
588 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
589 (goto-char (point-max)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
590 (forward-line -1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
591 ;; And comment terminator was on a separate line before, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
592 ;; keep it that way. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
593 ;; This also avoids another problem: |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
594 ;; if the fill-prefix ends in a *, it could eat up |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
595 ;; the * of the comment terminator. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
596 (if (looking-at "[ \t]*\\*/") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
597 (narrow-to-region (point-min) (point)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
598 (fill-paragraph arg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
599 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
600 ;; Delete the chars we inserted to avoid clobbering |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
601 ;; the stuff before the comment start. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
602 (goto-char (point-min)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
603 (if (> chars-to-delete 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
604 (delete-region (point) (+ (point) chars-to-delete))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
605 ;; Find the comment ender (should be on last line of buffer, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
606 ;; given the narrowing) and don't leave it on its own line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
607 ;; Do this with a fill command, so as to preserve sentence |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
608 ;; boundaries. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
609 (goto-char (point-max)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
610 (forward-line -1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
611 (search-forward "*/" nil 'move) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
612 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
613 (if (looking-at "[ \t]*\\*/") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
614 (let ((fill-column (+ fill-column 9999))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
615 (forward-line -1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
616 (fill-region-as-paragraph (point) (point-max))))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
617 ;; Outside of comments: do ordinary filling. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
618 (fill-paragraph arg))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
619 t)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
620 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
621 (defun electric-c-brace (arg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
622 "Insert character and correct line's indentation." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
623 (interactive "P") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
624 (let (insertpos) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
625 (if (and (not arg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
626 (eolp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
627 (or (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
628 (skip-chars-backward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
629 (bolp)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
630 (if c-auto-newline (progn (c-indent-line) (newline) t) nil))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
631 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
632 (insert last-command-char) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
633 (c-indent-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
634 (if c-auto-newline |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
635 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
636 (newline) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
637 ;; (newline) may have done auto-fill |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
638 (setq insertpos (- (point) 2)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
639 (c-indent-line))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
640 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
641 (if insertpos (goto-char (1+ insertpos))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
642 (delete-char -1)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
643 (if insertpos |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
644 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
645 (goto-char insertpos) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
646 (self-insert-command (prefix-numeric-value arg))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
647 (self-insert-command (prefix-numeric-value arg))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
648 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
649 (defun electric-c-sharp-sign (arg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
650 "Insert character and correct line's indentation." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
651 (interactive "P") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
652 (if (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
653 (skip-chars-backward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
654 (bolp)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
655 (let ((c-auto-newline nil)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
656 (electric-c-terminator arg)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
657 (self-insert-command (prefix-numeric-value arg)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
658 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
659 (defun electric-c-semi (arg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
660 "Insert character and correct line's indentation." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
661 (interactive "P") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
662 (if c-auto-newline |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
663 (electric-c-terminator arg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
664 (self-insert-command (prefix-numeric-value arg)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
665 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
666 (defun electric-c-terminator (arg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
667 "Insert character and correct line's indentation." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
668 (interactive "P") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
669 (let (insertpos (end (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
670 (if (and (not arg) (eolp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
671 (not (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
672 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
673 (skip-chars-forward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
674 (or (= (following-char) ?#) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
675 ;; Colon is special only after a label, or case .... |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
676 ;; So quickly rule out most other uses of colon |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
677 ;; and do no indentation for them. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
678 (and (eq last-command-char ?:) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
679 (not (looking-at c-switch-label-regexp)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
680 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
681 (skip-chars-forward "a-zA-Z0-9_$") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
682 (skip-chars-forward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
683 (< (point) end))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
684 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
685 (beginning-of-defun) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
686 (let ((pps (parse-partial-sexp (point) end))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
687 (or (nth 3 pps) (nth 4 pps) (nth 5 pps)))))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
688 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
689 (insert last-command-char) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
690 (c-indent-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
691 (and c-auto-newline |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
692 (not (c-inside-parens-p)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
693 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
694 (newline) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
695 ;; (newline) may have done auto-fill |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
696 (setq insertpos (- (point) 2)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
697 (c-indent-line))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
698 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
699 (if insertpos (goto-char (1+ insertpos))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
700 (delete-char -1)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
701 (if insertpos |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
702 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
703 (goto-char insertpos) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
704 (self-insert-command (prefix-numeric-value arg))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
705 (self-insert-command (prefix-numeric-value arg))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
706 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
707 (defun c-inside-parens-p () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
708 (condition-case () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
709 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
710 (save-restriction |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
711 (narrow-to-region (point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
712 (progn (beginning-of-defun) (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
713 (goto-char (point-max)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
714 (= (char-after (or (scan-lists (point) -1 1) (point-min))) ?\())) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
715 (error nil))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
716 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
717 (defun c-indent-command (&optional whole-exp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
718 "Indent current line as C code, or in some cases insert a tab character. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
719 If `c-tab-always-indent' is non-nil (the default), always indent current line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
720 Otherwise, indent the current line only if point is at the left margin or |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
721 in the line's indentation; otherwise insert a tab. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
722 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
723 A numeric argument, regardless of its value, means indent rigidly all the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
724 lines of the expression starting after point so that this line becomes |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
725 properly indented. The relative indentation among the lines of the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
726 expression are preserved." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
727 (interactive "P") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
728 (if whole-exp |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
729 ;; If arg, always indent this line as C |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
730 ;; and shift remaining lines of expression the same amount. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
731 (let ((shift-amt (c-indent-line)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
732 beg end) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
733 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
734 (if c-tab-always-indent |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
735 (beginning-of-line)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
736 ;; Find beginning of following line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
737 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
738 (forward-line 1) (setq beg (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
739 ;; Find first beginning-of-sexp for sexp extending past this line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
740 (while (< (point) beg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
741 (forward-sexp 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
742 (setq end (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
743 (skip-chars-forward " \t\n"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
744 (if (> end beg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
745 (indent-code-rigidly beg end shift-amt "#"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
746 (if (and (not c-tab-always-indent) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
747 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
748 (skip-chars-backward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
749 (not (bolp)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
750 (insert-tab) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
751 (c-indent-line)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
752 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
753 (defun c-indent-line () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
754 "Indent current line as C code. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
755 Return the amount the indentation changed by." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
756 (let ((indent (calculate-c-indent nil)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
757 beg shift-amt |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
758 (case-fold-search nil) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
759 (pos (- (point-max) (point)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
760 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
761 (setq beg (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
762 (cond ((eq indent nil) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
763 (setq indent (current-indentation))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
764 ((eq indent t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
765 (setq indent (calculate-c-indent-within-comment))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
766 ((looking-at "[ \t]*#") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
767 (setq indent 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
768 (t |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
769 (skip-chars-forward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
770 (if (listp indent) (setq indent (car indent))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
771 (cond ((or (looking-at c-switch-label-regexp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
772 (and (looking-at "[A-Za-z]") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
773 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
774 (forward-sexp 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
775 (looking-at ":")))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
776 (setq indent (max 1 (+ indent c-label-offset)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
777 ((and (looking-at "else\\b") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
778 (not (looking-at "else\\s_"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
779 (setq indent (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
780 (c-backward-to-start-of-if) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
781 (current-indentation)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
782 ((and (looking-at "}[ \t]*else\\b") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
783 (not (looking-at "}[ \t]*else\\s_"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
784 (setq indent (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
785 (forward-char) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
786 (backward-sexp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
787 (c-backward-to-start-of-if) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
788 (current-indentation)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
789 ((and (looking-at "while\\b") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
790 (not (looking-at "while\\s_")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
791 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
792 (c-backward-to-start-of-do))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
793 ;; This is a `while' that ends a do-while. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
794 (setq indent (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
795 (c-backward-to-start-of-do) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
796 (current-indentation)))) |
41609 | 797 ((= (following-char) ?\}) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
798 (setq indent (- indent c-indent-level))) |
41609 | 799 ((= (following-char) ?\{) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
800 (setq indent (+ indent c-brace-offset)))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
801 (skip-chars-forward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
802 (setq shift-amt (- indent (current-column))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
803 (if (zerop shift-amt) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
804 (if (> (- (point-max) pos) (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
805 (goto-char (- (point-max) pos))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
806 (delete-region beg (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
807 (indent-to indent) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
808 ;; If initial point was within line's indentation, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
809 ;; position after the indentation. Else stay at same point in text. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
810 (if (> (- (point-max) pos) (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
811 (goto-char (- (point-max) pos)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
812 shift-amt)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
813 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
814 (defun calculate-c-indent (&optional parse-start) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
815 "Return appropriate indentation for current line as C code. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
816 In usual case returns an integer: the column to indent to. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
817 Returns nil if line starts inside a string, t if in a comment." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
818 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
819 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
820 (let ((indent-point (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
821 (case-fold-search nil) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
822 state |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
823 containing-sexp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
824 (if parse-start |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
825 (goto-char parse-start) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
826 (beginning-of-defun)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
827 (while (< (point) indent-point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
828 (setq parse-start (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
829 (setq state (parse-partial-sexp (point) indent-point 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
830 (setq containing-sexp (car (cdr state)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
831 (cond ((or (nth 3 state) (nth 4 state)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
832 ;; return nil or t if should not change this line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
833 (nth 4 state)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
834 ((null containing-sexp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
835 ;; Line is at top level. May be data or function definition, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
836 ;; or may be function argument declaration. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
837 ;; Indent like the previous top level line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
838 ;; unless that ends in a closeparen without semicolon, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
839 ;; in which case this line is the first argument decl. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
840 (goto-char indent-point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
841 (skip-chars-forward " \t") |
41609 | 842 (if (= (following-char) ?\{) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
843 0 ; Unless it starts a function body |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
844 (c-backward-to-noncomment (or parse-start (point-min))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
845 ;; Look at previous line that's at column 0 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
846 ;; to determine whether we are in top-level decls |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
847 ;; or function's arg decls. Set basic-indent accordingly. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
848 (let ((basic-indent |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
849 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
850 (re-search-backward "^[^ \^L\t\n#]" nil 'move) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
851 (let (comment lim) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
852 ;; Recognize the DEFUN macro in Emacs. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
853 (if (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
854 ;; Move down to the (putative) argnames line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
855 (while (and (not (eobp)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
856 (not (looking-at " *[({}#/]"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
857 (forward-line 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
858 ;; Go back to the DEFUN, if it is one. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
859 (condition-case nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
860 (backward-sexp 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
861 (error)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
862 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
863 (looking-at "DEFUN\\b")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
864 c-argdecl-indent |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
865 (if (and (looking-at "\\sw\\|\\s_") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
866 ;; This is careful to stop at the first |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
867 ;; paren if we have |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
868 ;; int foo Proto ((int, int)); |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
869 (looking-at "[^\"\n=(]*(") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
870 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
871 (goto-char (1- (match-end 0))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
872 ;; Skip any number of paren-groups. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
873 ;; Consider typedef int (*fcn) (int); |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
874 (while (= (following-char) ?\() |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
875 (setq lim (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
876 (condition-case nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
877 (forward-sexp 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
878 (error)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
879 (skip-chars-forward " \t\f")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
880 ;; Have we reached something |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
881 ;; that shows this isn't a function |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
882 ;; definition? |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
883 (and (< (point) indent-point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
884 (not (memq (following-char) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
885 '(?\, ?\;))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
886 ;; Make sure the "function decl" we found |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
887 ;; is not inside a comment. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
888 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
889 ;; Move back to the `(' starting arglist |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
890 (goto-char lim) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
891 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
892 (while (and (not comment) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
893 (search-forward "/*" lim t)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
894 (setq comment |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
895 (not (search-forward "*/" lim t)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
896 (not comment))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
897 c-argdecl-indent 0)))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
898 basic-indent))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
899 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
900 ;; ;; Now add a little if this is a continuation line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
901 ;; (+ basic-indent (if (or (bobp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
902 ;; (memq (preceding-char) '(?\) ?\; ?\})) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
903 ;; ;; Line with zero indentation |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
904 ;; ;; is probably the return-type |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
905 ;; ;; of a function definition, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
906 ;; ;; so following line is function name. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
907 ;; (= (current-indentation) 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
908 ;; 0 c-continued-statement-offset)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
909 |
41609 | 910 ((/= (char-after containing-sexp) ?\{) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
911 ;; line is expression, not statement: |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
912 ;; indent to just after the surrounding open. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
913 (goto-char (1+ containing-sexp)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
914 (current-column)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
915 (t |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
916 ;; Statement level. Is it a continuation or a new statement? |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
917 ;; Find previous non-comment character. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
918 (goto-char indent-point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
919 (c-backward-to-noncomment containing-sexp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
920 ;; Back up over label lines, since they don't |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
921 ;; affect whether our line is a continuation. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
922 (while (or (eq (preceding-char) ?\,) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
923 (and (eq (preceding-char) ?:) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
924 (or (eq (char-after (- (point) 2)) ?\') |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
925 (memq (char-syntax (char-after (- (point) 2))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
926 '(?w ?_))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
927 (if (eq (preceding-char) ?\,) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
928 (progn (forward-char -1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
929 (c-backward-to-start-of-continued-exp containing-sexp))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
930 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
931 (c-backward-to-noncomment containing-sexp)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
932 ;; Check for a preprocessor statement or its continuation lines. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
933 ;; Move back to end of previous non-preprocessor line, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
934 ;; or possibly beginning of buffer. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
935 (let ((found (point)) stop) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
936 (while (not stop) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
937 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
938 (cond ((bobp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
939 (setq found (point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
940 stop t)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
941 ((save-excursion (forward-char -1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
942 (= (preceding-char) ?\\)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
943 (forward-char -1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
944 ;; This line is not preceded by a backslash. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
945 ;; So either it starts a preprocessor command |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
946 ;; or any following continuation lines |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
947 ;; should not be skipped. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
948 ((= (following-char) ?#) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
949 (forward-char -1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
950 (setq found (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
951 (t (setq stop t)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
952 (goto-char found)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
953 ;; Now we get the answer. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
954 (if (and (not (memq (preceding-char) '(0 ?\, ?\; ?\} ?\{))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
955 ;; But don't treat a line with a close-brace |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
956 ;; as a continuation. It is probably the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
957 ;; end of an enum type declaration. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
958 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
959 (goto-char indent-point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
960 (skip-chars-forward " \t") |
41609 | 961 (not (= (following-char) ?\})))) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
962 ;; This line is continuation of preceding line's statement; |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
963 ;; indent c-continued-statement-offset more than the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
964 ;; previous line of the statement. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
965 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
966 (c-backward-to-start-of-continued-exp containing-sexp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
967 (+ c-continued-statement-offset (current-column) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
968 (if (save-excursion (goto-char indent-point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
969 (skip-chars-forward " \t") |
41609 | 970 (eq (following-char) ?\{)) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
971 c-continued-brace-offset 0))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
972 ;; This line starts a new statement. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
973 ;; Position following last unclosed open. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
974 (goto-char containing-sexp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
975 ;; Is line first statement after an open-brace? |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
976 (or |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
977 ;; If no, find that first statement and indent like it. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
978 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
979 (forward-char 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
980 (let ((colon-line-end 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
981 (while (progn (skip-chars-forward " \t\n") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
982 (looking-at "#\\|/\\*\\|case[ \t\n'/(].*:\\|[a-zA-Z0-9_$]*:")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
983 ;; Skip over comments and labels following openbrace. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
984 (cond ((= (following-char) ?\#) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
985 (forward-line 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
986 ((= (following-char) ?\/) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
987 (forward-char 2) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
988 (search-forward "*/" nil 'move)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
989 ;; case or label: |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
990 (t |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
991 (save-excursion (end-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
992 (setq colon-line-end (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
993 (search-forward ":")))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
994 ;; The first following code counts |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
995 ;; if it is before the line we want to indent. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
996 (and (< (point) indent-point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
997 (- |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
998 (if (> colon-line-end (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
999 (- (current-indentation) c-label-offset) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1000 (current-column)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1001 ;; If prev stmt starts with open-brace, that |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1002 ;; open brace was offset by c-brace-offset. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1003 ;; Compensate to get the column where |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1004 ;; an ordinary statement would start. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1005 (if (= (following-char) ?\{) c-brace-offset 0))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1006 ;; If no previous statement, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1007 ;; indent it relative to line brace is on. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1008 (calculate-c-indent-after-brace)))))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1009 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1010 (defun calculate-c-indent-after-brace () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1011 "Return the proper C indent for the first line after an open-brace. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1012 This function is called with point before the brace." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1013 ;; For open brace in column zero, don't let statement |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1014 ;; start there too. If c-indent-level is zero, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1015 ;; use c-brace-offset + c-continued-statement-offset instead. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1016 ;; For open-braces not the first thing in a line, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1017 ;; add in c-brace-imaginary-offset. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1018 (+ (if (and (bolp) (zerop c-indent-level)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1019 (+ c-brace-offset c-continued-statement-offset) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1020 c-indent-level) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1021 ;; Move back over whitespace before the openbrace. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1022 ;; If openbrace is not first nonwhite thing on the line, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1023 ;; add the c-brace-imaginary-offset. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1024 (progn (skip-chars-backward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1025 (if (bolp) 0 c-brace-imaginary-offset)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1026 ;; If the openbrace is preceded by a parenthesized exp, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1027 ;; move to the beginning of that; |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1028 ;; possibly a different line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1029 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1030 (if (eq (preceding-char) ?\)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1031 (forward-sexp -1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1032 ;; Get initial indentation of the line we are on. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1033 (current-indentation)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1034 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1035 (defun calculate-c-indent-within-comment (&optional after-star) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1036 "Return the indentation amount for line inside a block comment. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1037 Optional arg AFTER-STAR means, if lines in the comment have a leading star, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1038 return the indentation of the text that would follow this star." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1039 (let (end star-start) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1040 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1041 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1042 (skip-chars-forward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1043 (setq star-start (= (following-char) ?\*)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1044 (skip-chars-backward " \t\n") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1045 (setq end (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1046 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1047 (skip-chars-forward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1048 (if after-star |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1049 (and (looking-at "\\*") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1050 (re-search-forward "\\*[ \t]*"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1051 (and (re-search-forward "/\\*[ \t]*" end t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1052 star-start |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1053 (not after-star) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1054 (goto-char (1+ (match-beginning 0)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1055 (if (and (looking-at "[ \t]*$") (= (preceding-char) ?\*)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1056 (1+ (current-column)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1057 (current-column))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1058 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1059 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1060 (defun c-backward-to-noncomment (lim) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1061 (let (opoint stop) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1062 (while (not stop) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1063 (skip-chars-backward " \t\n\f" lim) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1064 (setq opoint (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1065 (if (and (>= (point) (+ 2 lim)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1066 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1067 (forward-char -2) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1068 (looking-at "\\*/"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1069 (search-backward "/*" lim 'move) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1070 (setq stop (or (<= (point) lim) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1071 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1072 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1073 (skip-chars-forward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1074 (not (looking-at "#"))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1075 (or stop (beginning-of-line)))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1076 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1077 (defun c-backward-to-start-of-continued-exp (lim) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1078 (if (memq (preceding-char) '(?\) ?\")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1079 (forward-sexp -1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1080 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1081 (if (<= (point) lim) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1082 (goto-char (1+ lim))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1083 (skip-chars-forward " \t")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1084 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1085 (defun c-backward-to-start-of-if (&optional limit) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1086 "Move to the start of the last \"unbalanced\" `if'." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1087 (or limit (setq limit (save-excursion (beginning-of-defun) (point)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1088 (let ((if-level 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1089 (case-fold-search nil)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1090 (while (and (not (bobp)) (not (zerop if-level))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1091 (backward-sexp 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1092 (cond ((and (looking-at "else\\b") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1093 (not (looking-at "else\\s_"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1094 (setq if-level (1+ if-level))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1095 ((and (looking-at "if\\b") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1096 (not (looking-at "if\\s_"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1097 (setq if-level (1- if-level))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1098 ((< (point) limit) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1099 (setq if-level 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1100 (goto-char limit)))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1101 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1102 (defun c-backward-to-start-of-do (&optional limit) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1103 "If point follows a `do' statement, move to beginning of it and return t. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1104 Otherwise return nil and don't move point." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1105 (or limit (setq limit (save-excursion (beginning-of-defun) (point)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1106 (let ((first t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1107 (startpos (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1108 (done nil)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1109 (while (not done) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1110 (let ((next-start (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1111 (condition-case nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1112 ;; Move back one token or one brace or paren group. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1113 (backward-sexp 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1114 ;; If we find an open-brace, we lose. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1115 (error (setq done 'fail))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1116 (if done |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1117 nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1118 ;; If we reached a `do', we win. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1119 (if (looking-at "do\\b") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1120 (setq done 'succeed) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1121 ;; Otherwise, if we skipped a semicolon, we lose. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1122 ;; (Exception: we can skip one semicolon before getting |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1123 ;; to a the last token of the statement, unless that token |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1124 ;; is a close brace.) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1125 (if (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1126 (forward-sexp 1) |
41609 | 1127 (or (and (not first) (= (preceding-char) ?\})) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1128 (search-forward ";" next-start t |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1129 (if (and first |
41609 | 1130 (/= (preceding-char) ?\})) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1131 2 1)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1132 (setq done 'fail) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1133 (setq first nil) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1134 ;; If we go too far back in the buffer, we lose. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1135 (if (< (point) limit) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1136 (setq done 'fail))))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1137 (if (eq done 'succeed) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1138 t |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1139 (goto-char startpos) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1140 nil))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1141 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1142 (defun c-beginning-of-statement (count) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1143 "Go to the beginning of the innermost C statement. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1144 With prefix arg, go back N - 1 statements. If already at the beginning of a |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1145 statement then go to the beginning of the preceding one. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1146 If within a string or comment, or next to a comment (only whitespace between), |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1147 move by sentences instead of statements." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1148 (interactive "p") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1149 (let ((here (point)) state) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1150 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1151 (beginning-of-defun) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1152 (setq state (parse-partial-sexp (point) here nil nil))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1153 (if (or (nth 3 state) (nth 4 state) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1154 (looking-at (concat "[ \t]*" comment-start-skip)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1155 (save-excursion (skip-chars-backward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1156 (goto-char (- (point) 2)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1157 (looking-at "\\*/"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1158 (forward-sentence (- count)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1159 (while (> count 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1160 (c-beginning-of-statement-1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1161 (setq count (1- count))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1162 (while (< count 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1163 (c-end-of-statement-1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1164 (setq count (1+ count)))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1165 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1166 (defun c-end-of-statement (count) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1167 "Go to the end of the innermost C statement. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1168 With prefix arg, go forward N - 1 statements. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1169 Move forward to end of the next statement if already at end. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1170 If within a string or comment, move by sentences instead of statements." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1171 (interactive "p") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1172 (c-beginning-of-statement (- count))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1173 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1174 (defun c-beginning-of-statement-1 () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1175 (let ((last-begin (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1176 (first t)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1177 (condition-case () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1178 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1179 (while (and (not (bobp)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1180 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1181 (backward-sexp 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1182 (or first |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1183 (not (re-search-forward "[;{}]" last-begin t))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1184 (setq last-begin (point) first nil)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1185 (goto-char last-begin)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1186 (error (if first (backward-up-list 1) (goto-char last-begin)))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1187 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1188 (defun c-end-of-statement-1 () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1189 (condition-case () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1190 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1191 (while (and (not (eobp)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1192 (let ((beg (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1193 (forward-sexp 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1194 (let ((end (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1195 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1196 (goto-char beg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1197 (not (re-search-forward "[;{}]" end t))))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1198 (re-search-backward "[;}]") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1199 (forward-char 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1200 (error |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1201 (let ((beg (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1202 (backward-up-list -1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1203 (let ((end (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1204 (goto-char beg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1205 (search-forward ";" end 'move)))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1206 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1207 (defun mark-c-function () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1208 "Put mark at end of C function, point at beginning." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1209 (interactive) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1210 (push-mark (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1211 (end-of-defun) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1212 (push-mark (point) nil t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1213 (beginning-of-defun) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1214 (backward-paragraph)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1215 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1216 ;; Idea of ENDPOS is, indent each line, stopping when |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1217 ;; ENDPOS is encountered. But it's too much of a pain to make that work. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1218 (defun indent-c-exp (&optional endpos) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1219 "Indent each line of the C grouping following point." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1220 (interactive) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1221 (let* ((indent-stack (list nil)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1222 (opoint (point)) ;; May be altered below. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1223 (contain-stack |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1224 (list (if endpos |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1225 (let (funbeg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1226 ;; Find previous fcn-start. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1227 (save-excursion (forward-char 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1228 (beginning-of-defun) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1229 (setq funbeg (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1230 (setq opoint funbeg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1231 ;; Try to find containing open, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1232 ;; but don't scan past that fcn-start. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1233 (save-restriction |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1234 (narrow-to-region funbeg (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1235 (condition-case nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1236 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1237 (backward-up-list 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1238 (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1239 ;; We gave up: must be between fcns. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1240 ;; Set opoint to beg of prev fcn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1241 ;; since otherwise calculate-c-indent |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1242 ;; will get wrong answers. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1243 (error (setq opoint funbeg) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1244 (point))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1245 (point)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1246 (case-fold-search nil) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1247 restart outer-loop-done inner-loop-done state ostate |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1248 this-indent last-sexp |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1249 at-else at-brace at-while |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1250 last-depth this-point |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1251 (next-depth 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1252 ;; If the braces don't match, get an error right away. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1253 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1254 (forward-sexp 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1255 ;; Realign the comment on the first line, even though we don't reindent it. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1256 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1257 (let ((beg (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1258 (and (re-search-forward |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1259 comment-start-skip |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1260 (save-excursion (end-of-line) (point)) t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1261 ;; Make sure this isn't a comment alone on a line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1262 ;; (which should be indented like code instead). |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1263 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1264 (goto-char (match-beginning 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1265 (skip-chars-backward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1266 (not (bolp))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1267 ;; Make sure the comment starter we found |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1268 ;; is not actually in a string or quoted. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1269 (let ((new-state |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1270 (parse-partial-sexp beg (point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1271 nil nil state))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1272 (and (not (nth 3 new-state)) (not (nth 5 new-state)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1273 (progn (indent-for-comment) (beginning-of-line))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1274 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1275 (setq outer-loop-done nil) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1276 (while (and (not (eobp)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1277 (if endpos (< (point) endpos) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1278 (not outer-loop-done))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1279 (setq last-depth next-depth) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1280 ;; Compute how depth changes over this line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1281 ;; plus enough other lines to get to one that |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1282 ;; does not end inside a comment or string. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1283 ;; Meanwhile, do appropriate indentation on comment lines. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1284 (setq inner-loop-done nil) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1285 (while (and (not inner-loop-done) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1286 (not (and (eobp) (setq outer-loop-done t)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1287 (setq ostate state) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1288 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1289 nil nil state)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1290 (setq next-depth (car state)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1291 (if (and (car (cdr (cdr state))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1292 (>= (car (cdr (cdr state))) 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1293 (setq last-sexp (car (cdr (cdr state))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1294 ;; If this line started within a comment, indent it as such. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1295 (if (or (nth 4 ostate) (nth 7 ostate)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1296 (c-indent-line)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1297 ;; If it ends outside of comments or strings, exit the inner loop. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1298 ;; Otherwise move on to next line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1299 (if (or (nth 3 state) (nth 4 state) (nth 7 state)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1300 (forward-line 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1301 (setq inner-loop-done t))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1302 (and endpos |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1303 (while (< next-depth 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1304 (setq indent-stack (append indent-stack (list nil))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1305 (setq contain-stack (append contain-stack (list nil))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1306 (setq next-depth (1+ next-depth)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1307 (setq last-depth (1+ last-depth)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1308 (setcar (nthcdr 6 state) (1+ (nth 6 state))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1309 (setq outer-loop-done (and (not endpos) (<= next-depth 0))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1310 (if outer-loop-done |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1311 nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1312 ;; If this line had ..))) (((.. in it, pop out of the levels |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1313 ;; that ended anywhere in this line, even if the final depth |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1314 ;; doesn't indicate that they ended. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1315 (while (> last-depth (nth 6 state)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1316 (setq indent-stack (cdr indent-stack) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1317 contain-stack (cdr contain-stack) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1318 last-depth (1- last-depth))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1319 (if (/= last-depth next-depth) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1320 (setq last-sexp nil)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1321 ;; Add levels for any parens that were started in this line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1322 (while (< last-depth next-depth) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1323 (setq indent-stack (cons nil indent-stack) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1324 contain-stack (cons nil contain-stack) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1325 last-depth (1+ last-depth))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1326 (if (null (car contain-stack)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1327 (setcar contain-stack (or (car (cdr state)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1328 (save-excursion (forward-sexp -1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1329 (point))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1330 (forward-line 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1331 (skip-chars-forward " \t") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1332 ;; Don't really reindent if the line is just whitespace, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1333 ;; or if it is past the endpos. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1334 ;; (The exit test in the outer while |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1335 ;; does not exit until we have passed the first line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1336 ;; past the region.) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1337 (if (or (eolp) (and endpos (>= (point) endpos))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1338 nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1339 ;; Is this line in a new nesting level? |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1340 ;; In other words, is this the first line that |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1341 ;; starts in the new level? |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1342 (if (and (car indent-stack) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1343 (>= (car indent-stack) 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1344 nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1345 ;; Yes. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1346 ;; Compute the standard indent for this level. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1347 (let (val) |
41609 | 1348 (if (= (char-after (car contain-stack)) ?\{) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1349 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1350 (goto-char (car contain-stack)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1351 (setq val (calculate-c-indent-after-brace))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1352 (setq val (calculate-c-indent |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1353 (if (car indent-stack) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1354 (- (car indent-stack)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1355 opoint)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1356 ;; t means we are in a block comment and should |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1357 ;; calculate accordingly. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1358 (if (eq val t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1359 (setq val (calculate-c-indent-within-comment))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1360 (setcar indent-stack val))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1361 ;; Adjust indent of this individual line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1362 ;; based on its predecessor. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1363 ;; Handle continuation lines, if, else, while, and so on. |
41609 | 1364 (if (/= (char-after (car contain-stack)) ?\{) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1365 (setq this-indent (car indent-stack)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1366 ;; Line is at statement level. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1367 ;; Is it a new statement? Is it an else? |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1368 ;; Find last non-comment character before this line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1369 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1370 (setq this-point (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1371 (setq at-else (and (looking-at "else\\b") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1372 (not (looking-at "else\\s_")))) |
41609 | 1373 (setq at-brace (= (following-char) ?\{)) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1374 (setq at-while (and (looking-at "while\\b") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1375 (not (looking-at "while\\s_")))) |
41609 | 1376 (if (= (following-char) ?\}) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1377 (setq this-indent (car indent-stack)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1378 (c-backward-to-noncomment opoint) |
41609 | 1379 (if (not (memq (preceding-char) '(0 ?\, ?\; ?\} ?: ?\{))) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1380 ;; Preceding line did not end in comma or semi; |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1381 ;; indent this line c-continued-statement-offset |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1382 ;; more than previous. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1383 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1384 (c-backward-to-start-of-continued-exp (car contain-stack)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1385 (setq this-indent |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1386 (+ c-continued-statement-offset (current-column) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1387 (if at-brace c-continued-brace-offset 0)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1388 ;; Preceding line ended in comma or semi; |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1389 ;; use the standard indent for this level. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1390 (cond (at-else (progn (c-backward-to-start-of-if opoint) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1391 (setq this-indent |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1392 (current-indentation)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1393 ((and at-while (c-backward-to-start-of-do opoint)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1394 (setq this-indent (current-indentation))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1395 ((eq (preceding-char) ?\,) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1396 (goto-char this-point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1397 (setq this-indent (calculate-c-indent))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1398 (t (setq this-indent (car indent-stack)))))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1399 ;; Adjust line indentation according to its contents |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1400 (if (or (looking-at c-switch-label-regexp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1401 (and (looking-at "[A-Za-z]") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1402 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1403 (forward-sexp 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1404 (looking-at ":")))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1405 (setq this-indent (max 1 (+ this-indent c-label-offset)))) |
41609 | 1406 (if (= (following-char) ?\}) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1407 (setq this-indent (- this-indent c-indent-level))) |
41609 | 1408 (if (= (following-char) ?\{) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1409 ;; Don't move an open-brace in column 0. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1410 ;; This is good when constructs such as |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1411 ;; `extern "C" {' surround a function definition |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1412 ;; that should be indented as usual. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1413 ;; It is also good for nested functions. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1414 ;; It is bad when an open-brace is indented at column 0 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1415 ;; and you want to fix that, but we can't win 'em all. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1416 (if (zerop (current-column)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1417 (setq this-indent 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1418 (setq this-indent (+ this-indent c-brace-offset)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1419 ;; Don't leave indentation in empty lines. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1420 (if (eolp) (setq this-indent 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1421 ;; Put chosen indentation into effect. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1422 (or (= (current-column) this-indent) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1423 (= (following-char) ?\#) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1424 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1425 (delete-region (point) (progn (beginning-of-line) (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1426 (indent-to this-indent))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1427 ;; Indent any comment following the text. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1428 (or (looking-at comment-start-skip) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1429 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1430 (let ((beg (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1431 (and (re-search-forward |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1432 comment-start-skip |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1433 (save-excursion (end-of-line) (point)) t) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1434 ;; Make sure the comment starter we found |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1435 ;; is not actually in a string or quoted. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1436 (let ((new-state |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1437 (parse-partial-sexp beg (point) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1438 nil nil state))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1439 (and (not (nth 3 new-state)) (not (nth 5 new-state)))) |
41609 | 1440 (indent-for-comment))))))))))) |
34454
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1441 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1442 ;; Look at all comment-start strings in the current line after point. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1443 ;; Return t if one of them starts a real comment. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1444 ;; This is not used yet, because indent-for-comment |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1445 ;; isn't smart enough to handle the cases this can find. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1446 (defun indent-c-find-real-comment () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1447 (let (win) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1448 (while (and (not win) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1449 (re-search-forward comment-start-skip |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1450 (save-excursion (end-of-line) (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1451 t)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1452 ;; Make sure the comment start is not quoted. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1453 (let ((state-1 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1454 (parse-partial-sexp |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1455 (save-excursion (beginning-of-line) (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1456 (point) nil nil state))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1457 (setq win (and (null (nth 3 state-1)) (null (nth 5 state-1)))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1458 win)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1459 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1460 ;; Indent every line whose first char is between START and END inclusive. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1461 (defun c-indent-region (start end) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1462 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1463 (goto-char start) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1464 ;; Advance to first nonblank line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1465 (skip-chars-forward " \t\n") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1466 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1467 (let ((endmark (copy-marker end)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1468 (c-tab-always-indent t)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1469 (while (and (bolp) (not (eobp)) (< (point) endmark)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1470 ;; Indent one line as with TAB. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1471 (let ((shift-amt (c-indent-line)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1472 nextline sexpbeg sexpend) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1473 (if (save-excursion (beginning-of-line) (looking-at "[ \t]*#")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1474 (forward-line 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1475 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1476 ;; Find beginning of following line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1477 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1478 (forward-line 1) (setq nextline (point))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1479 ;; Find first beginning-of-sexp for sexp extending past this line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1480 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1481 (while (< (point) nextline) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1482 (condition-case nil |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1483 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1484 (forward-sexp 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1485 (setq sexpend (point-marker))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1486 (error (setq sexpend nil) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1487 (goto-char nextline))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1488 (skip-chars-forward " \t\n")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1489 (if sexpend |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1490 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1491 ;; Make sure the sexp we found really starts on the |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1492 ;; current line and extends past it. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1493 (goto-char sexpend) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1494 (backward-sexp 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1495 (setq sexpbeg (point))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1496 ;; If that sexp ends within the region, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1497 ;; indent it all at once, fast. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1498 (if (and sexpend (> sexpend nextline) (<= sexpend endmark) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1499 (< sexpbeg nextline)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1500 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1501 (indent-c-exp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1502 (goto-char sexpend))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1503 ;; Move to following line and try again. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1504 (and sexpend (set-marker sexpend nil)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1505 (forward-line 1)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1506 (set-marker endmark nil)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1507 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1508 (defun set-c-style (style &optional global) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1509 "Set C-mode variables to use one of several different indentation styles. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1510 The arguments are a string representing the desired style |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1511 and a flag which, if non-nil, means to set the style globally. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1512 \(Interactively, the flag comes from the prefix argument.) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1513 Available styles are GNU, K&R, BSD and Whitesmith." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1514 (interactive (list (let ((completion-ignore-case t)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1515 (completing-read "Use which C indentation style? " |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1516 c-style-alist nil t)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1517 current-prefix-arg)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1518 (let ((vars (cdr (assoc style c-style-alist)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1519 (or vars |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1520 (error "Invalid C indentation style `%s'" style)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1521 (while vars |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1522 (or global |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1523 (make-local-variable (car (car vars)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1524 (set (car (car vars)) (cdr (car vars))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1525 (setq vars (cdr vars))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1526 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1527 ;;; This page handles insertion and removal of backslashes for C macros. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1528 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1529 (defcustom c-backslash-column 48 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1530 "*Minimum column for end-of-line backslashes of macro definitions." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1531 :type 'integer |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1532 :group 'old-c) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1533 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1534 (defun c-backslash-region (from to delete-flag) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1535 "Insert, align, or delete end-of-line backslashes on the lines in the region. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1536 With no argument, inserts backslashes and aligns existing backslashes. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1537 With an argument, deletes the backslashes. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1538 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1539 This function does not modify the last line of the region if the region ends |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1540 right at the start of the following line; it does not modify blank lines |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1541 at the start of the region. So you can put the region around an entire macro |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1542 definition and conveniently use this command." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1543 (interactive "r\nP") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1544 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1545 (goto-char from) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1546 (let ((column c-backslash-column) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1547 (endmark (make-marker))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1548 (move-marker endmark to) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1549 ;; Compute the smallest column number past the ends of all the lines. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1550 (if (not delete-flag) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1551 (while (< (point) to) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1552 (end-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1553 (if (= (preceding-char) ?\\) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1554 (progn (forward-char -1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1555 (skip-chars-backward " \t"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1556 (setq column (max column (1+ (current-column)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1557 (forward-line 1))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1558 ;; Adjust upward to a tab column, if that doesn't push past the margin. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1559 (if (> (% column tab-width) 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1560 (let ((adjusted (* (/ (+ column tab-width -1) tab-width) tab-width))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1561 (if (< adjusted (window-width)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1562 (setq column adjusted)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1563 ;; Don't modify blank lines at start of region. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1564 (goto-char from) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1565 (while (and (< (point) endmark) (eolp)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1566 (forward-line 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1567 ;; Add or remove backslashes on all the lines. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1568 (while (and (< (point) endmark) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1569 ;; Don't backslashify the last line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1570 ;; if the region ends right at the start of the next line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1571 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1572 (forward-line 1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1573 (< (point) endmark))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1574 (if (not delete-flag) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1575 (c-append-backslash column) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1576 (c-delete-backslash)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1577 (forward-line 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1578 (move-marker endmark nil)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1579 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1580 (defun c-append-backslash (column) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1581 (end-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1582 ;; Note that "\\\\" is needed to get one backslash. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1583 (if (= (preceding-char) ?\\) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1584 (progn (forward-char -1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1585 (delete-horizontal-space) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1586 (indent-to column)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1587 (indent-to column) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1588 (insert "\\"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1589 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1590 (defun c-delete-backslash () |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1591 (end-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1592 (or (bolp) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1593 (progn |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1594 (forward-char -1) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1595 (if (looking-at "\\\\") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1596 (delete-region (1+ (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1597 (progn (skip-chars-backward " \t") (point))))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1598 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1599 (defun c-up-conditional (count) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1600 "Move back to the containing preprocessor conditional, leaving mark behind. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1601 A prefix argument acts as a repeat count. With a negative argument, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1602 move forward to the end of the containing preprocessor conditional. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1603 When going backwards, `#elif' is treated like `#else' followed by `#if'. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1604 When going forwards, `#elif' is ignored." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1605 (interactive "p") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1606 (c-forward-conditional (- count) t)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1607 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1608 (defun c-backward-conditional (count &optional up-flag) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1609 "Move back across a preprocessor conditional, leaving mark behind. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1610 A prefix argument acts as a repeat count. With a negative argument, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1611 move forward across a preprocessor conditional." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1612 (interactive "p") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1613 (c-forward-conditional (- count) up-flag)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1614 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1615 (defun c-forward-conditional (count &optional up-flag) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1616 "Move forward across a preprocessor conditional, leaving mark behind. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1617 A prefix argument acts as a repeat count. With a negative argument, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1618 move backward across a preprocessor conditional." |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1619 (interactive "p") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1620 (let* ((forward (> count 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1621 (increment (if forward -1 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1622 (search-function (if forward 're-search-forward 're-search-backward)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1623 (opoint (point)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1624 (new)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1625 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1626 (while (/= count 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1627 (let ((depth (if up-flag 0 -1)) found) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1628 (save-excursion |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1629 ;; Find the "next" significant line in the proper direction. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1630 (while (and (not found) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1631 ;; Rather than searching for a # sign that comes |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1632 ;; at the beginning of a line aside from whitespace, |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1633 ;; search first for a string starting with # sign. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1634 ;; Then verify what precedes it. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1635 ;; This is faster on account of the fastmap feature of |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1636 ;; the regexp matcher. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1637 (funcall search-function |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1638 "#[ \t]*\\(if\\|elif\\|endif\\)" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1639 nil t)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1640 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1641 ;; Now verify it is really a preproc line. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1642 (if (looking-at "^[ \t]*#[ \t]*\\(if\\|elif\\|endif\\)") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1643 (let ((prev depth)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1644 ;; Update depth according to what we found. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1645 (beginning-of-line) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1646 (cond ((looking-at "[ \t]*#[ \t]*endif") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1647 (setq depth (+ depth increment))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1648 ((looking-at "[ \t]*#[ \t]*elif") |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1649 (if (and forward (= depth 0)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1650 (setq found (point)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1651 (t (setq depth (- depth increment)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1652 ;; If we are trying to move across, and we find |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1653 ;; an end before we find a beginning, get an error. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1654 (if (and (< prev 0) (< depth prev)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1655 (error (if forward |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1656 "No following conditional at this level" |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1657 "No previous conditional at this level"))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1658 ;; When searching forward, start from next line |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1659 ;; so that we don't find the same line again. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1660 (if forward (forward-line 1)) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1661 ;; If this line exits a level of conditional, exit inner loop. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1662 (if (< depth 0) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1663 (setq found (point)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1664 ;; If the line is not really a conditional, skip past it. |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1665 (if forward (end-of-line))))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1666 (or found |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1667 (error "No containing preprocessor conditional")) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1668 (goto-char (setq new found))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1669 (setq count (+ count increment)))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1670 (push-mark) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1671 (goto-char new))) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1672 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1673 (provide 'c-mode) |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1674 |
ed29ea01b35b
Moved from progmodes/c-mode.el to obsolete/c-mode.el
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
diff
changeset
|
1675 ;;; c-mode.el ends here |