annotate lisp/modes/vrml-mode.el @ 126:1370575f1259 xemacs-20-1p1

Import from CVS: tag xemacs-20-1p1
author cvs
date Mon, 13 Aug 2007 09:27:39 +0200
parents cca96a509cfe
children 1856695b1fa9
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 ;;; vrml-mode.el --- major mode for editing VRML (.wrl) files
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) 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4 ;; Copyright (C) 1996 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Author: Ben Wing <wing@666.com>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 ;; Keywords: languages vrml modes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; under the terms of the GNU General Public License as published by
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
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 ;; General Public License for more details.
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
16
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
22 ;; along with XEmacs; see the file COPYING. If not, write to the
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
0293115a14e9 Import from CVS: tag r19-15b91
cvs
parents: 2
diff changeset
24 ;; Boston, MA 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 ;;; Synched up with: Not in FSF.
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 ;; Mostly bastardized from tcl.el.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; HOW TO INSTALL:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 ;; Put the following forms in your .emacs to enable autoloading of VRML
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;; mode, and auto-recognition of ".wrl" files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 ;; (autoload 'vrml-mode "vrml" "VRML mode." t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 ;; (setq auto-mode-alist (append '(("\\.wrl\\'" . vrml-mode))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 ;; auto-mode-alist))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 ;; User variables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
47 (defgroup vrml nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
48 "VRML Language"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
49 :group 'languages)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
50
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
51 (defgroup vrml-mode nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
52 "VRML mode customization"
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
53 :group 'vrml
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
54 :prefix "vrml-")
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
55
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
57 (defcustom vrml-indent-level 3
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
58 "*Indentation of VRML statements with respect to containing block."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
59 :type 'integer
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
60 :group 'vrml-mode)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
61
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
62 (defcustom vrml-auto-newline nil
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 "*Non-nil means automatically newline before and after braces
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
64 inserted in VRML code."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
65 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
66 :group 'vrml-mode)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
68 (defcustom vrml-tab-always-indent t
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 "*Control effect of TAB key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 If t (the default), always indent current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 If nil and point is not in the indentation area at the beginning of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 the line, a TAB is inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 Other values cause the first possible action from the following list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 to take place:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 1. Move from beginning of line to correct indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 2. Delete an empty comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 3. Move forward to start of comment, indenting if necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 4. Move forward to end of line, indenting if necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 5. Create an empty comment.
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
81 6. Move backward to start of comment, indenting if necessary."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
82 :type '(choice (const :tag "on" t)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
83 (const :tag "off" nil)
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
84 (const :tag "The Works" other))
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
85 :group 'vrml-mode)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
87 (defcustom vrml-use-hairy-comment-detector t
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
88 "*If not `nil', then the more complicated, but slower, comment
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
89 detecting function is used."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
90 :type 'boolean
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
91 :group 'vrml-mode)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (defvar vrml-mode-abbrev-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94 "Abbrev table used while in VRML mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (define-abbrev-table 'vrml-mode-abbrev-table ())
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (defvar vrml-mode-map ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 "Keymap used in VRML mode.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (if (null vrml-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (setq vrml-mode-map (make-sparse-keymap))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (set-keymap-name vrml-mode-map 'vrml-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (define-key vrml-mode-map "{" 'vrml-electric-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 (define-key vrml-mode-map "}" 'vrml-electric-brace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 (define-key vrml-mode-map "\e\C-q" 'indent-vrml-exp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 (define-key vrml-mode-map "\177" 'backward-delete-char-untabify)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 (define-key vrml-mode-map "\t" 'vrml-indent-command)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (define-key vrml-mode-map "\M-;" 'vrml-indent-for-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (defvar vrml-mode-syntax-table nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 "Syntax table in use in vrml-mode buffers.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 (if vrml-mode-syntax-table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (setq vrml-mode-syntax-table (make-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (modify-syntax-entry ?\n ">" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 (modify-syntax-entry ?\f ">" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 (modify-syntax-entry ?\# "<" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 (modify-syntax-entry ?\\ "\\" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 (modify-syntax-entry ?% "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 (modify-syntax-entry ?@ "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 (modify-syntax-entry ?& "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 (modify-syntax-entry ?* "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (modify-syntax-entry ?- "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 (modify-syntax-entry ?: "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 (modify-syntax-entry ?! "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (modify-syntax-entry ?$ "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (modify-syntax-entry ?/ "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (modify-syntax-entry ?~ "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 (modify-syntax-entry ?< "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 (modify-syntax-entry ?= "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 (modify-syntax-entry ?> "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (modify-syntax-entry ?| "_" vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (modify-syntax-entry ?+ "." vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (modify-syntax-entry ?\' "\"" vrml-mode-syntax-table))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
138 (defcustom vrml-mode-hook nil
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
139 "Hook run on entry to VRML mode."
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
140 :type 'hook
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 108
diff changeset
141 :group 'vrml-mode)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (defvar vrml-keyword-list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 '(
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 ; shape nodes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 "AsciiText" "Cone" "Cube" "Cylinder" "IndexedFaceSet" "IndexedLineSet"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 "PointSet" "Sphere"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ; geometry and material nodes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 "Coordinate3" "FontStyle" "Info" "LOD" "Material" "MaterialBinding"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 "Normal" "NormalBinding" "Texture2" "Texture2Transform"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 "TextureCoordinate2" "ShapeHints"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 ; transformation nodes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 "MatrixTransform" "Rotation" "Scale" "Transform" "Translation"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 ;camera nodes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 "OrthographicCamera" "PerspectiveCamera"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 ;lighting nodes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 "DirectionalLight" "PointLight" "SpotLight"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 ;group nodes:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 "Group" "Separator" "Switch" "TransformSeparator" "WWWAnchor"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;other:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 "WWWInline"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;new VRML 2.0 nodes (#### not yet classified)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 "Anchor" "Appearance" "AudioClip" "Background" "Billboard" "Box"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 "Collision" "Color" "ColorInterpolator" "Coordinate"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 "CoordinateInterpolator" "CylinderSensor" "DiskSensor" "ElevationGrid"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 "Extrusion" "Fog" "FontStyle" "ImageTexture" "Inline" "MovieTexture"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 "NavigationInfo" "NormalInterpolator" "OrientationInterpolator"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 "PixelTexture" "PlaneSensor" "PositionInterpolator" "ProximitySensor"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 "ScalarInterpolator" "Script" "Shape" "Sound" "SphereSensor" "Text"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 "TextureTransform" "TextureCoordinate" "TimeSensor" "TouchSensor"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 "Viewpoint" "VisibilitySensor" "WorldInfo"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 ;VRML 2.0 node fields
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 "eventIn" "eventOut" "field" "exposedField"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 ;misc. VRML 2.0 keywords (DEF, PROTO, EXTERNPROTO handled below)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 "USE" "ROUTE" "TO" "IS" "TRUE" "FALSE" "NULL"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (defconst vrml-font-lock-keywords
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 ;; Names of functions (and other "defining things").
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (list "\\(DEF\\|PROTO\\|EXTERNPROTO\\)[ \t\n]+\\([^ \t\n]+\\)"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 2 'font-lock-function-name-face)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 ;; Keywords. Only recognized if surrounded by whitespace.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ;; FIXME consider using "not word or symbol", not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 ;; "whitespace".
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (cons (concat "\\(\\s-\\|^\\)\\("
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 ;; FIXME Use regexp-quote?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (mapconcat 'identity vrml-keyword-list "\\|")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 "\\)\\(\\s-\\|$\\)")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 "Keywords to highlight for VRML. See variable `font-lock-keywords'.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (defun vrml-mode ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 "Major mode for editing VRML code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 Expression and list commands understand all VRML brackets.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 Tab indents for VRML code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 Paragraphs are separated by blank lines only.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 Delete converts tabs to spaces as it moves back.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 Variables controlling indentation style:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 vrml-indent-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 Indentation of VRML statements within surrounding block.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 Variables controlling user interaction with mode (see variable
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 documentation for details):
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 vrml-tab-always-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 Controls action of TAB key.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 vrml-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 Non-nil means automatically newline before and after braces
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 inserted in VRML code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 Turning on VRML mode calls the value of the variable `vrml-mode-hook'
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 with no args, if that value is non-nil. Read the documentation for
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 `vrml-mode-hook' to see what kinds of interesting hook functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 already exist.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 Commands:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 \\{vrml-mode-map}"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (kill-all-local-variables)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 (use-local-map vrml-mode-map)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 (setq major-mode 'vrml-mode)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 (setq mode-name "VRML")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (setq local-abbrev-table vrml-mode-abbrev-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (set-syntax-table vrml-mode-syntax-table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (make-local-variable 'paragraph-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (make-local-variable 'paragraph-separate)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (if (fboundp 'move-to-left-margin)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 ;; In FSF Emacs 19.29 / XEmacs 19.14, you aren't supposed to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;; start these with a ^.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (setq paragraph-start "$\\| ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 (setq paragraph-separate paragraph-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (setq paragraph-start (concat "^$\\|" page-delimiter))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 (setq paragraph-separate paragraph-start))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (make-local-variable 'paragraph-ignore-fill-prefix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 (setq paragraph-ignore-fill-prefix t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (make-local-variable 'fill-paragraph-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 (setq fill-paragraph-function 'vrml-do-fill-paragraph)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 (make-local-variable 'indent-line-function)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 (setq indent-line-function 'vrml-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 (make-local-variable 'require-final-newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 (setq require-final-newline t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (make-local-variable 'comment-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 (setq comment-start "# ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (make-local-variable 'comment-start-skip)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (setq comment-start-skip "#+ *")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 (make-local-variable 'comment-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 (setq comment-column 40)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (make-local-variable 'comment-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 (setq comment-end "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 (make-local-variable 'outline-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (setq outline-regexp "[^\n\^M]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 (make-local-variable 'outline-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (setq outline-level 'vrml-outline-level)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (make-local-variable 'font-lock-keywords)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 (setq font-lock-keywords vrml-font-lock-keywords)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 (make-local-variable 'parse-sexp-ignore-comments)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 (setq parse-sexp-ignore-comments t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 (make-local-variable 'defun-prompt-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 (setq defun-prompt-regexp "^[^ \t\n#}][^\n}]+}*[ \t]+")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 ;; Settings for new dabbrev code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (make-local-variable 'dabbrev-case-fold-search)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (setq dabbrev-case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 (make-local-variable 'dabbrev-case-replace)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 (setq dabbrev-case-replace nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 (make-local-variable 'dabbrev-abbrev-skip-leading-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (setq dabbrev-abbrev-skip-leading-regexp "[$!]")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 (make-local-variable 'dabbrev-abbrev-char-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (setq dabbrev-abbrev-char-regexp "\\sw\\|\\s_")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (run-hooks 'vrml-mode-hook))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ;; This is used for closing braces. If vrml-auto-newline is set, can
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 ;; insert a newline both before and after the brace, depending on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 ;; context. FIXME should this be configurable? Does anyone use this?
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 (defun vrml-electric-brace (arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 "Insert character and correct line's indentation."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 ;; If auto-newlining and there is stuff on the same line, insert a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 ;; newline first.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (if vrml-auto-newline
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (if (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297 (bolp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 (vrml-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (newline))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301 ;; In auto-newline case, must insert a newline after each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;; brace. So an explicit loop is needed.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 (while (> arg 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 (insert last-command-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 (vrml-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (newline)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 (setq arg (1- arg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 (self-insert-command arg))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 (vrml-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 (defun vrml-indent-command (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 "Indent current line as VRML code, or in some cases insert a tab character.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 If vrml-tab-always-indent is t (the default), always indent current line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 If vrml-tab-always-indent is nil and point is not in the indentation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 area at the beginning of the line, a TAB is inserted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 Other values of vrml-tab-always-indent cause the first possible action
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 from the following list to take place:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321 1. Move from beginning of line to correct indentation.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 2. Delete an empty comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 3. Move forward to start of comment, indenting if necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 4. Move forward to end of line, indenting if necessary.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 5. Create an empty comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 6. Move backward to start of comment, indenting if necessary."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 (interactive "p")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 ((not vrml-tab-always-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 ;; Indent if in indentation area, otherwise insert TAB.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 (if (<= (current-column) (current-indentation))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (vrml-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (self-insert-command arg)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334 ((eq vrml-tab-always-indent t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 ;; Always indent.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 (vrml-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 ;; "Perl-mode" style TAB command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (let* ((ipoint (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (eolpoint (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (comment-p (vrml-in-comment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 ((= ipoint (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 (vrml-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 ;; If indenting didn't leave us in column 0, go to the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 ;; indentation. Otherwise leave point at end of line. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 ;; is a hack.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 (if (= (point) (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 (back-to-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 ((and comment-p (looking-at "[ \t]*$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 ;; Empty comment, so delete it. We also delete any ";"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 ;; characters at the end of the line. I think this is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 ;; friendlier, but I don't know how other people will feel.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 (skip-chars-backward " \t;")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 (delete-region (point) eolpoint))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 ((and comment-p (< ipoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 ;; Before comment, so skip to it.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (vrml-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 (indent-for-comment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 ((/= ipoint eolpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 ;; Go to end of line (since we're not there yet).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (goto-char eolpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (vrml-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 ((not comment-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (vrml-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (vrml-indent-for-comment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 ;; Go to start of comment. We don't leave point where it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 ;; because we want to skip comment-start-skip.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (vrml-indent-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (indent-for-comment)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (defun vrml-indent-line ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 "Indent current line as VRML code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 Return the amount the indentation changed by."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (let ((indent (calculate-vrml-indent nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 beg shift-amt
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 (pos (- (point-max) (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (setq beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (cond ((eq indent nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (setq indent (current-indentation)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (if (listp indent) (setq indent (car indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 (cond ((= (following-char) ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (setq indent (- indent vrml-indent-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 ((= (following-char) ?\])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 (setq indent (- indent 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 (setq shift-amt (- indent (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 (if (zerop shift-amt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 (if (> (- (point-max) pos) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (goto-char (- (point-max) pos)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (delete-region beg (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (indent-to indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 ;; If initial point was within line's indentation,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 ;; position after the indentation. Else stay at same point in text.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (if (> (- (point-max) pos) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 (goto-char (- (point-max) pos))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 shift-amt))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 (defun calculate-vrml-indent (&optional parse-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414 "Return appropriate indentation for current line as VRML code.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 In usual case returns an integer: the column to indent to.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 Returns nil if line starts inside a string, t if in a comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 (let* ((indent-point (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 state
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 containing-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 found-next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (if parse-start
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (goto-char parse-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 (beginning-of-defun))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (while (< (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (setq parse-start (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (setq state (parse-partial-sexp (point) indent-point 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (setq containing-sexp (car (cdr state))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (cond ((or (nth 3 state) (nth 4 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 ;; Inside comment or string. Return nil or t if should
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 ;; not change this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (nth 4 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 ((null containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 ;; Line is at top level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 (let* ((expr-start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ;; Find the first statement in the block and indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ;; like it. The first statement in the block might be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ;; on the same line, so what we do is skip all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 ;; "virtually blank" lines, looking for a non-blank
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ;; one. A line is virtually blank if it only contains
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 ;; a comment and whitespace. We do it this funky way
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 ;; because we want to know if we've found a statement
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 ;; on some line _after_ the line holding the sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 ;; opener.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 (forward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 (if (and (< (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (looking-at "[ \t]*\\(#.*\\)?$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (forward-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (while (and (< (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 (looking-at "[ \t]*\\(#.*\\)?$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (setq found-next-line t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (forward-line))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (if (not (or (= (char-after containing-sexp) ?{)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 (and (= (char-after containing-sexp) ?\[)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (skip-chars-backward " \t\n")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 (forward-char -8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 (looking-at "children")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 ;; Line is continuation line, or the sexp opener
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
469 ;; is not a curly brace, or we are looking at
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 ;; an `expr' expression (which must be split
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 ;; specially). So indentation is column of first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 ;; good spot after sexp opener. If there is no
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 ;; nonempty line before the indentation point, we
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 ;; use the column of the character after the sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 ;; opener.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 (if (>= (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (goto-char containing-sexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (forward-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 (skip-chars-forward " \t"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (current-column))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 ;; After a curly brace, and not a continuation line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 ;; So take indentation from first good line after
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 ;; start of block, unless that line is on the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 ;; line as the opening brace. In this case use the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 ;; indentation of the opening brace's line, plus
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 ;; another indent step. If we are in the body part
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 ;; of an "if" or "while" then the indentation is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 ;; taken from the line holding the start of the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 ;; statement.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (if (and (< (point) indent-point)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 found-next-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 (current-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (if t ; commands-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (goto-char expr-start)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 (goto-char containing-sexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (+ (current-indentation) vrml-indent-level)))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 (defun indent-vrml-exp ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 "Indent each line of the VRML grouping following point."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (let ((indent-stack (list nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 (contain-stack (list (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 (case-fold-search nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 outer-loop-done inner-loop-done state ostate
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 this-indent last-sexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 (next-depth 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 last-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 (forward-sexp 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 (setq outer-loop-done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 (while (and (not (eobp)) (not outer-loop-done))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 (setq last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 ;; Compute how depth changes over this line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 ;; plus enough other lines to get to one that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 ;; does not end inside a comment or string.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 ;; Meanwhile, do appropriate indentation on comment lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (setq inner-loop-done nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (while (and (not inner-loop-done)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (not (and (eobp) (setq outer-loop-done t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (setq ostate state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (setq state (parse-partial-sexp (point) (progn (end-of-line) (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 nil nil state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 (setq next-depth (car state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 (if (and (car (cdr (cdr state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (>= (car (cdr (cdr state))) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530 (setq last-sexp (car (cdr (cdr state)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (if (or (nth 4 ostate))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 (vrml-indent-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 (if (or (nth 3 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 (setq inner-loop-done t)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 (if (<= next-depth 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (setq outer-loop-done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (if outer-loop-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 ;; If this line had ..))) (((.. in it, pop out of the levels
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 ;; that ended anywhere in this line, even if the final depth
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 ;; doesn't indicate that they ended.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 (while (> last-depth (nth 6 state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 (setq indent-stack (cdr indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545 contain-stack (cdr contain-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 last-depth (1- last-depth)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (if (/= last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 (setq last-sexp nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ;; Add levels for any parens that were started in this line.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 (while (< last-depth next-depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 (setq indent-stack (cons nil indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 contain-stack (cons nil contain-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 last-depth (1+ last-depth)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 (if (null (car contain-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 (setcar contain-stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 (or (car (cdr state))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (forward-sexp -1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (point)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (forward-line 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 (skip-chars-forward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 (if (eolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 (if (and (car indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (>= (car indent-stack) 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 ;; Line is on an existing nesting level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (setq this-indent (car indent-stack))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 ;; Just started a new nesting level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 ;; Compute the standard indent for this level.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (let ((val (calculate-vrml-indent
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (if (car indent-stack)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (- (car indent-stack))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 (setcar indent-stack
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 (setq this-indent val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (cond ((not (numberp this-indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 ((= (following-char) ?})
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (setq this-indent (- this-indent vrml-indent-level)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 ((= (following-char) ?\])
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (setq this-indent (- this-indent 1))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 ;; Put chosen indentation into effect.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (or (null this-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (= (current-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 this-indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (delete-region (point) (progn (beginning-of-line) (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (indent-to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 this-indent))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 ;; Auto-fill support.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 ;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (defun vrml-real-command-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 "Return nil if point is not at the beginning of a command.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 A command is the first word on an otherwise empty line, or the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 first word following an opening brace."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (cond
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 ((bobp) t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 ((bolp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 ;; Note -- continued comments are not supported here. I
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 ;; consider those to be a wart on the language.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 (not (eq ?\\ (preceding-char))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 (memq (preceding-char) '(?{))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 ;; FIXME doesn't actually return t. See last case.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 (defun vrml-real-comment-p ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 "Return t if point is just after the `#' beginning a real comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 Does not check to see if previous char is actually `#'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 A real comment is either at the beginning of the buffer,
108
360340f9fd5f Import from CVS: tag r20-1b6
cvs
parents: 70
diff changeset
616 preceded only by whitespace on the line, or has a preceding
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 semicolon, opening brace, or opening bracket on the same line."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (vrml-real-command-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (defun vrml-hairy-scan-for-comment (state end always-stop)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 "Determine if point is in a comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 Returns a list of the form `(FLAG . STATE)'. STATE can be used
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 as input to future invocations. FLAG is nil if not in comment,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 t otherwise. If in comment, leaves point at beginning of comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 See also `vrml-simple-scan-for-comment', a simpler version that is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 often right."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (let ((bol (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 (goto-char end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 real-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 last-cstart)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (while (and (not last-cstart) (< (point) end))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (setq real-comment nil) ;In case we've looped around and it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 ;set.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (setq state (parse-partial-sexp (point) end nil nil state t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 (if (nth 4 state)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 ;; If ALWAYS-STOP is set, stop even if we don't have a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 ;; real comment, or if the comment isn't on the same line
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 ;; as the end.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 (if always-stop (setq last-cstart (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 ;; If we have a real comment, then set the comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 ;; starting point if we are on the same line as the ending
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 ;; location.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (setq real-comment (vrml-real-comment-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (if real-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 (and (> (point) bol) (setq last-cstart (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 ;; NOTE Emacs 19 has a misfeature whereby calling
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 ;; parse-partial-sexp with COMMENTSTOP set and with
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 ;; an initial list that says point is in a comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 ;; will cause an immediate return. So we must skip
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 ;; over the comment ourselves.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (beginning-of-line 2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 ;; Frob the state to make it look like we aren't in a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 ;; comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (setcar (nthcdr 4 state) nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (and last-cstart
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (goto-char last-cstart))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (cons real-comment state)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (defun vrml-hairy-in-comment ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 "Return t if point is in a comment, and leave point at beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 of comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (let ((save (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (beginning-of-defun)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (car (vrml-hairy-scan-for-comment nil save nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (defun vrml-simple-in-comment ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 "Return t if point is in comment, and leave point at beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 of comment. This is faster than `vrml-hairy-in-comment', but is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 correct less often."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (let ((save (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (while (and (< (point) save) (not comment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (search-forward "#" save 'move)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (setq comment (vrml-real-comment-p)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 comment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (defun vrml-in-comment ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 "Return t if point is in comment, and leave point at beginning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 of comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (if vrml-use-hairy-comment-detector
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (vrml-hairy-in-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 (vrml-simple-in-comment)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (defun vrml-do-fill-paragraph (ignore)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 "fill-paragraph function for VRML mode. Only fills in a comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 (let (in-comment col where)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (setq in-comment (vrml-in-comment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (if in-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (setq where (1+ (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (setq col (1- (current-column))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (and in-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (= col (current-column)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 ;; In a comment. Set the fill prefix, and find the paragraph
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 ;; boundaries by searching for lines that look like
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 ;; comment-only lines.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 (let ((fill-prefix (buffer-substring (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (point))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 where))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 p-start p-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 ;; Search backwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (while (looking-at "^[ \t]*#")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 (forward-line -1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (forward-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (setq p-start (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 ;; Search forwards.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (while (looking-at "^[ \t]*#")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (forward-line))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (setq p-end (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726 ;; Narrow and do the fill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (narrow-to-region p-start p-end)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 (fill-paragraph ignore)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 (defun vrml-do-auto-fill ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 "Auto-fill function for VRML mode. Only auto-fills in a comment."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (if (> (current-column) fill-column)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (let ((fill-prefix "# ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 in-comment col)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (setq in-comment (vrml-in-comment))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (if in-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (setq col (1- (current-column)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (if in-comment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (do-auto-fill)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (back-to-indentation)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (delete-region (point) (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (indent-to-column col)))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 (defun vrml-indent-for-comment ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752 "Indent this line's comment to comment column, or insert an empty comment.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 Is smart about syntax of VRML comments.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 Parts of this were taken from indent-for-comment (simple.el)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 (interactive "*")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 (end-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 (or (vrml-in-comment)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 ;; Not in a comment, so we have to insert one. Create an
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 ;; empty comment (since there isn't one on this line).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 (skip-chars-backward " \t")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (let ((eolpoint (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (if (/= (point) eolpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (goto-char eolpoint)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (insert
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 "# ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (backward-char))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 ;; Point is just after the "#" starting a comment. Move it as
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 ;; appropriate.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (let* ((indent (funcall comment-indent-function))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 (begpos (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (backward-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 (point))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (if (/= begpos indent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (skip-chars-backward " \t" (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (beginning-of-line)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 (point)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (delete-region (point) begpos)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (indent-to indent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (looking-at comment-start-skip) ; Always true.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (goto-char (match-end 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 ;; I don't like the effect of the next two.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786 ;;(skip-chars-backward " \t" (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 ;;(skip-chars-backward "^ \t" (match-beginning 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 ))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790 ;;; vrml-mode.el ends here