annotate lisp/modes/icon.el @ 172:a38aed19690b

Added tag r20-3b12 for changeset 929b76928fce
author cvs
date Mon, 13 Aug 2007 09:47:55 +0200
parents 28f395d8dc7a
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; icon.el --- mode for editing Icon code
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1989 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Chris Smith <csmith@convex.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Created: 15 Feb 89
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: languages
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
9 ;; This file is part of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
12 ;; under the terms of the GNU General Public License as published by
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
19 ;; General Public License for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; You should have received a copy of the GNU General Public License
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the Free
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
24 ;; 02111-1307, USA.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
25
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
26 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; A major mode for editing the Icon programming language.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 (defvar icon-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 "Abbrev table in use in Icon-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 (define-abbrev-table 'icon-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (defvar icon-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 "Keymap used in Icon mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (if icon-mode-map
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (setq icon-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (define-key icon-mode-map "{" 'electric-icon-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (define-key icon-mode-map "}" 'electric-icon-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (define-key icon-mode-map "\e\C-h" 'mark-icon-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (define-key icon-mode-map "\e\C-a" 'beginning-of-icon-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (define-key icon-mode-map "\e\C-e" 'end-of-icon-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (define-key icon-mode-map "\e\C-q" 'indent-icon-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (define-key icon-mode-map "\t" 'icon-indent-command))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (defvar icon-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 "Syntax table in use in Icon-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (if icon-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (setq icon-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (modify-syntax-entry ?\\ "\\" icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 (modify-syntax-entry ?# "<" icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (modify-syntax-entry ?\n ">" icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (modify-syntax-entry ?$ "." icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 (modify-syntax-entry ?/ "." icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62 (modify-syntax-entry ?* "." icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (modify-syntax-entry ?+ "." icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64 (modify-syntax-entry ?- "." icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (modify-syntax-entry ?= "." icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (modify-syntax-entry ?% "." icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (modify-syntax-entry ?< "." icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 (modify-syntax-entry ?> "." icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 (modify-syntax-entry ?& "." icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 (modify-syntax-entry ?| "." icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 (modify-syntax-entry ?\' "\"" icon-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
73 (defgroup icon nil
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
74 "Mode for editing icon code."
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
75 :group 'languages)
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
76
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
77
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
78 (defcustom icon-indent-level 4
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
79 "*Indentation of Icon statements with respect to containing block."
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
80 :type 'integer
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
81 :group 'icon)
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
82 (defcustom icon-brace-imaginary-offset 0
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
83 "*Imagined indentation of a Icon open brace that actually follows a statement."
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
84 :type 'integer
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
85 :group 'icon)
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
86 (defcustom icon-brace-offset 0
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
87 "*Extra indentation for braces, compared with other text in same context."
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
88 :type 'integer
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
89 :group 'icon)
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
90 (defcustom icon-continued-statement-offset 4
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
91 "*Extra indent for lines not starting new statements."
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
92 :type 'integer
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
93 :group 'icon)
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
94 (defcustom icon-continued-brace-offset 0
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 "*Extra indent for substatements that start with open-braces.
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
96 This is in addition to icon-continued-statement-offset."
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
97 :type 'integer
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
98 :group 'icon)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
100 (defcustom icon-auto-newline nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 "*Non-nil means automatically newline before and after braces
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
102 inserted in Icon code."
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
103 :type 'boolean
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
104 :group 'icon)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
106 (defcustom icon-tab-always-indent t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 "*Non-nil means TAB in Icon mode should always reindent the current line,
142
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
108 regardless of where in the line point is when the TAB command is used."
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
109 :type 'integer
1856695b1fa9 Import from CVS: tag r20-2b5
cvs
parents: 2
diff changeset
110 :group 'icon)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defun icon-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 "Major mode for editing Icon code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 Expression and list commands understand all Icon brackets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 Tab indents for Icon code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 Paragraphs are separated by blank lines only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 Delete converts tabs to spaces as it moves back.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 \\{icon-mode-map}
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 Variables controlling indentation style:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 icon-tab-always-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 Non-nil means TAB in Icon mode should always reindent the current line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 regardless of where in the line point is when the TAB command is used.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 icon-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 Non-nil means automatically newline before and after braces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 inserted in Icon code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 icon-indent-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 Indentation of Icon statements within surrounding block.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 The surrounding block's indentation is the indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 of the line on which the open-brace appears.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 icon-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 Extra indentation given to a substatement, such as the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 then-clause of an if or body of a while.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 icon-continued-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 Extra indentation given to a brace that starts a substatement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 This is in addition to `icon-continued-statement-offset'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 icon-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 Extra indentation for line if it starts with an open brace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 icon-brace-imaginary-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 An open brace following other text is treated as if it were
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 this far to the right of the start of its line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 Turning on Icon mode calls the value of the variable `icon-mode-hook'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 with no args, if that value is non-nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (use-local-map icon-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (setq major-mode 'icon-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (setq mode-name "Icon")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (setq local-abbrev-table icon-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (set-syntax-table icon-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (make-local-variable 'paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 (setq paragraph-start (concat "$\\|" page-delimiter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (make-local-variable 'paragraph-separate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (setq paragraph-separate paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 (make-local-variable 'indent-line-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (setq indent-line-function 'icon-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (make-local-variable 'require-final-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (setq require-final-newline t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (make-local-variable 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (setq comment-start "# ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 (make-local-variable 'comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (setq comment-end "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (make-local-variable 'comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (setq comment-column 32)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (make-local-variable 'comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (setq comment-start-skip "# *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 (make-local-variable 'comment-indent-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (setq comment-indent-function 'icon-comment-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 (run-hooks 'icon-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;; This is used by indent-for-comment to decide how much to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ;; indent a comment in Icon code based on its context.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (defun icon-comment-indent ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (if (looking-at "^#")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (max (if (bolp) 0 (1+ (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 comment-column))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (defun electric-icon-brace (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 "Insert character and correct line's indentation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (let (insertpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (if (and (not arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (or (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (if icon-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 (progn (icon-indent-line) (newline) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 nil)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (insert last-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (icon-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 (if icon-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 ;; (newline) may have done auto-fill
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 (setq insertpos (- (point) 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (icon-indent-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 (if insertpos (goto-char (1+ insertpos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (delete-char -1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 (if insertpos
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 (goto-char insertpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (self-insert-command (prefix-numeric-value arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (self-insert-command (prefix-numeric-value arg)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (defun icon-indent-command (&optional whole-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 "Indent current line as Icon code, or in some cases insert a tab character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 If `icon-tab-always-indent' is non-nil (the default), always indent current
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 line. Otherwise, indent the current line only if point is at the left margin
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 or in the line's indentation; otherwise insert a tab.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 A numeric argument, regardless of its value, means indent rigidly all the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 lines of the expression starting after point so that this line becomes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 properly indented. The relative indentation among the lines of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 expression are preserved."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (if whole-exp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 ;; If arg, always indent this line as Icon
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 ;; and shift remaining lines of expression the same amount.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (let ((shift-amt (icon-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 beg end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (if icon-tab-always-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (beginning-of-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (forward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (setq end (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (goto-char beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (setq beg (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (if (> end beg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (indent-code-rigidly beg end shift-amt "#")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (if (and (not icon-tab-always-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (not (bolp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (insert-tab)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (icon-indent-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (defun icon-indent-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 "Indent current line as Icon code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 Return the amount the indentation changed by."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (let ((indent (calculate-icon-indent nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 beg shift-amt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (pos (- (point-max) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (cond ((eq indent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (setq indent (current-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 ((eq indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (setq indent (calculate-icon-indent-within-comment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 ((looking-at "[ \t]*#")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (setq indent 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (if (listp indent) (setq indent (car indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (cond ((and (looking-at "else\\b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (not (looking-at "else\\s_")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 (setq indent (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (icon-backward-to-start-of-if)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (current-indentation))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 ((or (= (following-char) ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (looking-at "end\\b"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (setq indent (- indent icon-indent-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 ((= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (setq indent (+ indent icon-brace-offset))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (setq shift-amt (- indent (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (if (zerop shift-amt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (if (> (- (point-max) pos) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (delete-region beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (indent-to indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 ;; If initial point was within line's indentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 ;; position after the indentation. Else stay at same point in text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (if (> (- (point-max) pos) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 (goto-char (- (point-max) pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 shift-amt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (defun calculate-icon-indent (&optional parse-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 "Return appropriate indentation for current line as Icon code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 In usual case returns an integer: the column to indent to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 Returns nil if line starts inside a string, t if in a comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (let ((indent-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 containing-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 toplevel)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (if parse-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (goto-char parse-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (setq toplevel (beginning-of-icon-defun)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 (while (< (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 (setq parse-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (setq state (parse-partial-sexp (point) indent-point 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (setq containing-sexp (car (cdr state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (cond ((or (nth 3 state) (nth 4 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 ;; return nil or t if should not change this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (nth 4 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 ((and containing-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (/= (char-after containing-sexp) ?{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 ;; line is expression, not statement:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 ;; indent to just after the surrounding open.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (goto-char (1+ containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 (if toplevel
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 ;; Outside any procedures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (progn (icon-backward-to-noncomment (point-min))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (if (icon-is-continuation-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 icon-continued-statement-offset 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 ;; Statement level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 (if (null containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (progn (beginning-of-icon-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 (setq containing-sexp (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 ;; Is it a continuation or a new statement?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 ;; Find previous non-comment character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (icon-backward-to-noncomment containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 ;; Now we get the answer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 (if (icon-is-continuation-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ;; This line is continuation of preceding line's statement;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 ;; indent icon-continued-statement-offset more than the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 ;; first line of the statement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 (icon-backward-to-start-of-continued-exp containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (+ icon-continued-statement-offset (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (if (save-excursion (goto-char indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 (eq (following-char) ?{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 icon-continued-brace-offset 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 ;; This line starts a new statement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ;; Position following last unclosed open.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 ;; Is line first statement after an open-brace?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ;; If no, find that first statement and indent like it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (if (looking-at "procedure\\s ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (forward-sexp 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (forward-char 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (while (progn (skip-chars-forward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 (looking-at "#"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ;; Skip over comments following openbrace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ;; The first following code counts
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 ;; if it is before the line we want to indent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (and (< (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ;; If no previous statement,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ;; indent it relative to line brace is on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ;; For open brace in column zero, don't let statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 ;; start there too. If icon-indent-level is zero,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 ;; use icon-brace-offset + icon-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 ;; instead.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 ;; For open-braces not the first thing in a line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ;; add in icon-brace-imaginary-offset.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (+ (if (and (bolp) (zerop icon-indent-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (+ icon-brace-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 icon-continued-statement-offset)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 icon-indent-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ;; Move back over whitespace before the openbrace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 ;; If openbrace is not first nonwhite thing on the line,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 ;; add the icon-brace-imaginary-offset.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (progn (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (if (bolp) 0 icon-brace-imaginary-offset))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 ;; Get initial indentation of the line we are on.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (current-indentation))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ;; List of words to check for as the last thing on a line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 ;; If cdr is t, next line is a continuation of the same statement,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 ;; if cdr is nil, next line starts a new (possibly indented) statement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (defconst icon-resword-alist
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 '(("by" . t) ("case" . t) ("create") ("do") ("dynamic" . t) ("else")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 ("every" . t) ("if" . t) ("global" . t) ("initial" . t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 ("link" . t) ("local" . t) ("of") ("record" . t) ("repeat" . t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 ("static" . t) ("then") ("to" . t) ("until" . t) ("while" . t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (defun icon-is-continuation-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (let* ((ch (preceding-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (ch-syntax (char-syntax ch)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (if (eq ch-syntax ?w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (assoc (buffer-substring
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (progn (forward-word -1) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (progn (forward-word 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 icon-resword-alist)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (not (memq ch '(0 ?\; ?\} ?\{ ?\) ?\] ?\" ?\' ?\n))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 (defun icon-backward-to-noncomment (lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (let (opoint stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (while (not stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (skip-chars-backward " \t\n\f" lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (setq opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (if (and (nth 5 (parse-partial-sexp (point) opoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (< lim (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (search-backward "#")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (setq stop t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (defun icon-backward-to-start-of-continued-exp (lim)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (if (memq (preceding-char) '(?\) ?\]))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 (forward-sexp -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 ((<= (point) lim) (goto-char (1+ lim)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 ((not (icon-is-continued-line)) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 ((and (eq (char-syntax (following-char)) ?w)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (cdr
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (assoc (buffer-substring (point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (save-excursion (forward-word 1) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 icon-resword-alist))) 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (t (end-of-line 0) (icon-backward-to-start-of-continued-exp lim))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (defun icon-is-continued-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (end-of-line 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (icon-is-continuation-line)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (defun icon-backward-to-start-of-if (&optional limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 "Move to the start of the last \"unbalanced\" if."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (or limit (setq limit (save-excursion (beginning-of-icon-defun) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 (let ((if-level 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (case-fold-search nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (while (not (zerop if-level))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 (backward-sexp 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (cond ((looking-at "else\\b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (setq if-level (1+ if-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 ((looking-at "if\\b")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (setq if-level (1- if-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ((< (point) limit)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 (setq if-level 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 (goto-char limit))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 (defun mark-icon-function ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 "Put mark at end of Icon function, point at beginning."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 (push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (end-of-icon-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 (push-mark (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (beginning-of-line 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (beginning-of-icon-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (defun beginning-of-icon-defun ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 "Go to the start of the enclosing procedure; return t if at top level."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (if (re-search-backward "^procedure\\s \\|^end[ \t\n]" (point-min) 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (looking-at "e")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (defun end-of-icon-defun ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (if (not (bobp)) (forward-char -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (re-search-forward "\\(\\s \\|^\\)end\\(\\s \\|$\\)" (point-max) 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (forward-word -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (forward-line 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (defun indent-icon-exp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 "Indent each line of the Icon grouping following point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 (let ((indent-stack (list nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (contain-stack (list (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 restart outer-loop-done inner-loop-done state ostate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 this-indent last-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 at-else at-brace at-do
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (opoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (next-depth 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (forward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (setq outer-loop-done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (while (and (not (eobp)) (not outer-loop-done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (setq last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; Compute how depth changes over this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ;; plus enough other lines to get to one that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 ;; does not end inside a comment or string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;; Meanwhile, do appropriate indentation on comment lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (setq innerloop-done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (while (and (not innerloop-done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (not (and (eobp) (setq outer-loop-done t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (setq ostate state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 nil nil state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (setq next-depth (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (if (and (car (cdr (cdr state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (>= (car (cdr (cdr state))) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (setq last-sexp (car (cdr (cdr state)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 (if (or (nth 4 ostate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (icon-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 (if (or (nth 3 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (setq innerloop-done t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (if (<= next-depth 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (setq outer-loop-done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (if outer-loop-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 (if (/= last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 (setq last-sexp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (while (> last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 (setq indent-stack (cdr indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 contain-stack (cdr contain-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 last-depth (1- last-depth)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (while (< last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (setq indent-stack (cons nil indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 contain-stack (cons nil contain-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 last-depth (1+ last-depth)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 (if (null (car contain-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (setcar contain-stack (or (car (cdr state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (save-excursion (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (if (and (car indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (>= (car indent-stack) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 ;; Line is on an existing nesting level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 ;; Lines inside parens are handled specially.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (if (/= (char-after (car contain-stack)) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (setq this-indent (car indent-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 ;; Line is at statement level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 ;; Is it a new statement? Is it an else?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 ;; Find last non-comment character before this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (setq at-else (looking-at "else\\W"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (setq at-brace (= (following-char) ?{))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (icon-backward-to-noncomment opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (if (icon-is-continuation-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 ;; Preceding line did not end in comma or semi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ;; indent this line icon-continued-statement-offset
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ;; more than previous.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (icon-backward-to-start-of-continued-exp (car contain-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (setq this-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 (+ icon-continued-statement-offset (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 (if at-brace icon-continued-brace-offset 0))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 ;; Preceding line ended in comma or semi;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 ;; use the standard indent for this level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 (if at-else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (progn (icon-backward-to-start-of-if opoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (setq this-indent (current-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 (setq this-indent (car indent-stack))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 ;; Just started a new nesting level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 ;; Compute the standard indent for this level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (let ((val (calculate-icon-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (if (car indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (- (car indent-stack))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (setcar indent-stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (setq this-indent val))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 ;; Adjust line indentation according to its contents
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (if (or (= (following-char) ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (looking-at "end\\b"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (setq this-indent (- this-indent icon-indent-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (if (= (following-char) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (setq this-indent (+ this-indent icon-brace-offset)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 ;; Put chosen indentation into effect.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (or (= (current-column) this-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (delete-region (point) (progn (beginning-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (indent-to this-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 ;; Indent any comment following the text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (or (looking-at comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (if (re-search-forward comment-start-skip (save-excursion (end-of-line) (point)) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (progn (indent-for-comment) (beginning-of-line))))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 ;;; icon.el ends here