annotate lisp/modes/vrml-mode.el @ 0:376386a54a3c r19-14

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