This repository has been archived by the owner on Nov 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathasp-mode.el
147 lines (123 loc) · 8.71 KB
/
asp-mode.el
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
;;; asp-mode-el -- Major mode for editing ASP files
;; Author: Chris Done <[email protected]>
;; Created: 22 March 2009
;; Keywords: ASP major-mode
;; Based on file based on WPDL-Mode Tutorial by Scott Andrew Borton
;; Copyright (C) 2009 Chris Done <[email protected]>
;; Copyright (C) 2004 Christoph Kepper <[email protected]>
;; Copyright (C) 2000, 2003 Scott Andrew Borton <[email protected]>
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or (at
;; your option) any later version.
;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; if not, write to the Free Software
;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
;; USA
;;; COMMENTARY
;;
;; Based on a file which is in turn based on a file for demonstrating modes.
;;;; This mode is based on an example by Scott Andrew Borton used in a
;;;; tutorial about Emacs mode creation. The tutorial can be found here:
;;;; http://two-wugs.net/emacs/mode-tutorial.html
;;;;
;;;; This is my first Emacs-mode - please be patient, if things don't work
;;;; as planned
;;; INSTALLATION
;;
;; To automatically load files with a .asp extension, put the following
;; lines in your .emacs file:
;; (autoload 'asp-mode "asp-mode")
;; (setq auto-mode-alist
;; (cons '("\\.asp\\'" . asp-mode) auto-mode-alist))
;;; TODO
;;
;;
;;; CODE
(defvar asp-mode-hook nil)
(defvar asp-mode-map
(let ((asp-mode-map (make-keymap)))
(define-key asp-mode-map "\C-j" 'newline-and-indent)
asp-mode-map)
"Keymap for ASP major mode")
(add-to-list 'auto-mode-alist '("\\.asp\\'" . asp-mode))
(defconst asp-font-lock-keywords-1
; (insert (regexp-opt '("if" "sub" "function" "then" "else" "end" "while" "do" "for" "each" "in" "set" "wend" "next" "loop" "call" "option" "explicit" "redim" "preserve" "dim" "const" "to" "select" "case" "elseif" "exit" "continue" "class" "new" "execute" "not") t))
(list
'("\\<\\(c\\(?:a\\(?:ll\\|se\\)\\|lass\\|on\\(?:st\\|tinue\\)\\)\\|d\\(?:im\\|o\\)\\|e\\(?:ach\\|lse\\(?:if\\)?\\|nd\\|x\\(?:ecute\\|\\(?:plic\\)?it\\)\\)\\|f\\(?:or\\|unction\\)\\|i[fn]\\|loop\\|n\\(?:e\\(?:w\\|xt\\)\\|ot\\)\\|option\\|preserve\\|redim\\|s\\(?:e\\(?:\\(?:lec\\)?t\\)\\|ub\\)\\|t\\(?:hen\\|o\\)\\|w\\(?:end\\|hile\\)\\)\\>" . font-lock-keyword-face))
"Keywords to highlight in ASP mode. (There aren't many.)")
(defconst asp-font-lock-keywords-2
; (insert (regexp-opt '("empty" "nothing" "null" "true" "false" "eof") t))
(append asp-font-lock-keywords-1
(list
'("\\<\\(e\\(?:mpty\\|of\\)\\|false\\|n\\(?:othing\\|ull\\)\\|true\\)\\>" . font-lock-constant-face))))
(defconst asp-font-lock-keywords-3
; (insert (regexp-opt '("@codepage" "@enablesessionstate" "@language" "@lcid" "@transaction" "abandon" "session" "addheader" "response" "appendtolog" "response" "application" "application_onend" "application" "application_onstart" "application" "aspcode" "asperror" "aspdescription" "asperror" "asperror" "binaryread" "request" "binarywrite" "response" "buffer" "response" "cachecontrol" "response" "category" "asperror" "charset" "response" "clear" "response" "clientcertificate" "collection" "request" "codepage" "response" "codepage" "session" "column" "asperror" "contents" "collection" "application" "contents" "collection" "session" "contenttype" "response" "cookies" "collection" "request" "cookies" "collection" "response" "create" "server" "description" "asperror" "end" "response" "execute" "server" "expires" "response" "expiresabsolute" "response" "file" "asperror" "flush" "response" "form" "collection" "request" "getlasterror" "server" "htmlencode" "server" "isclientconnected" "response" "lcid" "response" "lcid" "session" "line" "asperror" "lock" "application" "mappath" "server" "number" "asperror" "context" "onendpage" "custom" "onstartpage" "custom" "ontransactionabort" "context" "ontransactioncommit" "context" "pics" "response" "querystring" "collection" "request" "redirect" "response" "remove" "application" "remove" "session" "removeall" "application" "removeall" "session" "request" "response" "scripttimeout" "server" "server" "servervariables" "collection" "request" "session" "session_onend" "session" "session_onstart" "session" "sessionid" "session" "setabort" "context" "setcomplete" "context" "source" "asperror" "statics" "collection" "application" "statics" "collection" "session" "status" "response" "timeout" "session" "totalbytes" "request" "transfer" "server" "unlock" "application" "urlencode" "server" "write") t))
(append asp-font-lock-keywords-2
(list
'("\\<\\(@\\(?:codepage\\|enablesessionstate\\|l\\(?:anguage\\|cid\\)\\|transaction\\)\\|a\\(?:bandon\\|ddheader\\|pp\\(?:endtolog\\|lication\\(?:_on\\(?:end\\|start\\)\\)?\\)\\|sp\\(?:code\\|description\\|error\\)\\)\\|b\\(?:inary\\(?:read\\|write\\)\\|uffer\\)\\|c\\(?:a\\(?:checontrol\\|tegory\\)\\|harset\\|l\\(?:ear\\|ientcertificate\\)\\|o\\(?:depage\\|l\\(?:\\(?:lectio\\|um\\)n\\)\\|nte\\(?:nt\\(?:s\\|type\\)\\|xt\\)\\|okies\\)\\|reate\\|ustom\\)\\|description\\|e\\(?:nd\\|x\\(?:ecute\\|pires\\(?:absolute\\)?\\)\\)\\|f\\(?:ile\\|lush\\|orm\\)\\|getlasterror\\|htmlencode\\|isclientconnected\\|l\\(?:cid\\|ine\\|ock\\)\\|mappath\\|number\\|on\\(?:endpage\\|startpage\\|transaction\\(?:\\(?:abor\\|commi\\)t\\)\\)\\|pics\\|querystring\\|re\\(?:direct\\|move\\(?:all\\)?\\|quest\\|sponse\\)\\|s\\(?:cripttimeout\\|e\\(?:rver\\(?:variables\\)?\\|ssion\\(?:_on\\(?:end\\|start\\)\\|id\\)?\\|t\\(?:abort\\|complete\\)\\)\\|ource\\|tat\\(?:\\(?:ic\\|u\\)s\\)\\)\\|t\\(?:imeout\\|otalbytes\\|ransfer\\)\\|u\\(?:nlock\\|rlencode\\)\\|write\\)\\>" . font-lock-builtin-face))))
(defvar asp-font-lock-keywords asp-font-lock-keywords-3
"Default highlighting expressions for ASP mode.")
(defun asp-indent-line ()
"Indent current line as ASP code."
(interactive)
(beginning-of-line)
;; Regel 1
(if (bobp)
(indent-line-to 0) ; First line is always non-indented
(let ((not-indented t) cur-indent)
(if (looking-at "^[ \t]*\\(end \\w+\\|next\\|loop\\|wend\\|else\\|elseif\\)\\>") ; 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) default-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 \\w+\\|next\\|loop\\|wend\\)\\>") ; This hint indicates that we need to indent at the level of the END_ token
(progn
(setq cur-indent (current-indentation))
(setq not-indented nil))
(if (looking-at "^[ \t]*\\(if\\|sub\\|function\\|else\\|while\\|do\\|for\\|select\\)\\>") ; This hint indicates that we need to indent an extra level
(progn
(setq cur-indent (+ (current-indentation) default-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 asp-mode-syntax-table
(let ((asp-mode-syntax-table (make-syntax-table)))
;; This is added so entity names with underscores can be more easily parsed
(modify-syntax-entry ?_ "w" asp-mode-syntax-table)
;; Comment start with # and end with a newline
(modify-syntax-entry ?\' "<")
(modify-syntax-entry ?\n ">")
(modify-syntax-entry ?\\ ".")
asp-mode-syntax-table)
"Syntax table for asp-mode")
(defun asp-mode ()
"Major Mode for editing ASP files"
(interactive)
(kill-all-local-variables)
(use-local-map asp-mode-map)
(set-syntax-table asp-mode-syntax-table)
;; Set up font-lock
(set (make-local-variable 'font-lock-defaults) '(asp-font-lock-keywords nil t))
;; Register our indentation function
(set (make-local-variable 'indent-line-function) 'asp-indent-line)
(set (make-local-variable 'default-tab-width) 4)
(make-variable-buffer-local 'comment-start)
(setq comment-start "' ")
(setq major-mode 'asp-mode)
(setq mode-name "ASP")
(run-hooks 'asp-mode-hook))
(provide 'asp-mode)
;;; asp-mode.el ends here