forked from halmueller/mapserver-emacs-mode
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmapserver-mode.el
More file actions
180 lines (159 loc) · 11.4 KB
/
mapserver-mode.el
File metadata and controls
180 lines (159 loc) · 11.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
;; mapserver-mode-el -- Major mode for editing UMN MapServer files
;;
;; Author: Axel Schaefer
;; Modified: 25 August 2014
;; Keywords: UMN Mapserver major-mode
;;
;; Available at: https://github.com/AxxL/mapserver-emacs-mode
;;
;; Modified version of Hal Muellers mapserver-mode.
;; Forked from: https://github.com/halmueller/mapserver-emacs-mode
;;
;; Adjusted to mapserver 6.4.1.
;;
;; The original file seems to be based on the Mode Tutorial by Scott Andrew
;; Borton at http://www.emacswiki.org/emacs/ModeTutorial. See also the
;; Sample Major Mode example by Stefan Monnier at
;; http://www.emacswiki.org/emacs/SampleMode.
;;
;;
;; INSTALLATION
;; ------------
;;
;; Grab the neccessary file at:
;; https://github.com/AxxL/mapserver-emacs-mode/blob/master/mapserver-mode.el
;;
;; Put it into: $HOME/.emacs.d/lisp/
;;
;; You need to add the following lines to your $HOME/.emacs.d/init.el
;;
;; (autoload 'mapserver-mode "mapserver-mode" "Mode for editing UMN MapServer files." t)
;; (add-to-list 'auto-mode-alist '("\\.map\\'" . mapserver-mode))
;;
;; If you haven't specified your load-path it is a good idea to do it now. Put
;; the following line before the other two lines.
;;
;; (add-to-list 'load-path "~/.emacs.d/lisp")
;;
;; Some help for Emacs is available at the [[http://www.emacswiki.org/][Emacs Wiki]].
;;
;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Author: Hal Mueller <hal@mobilegeographics.com>
;; Created: 22 May 2004
;; Keywords: MapServer major-mode
;;
;; Copyright (C) 2004 Hal Mueller <hal@mobilegeographics.com>
;; (distributed under the standard MapServer license)
;;
;; Permission is hereby granted, free of charge, to any person obtaining a
;; copy of this software and associated documentation files (the
;; "Software"), to deal in the Software without restriction, including
;; without limitation the rights to use, copy, modify, merge, publish,
;; distribute, sublicense, and/or sell copies of the Software, and to permit
;; persons to whom the Software is furnished to do so, subject to the
;; following conditions:
;;
;; The above copyright notice and this permission notice shall be included
;; in all copies of this Software or works derived from this Software.
;;
;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
;; OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
;; MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
;; NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
;; DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
;; OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
;; USE OR OTHER DEALINGS IN THE SOFTWARE.
;;; Code:
(defvar mapserver-mode-hook nil)
(defvar mapserver-mode-map
(let ((mapserver-mode-map (make-keymap)))
(define-key mapserver-mode-map "\C-j" 'newline-and-indent)
mapserver-mode-map)
"Keymap for MapServer major mode")
(add-to-list 'auto-mode-alist '("\\.map\\'" . mapserver-mode))
(add-to-list 'auto-mode-alist '("\\.MAP\\'" . mapserver-mode))
(defconst mapserver-font-lock-keywords-1
(list
;; These define the beginning and end of each MapServer entity definition
'("\\<\\(C\\(?:L\\(?:ASS\\|USTER\\)\\|OMPOSITE\\)\\|END\\|FEATURE\\|GRID\\|JOIN\\|L\\(?:A\\(?:BEL\\|YER\\)\\|E\\(?:ADER\\|GEND\\)\\)\\|M\\(?:AP\\|ETADATA\\)\\|PROJECTION\\|QUERYMAP\\|REFERENCE\\|S\\(?:CALEBAR\\|TYLE\\|YMBOL\\)\\|VALIDATION\\|WEB\\)\\>" . font-lock-builtin-face)
'("\\('\\w*'\\)" . font-lock-variable-name-face))
"Minimal highlighting expressions for MapServer mode.")
(defconst mapserver-font-lock-keywords-2
(append mapserver-font-lock-keywords-1
(list
;; These are some possible attributes of MapServer entities
'("\\<\\(A\\(?:LIGN\\|N\\(?:CHORPOINT\\|GLE\\(?:ITEM\\)?\\|TIALIAS\\)\\)\\|B\\(?:\\(?:ACKGROUND\\(?:\\(?:SHADOW\\)?COLO\\)\\|UFFE\\)R\\)\\|C\\(?:HARACTER\\|LASS\\(?:GROUP\\|ITEM\\)\\|O\\(?:LOR\\|MPOP\\|N\\(?:FIG\\|NECTION\\(?:TYPE\\)?\\)\\)\\)\\|D\\(?:ATA\\(?:PATTERN\\)?\\|E\\(?:BUG\\|FRESOLUTION\\)\\|RIVER\\|UMP\\)\\|E\\(?:MPTY\\|NCODING\\|RROR\\|X\\(?:PRESSION\\|TEN\\(?:SION\\|T\\)\\)\\)\\|F\\(?:IL\\(?:LED\\|TER\\(?:ITEM\\)?\\)\\|O\\(?:NT\\(?:SET\\)?\\|OTER\\|R\\(?:CE\\|MATOPTION\\)\\)\\|ROM\\)\\|G\\(?:AP\\|EOMTRANSFORM\\|R\\(?:\\(?:IDSTE\\|OU\\)P\\)\\)\\|HEADER\\|I\\(?:MAGE\\(?:COLOR\\|MODE\\|PATH\\|QUALITY\\|TYPE\\|URL\\)?\\|N\\(?:CLUDE\\|ITIALGAP\\|TER\\(?:LACE\\|VALS\\)\\)\\|T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E\\(?:I\\(?:NDEX\\|TEM\\)\\|SRS\\)\\|O\\(?:LERANCE\\(?:UNITS\\)?\\)?\\|RANS\\(?:FORM\\|PAREN\\(?:CY\\|T\\)\\)\\|YPE\\)\\|UNITS\\|W\\(?:KT\\|RAP\\)\\)\\>" . font-lock-variable-name-face)
;; AXS
;; '("\\<\\(COLOR\\|MAXSIZE\\)\\>" . font-lock-keyword-face)
'("\\<\\(ON\\|OFF\\)\\>" . font-lock-constant-face)))
"Additional Keywords to highlight in MapServer mode.")
(defconst mapserver-font-lock-keywords-3
(append mapserver-font-lock-keywords-2
(list
;; These are some possible built-in values for MapServer attributes
;; POINT POLYGON LINE
;; AXS
;; '("\\<(LINE\\|PO\\(?:INT\\|LYGON\\))\\>" . font-lock-constant-face)))
'("\\<\\(LINE\\|MULTI\\(?:LINE\\|PO\\(?:INT\\|LYGON\\)\\)\\|O\\(?:FF\\|N\\)\\|PO\\(?:INT\\|LYGON\\)\\|RASTER\\|TRUETYPE\\|angle\\|bbox_pixel_is_point\\|c\\(?:lear\\|o\\(?:lor-\\(?:burn\\|dodge\\)\\|nt\\(?:our\\|rast\\)\\)\\)\\|d\\(?:arken\\|ifference\\|st\\(?:-\\(?:atop\\|in\\|o\\(?:ut\\|ver\\)\\)\\)?\\)\\|e\\(?:mbed\\|xclusion\\)\\|gml_\\(?:\\(?:exclude_item\\|g\\(?:eometrie\\|roup\\)\\|\\(?:include\\|xml\\)_item\\)s\\)\\|hard-light\\|invert\\(?:-rgb\\)?\\|kerneldensity\\|l\\(?:ighten\\|ocal\\)\\|m\\(?:eters\\|inus\\|ultiply\\)\\|o\\(?:gr\\|r\\(?:aclespatial\\)?\\|verlay\\|ws_\\(?:a\\(?:ccessconstraints\\|ddress\\(?:type\\)?\\|llowed_ip_list\\)\\|c\\(?:ity\\|o\\(?:ntact\\(?:electronicmailaddress\\|facsimiletelephone\\|information\\|organization\\|p\\(?:\\(?:ers\\|ositi\\)on\\)\\|voicetelephone\\)\\|untry\\)\\)\\|denied_ip_list\\|enable_request\\|fees\\|http_max_age\\|keywordlist\\|postcode\\|s\\(?:chemas_location\\|ld_enabled\\|tateorprovince\\)\\|updatesequence\\)\\)\\|p\\(?:lu\\(?:gin\\|s\\)\\|ostgis\\)\\|r\\(?:adius\\|l\\)\\|s\\(?:creen\\|de\\|oft-light\\|rc\\(?:-\\(?:atop\\|in\\|o\\(?:ut\\|ver\\)\\)\\)?\\)\\|u\\(?:nion\\|vraster\\|[lr]\\)\\|w\\(?:fs\\|ms\\(?:_\\(?:a\\(?:bstract\\|ccessconstraints\\|ddress\\(?: \\|type\\)\\|llowed_ip_list\\|ttribution_\\(?:logourl_\\(?:format\\|h\\(?:eight\\|ref\\)\\|width\\)\\|\\(?:onlineresourc\\|titl\\)e\\)\\|uthorityurl_\\(?:href\\|name\\)\\)\\|bbox_extended\\|c\\(?:ity\\|o\\(?:ntact\\(?:electronicmailaddress\\|facsimiletelephone\\|organization\\|p\\(?:\\(?:ers\\|ositi\\)on\\)\\|voicetelephone\\)\\|untry\\)\\)\\|d\\(?:ataurl_\\(?:format\\|href\\)\\|enied_ip_list\\)\\|e\\(?:n\\(?:able_request\\|coding\\)\\|x\\(?:clude_items\\|tent\\)\\)\\|fe\\(?:ature_info_mime_type\\|es\\)\\|g\\(?:et\\(?:capabilities_version\\|\\(?:featureinfo\\|legendgraphic\\|map\\)_formatlist\\)\\|roup_\\(?:abstract\\|title\\)\\)\\|i\\(?:dentifier_\\(?:authority\\|value\\)\\|nclude_items\\)\\|keywordlist\\(?:_vocabulary\\)?\\|la\\(?:nguages\\|yer\\(?:_group\\|limit\\)\\)\\|metadataurl_\\(?:format\\|href\\|type\\)\\|o\\(?:\\(?:nlineresourc\\|paqu\\)e\\)\\|postcode\\|r\\(?:e\\(?:mote_sld_max_bytes\\|s[xy]\\)\\|ootlayer_\\(?:abstract\\|keywordlist\\|title\\)\\)\\|s\\(?:ervice_onlineresource\\|rs\\|t\\(?:\\(?:ateorprovinc\\|yl\\)e\\)\\)\\|ti\\(?:me\\(?:default\\|extent\\|format\\|item\\)\\|tle\\)\\)\\)?\\)\\|xor\\)\\>" . font-lock-constant-face)))
"Balls-out highlighting in MapServer mode.")
(defvar mapserver-mode-tab-width 4)
(defvar mapserver-font-lock-keywords mapserver-font-lock-keywords-3
"Default highlighting expressions for MapServer mode.")
(defun mapserver-indent-line ()
"Indent current line as MapServer code."
(interactive)
(beginning-of-line)
(if (bobp)
(indent-line-to 0) ; First line is always non-indented
(let ((not-indented t) cur-indent)
(if (looking-at "^[ \t]*END") ; If the line we are looking at is the end of a block, then decrease the indentation
(progn
(save-excursion
(forward-line -1)
(setq cur-indent (- (current-indentation) mapserver-mode-tab-width)))
(if (< cur-indent 0) ; We can't indent past the left margin
(setq cur-indent 0)))
(save-excursion
(while not-indented ; Iterate backwards until we find an indentation hint
(forward-line -1)
(if (looking-at "^[ \t]*END") ; This hint indicates that we need to indent at the level of the END_ token
(progn
(indent-according-to-mode)
(setq cur-indent (current-indentation))
(setq not-indented nil))
;; CLASS FEATURE FONTSET GRID JOIN LAYER LEGEND MAP OUTPUTFORMAT POINTS PROJECTION QUERYMAP REFERENCE SCALEBAR STYLE WEB
(if (or (looking-at "^SYMBOL$")
(looking-at "^[ \t]*\\(CLASS$\\|COMPOSITE\\|FEATURE\\|FONTSET\\|GRID\\|JOIN\\|LABEL$\\|LAYER\\|LEGEND\\|MAP\\|METADATA\\|OUTPUTFORMAT\\|POINTS\\|PROJECTION\\|QUERYMAP\\|REFERENCE\\|SCALEBAR\\|SYMBOL$\\|SYMBOLSET\\|STYLE\\|WEB\\)")) ; This hint indicates that we need to indent an extra level
(progn
(setq cur-indent (+ (current-indentation) mapserver-mode-tab-width)) ; Do the actual indenting
(setq not-indented nil))
(if (bobp)
(setq not-indented nil)))))))
(if cur-indent
(indent-line-to cur-indent)
(indent-line-to 0))))) ; If we didn't see an indentation hint, then allow no indentation
(defvar mapserver-mode-syntax-table
(let ((mapserver-mode-syntax-table (make-syntax-table)))
;; This is added so entity names with underscores can be more easily parsed
(modify-syntax-entry ?_ "w" mapserver-mode-syntax-table)
(modify-syntax-entry ?# "<" mapserver-mode-syntax-table)
(modify-syntax-entry ?\n ">" mapserver-mode-syntax-table)
mapserver-mode-syntax-table)
"Syntax table for mapserver-mode")
(defun mapserver-mode ()
(interactive)
(kill-all-local-variables)
(use-local-map mapserver-mode-map)
(set-syntax-table mapserver-mode-syntax-table)
;; Set up font-lock
(set (make-local-variable 'font-lock-defaults) '(mapserver-font-lock-keywords))
;; Register our indentation function
(set (make-local-variable 'indent-line-function) 'mapserver-indent-line)
(set (make-local-variable 'tab-width) mapserver-mode-tab-width)
(setq major-mode 'mapserver-mode)
(setq mode-name "MapServer")
(run-hooks 'mapserver-mode-hook)
(setq comment-start "#"))
(provide 'mapserver-mode)
;;; mapserver-mode.el ends here