initial commit
[emacs-init.git] / nxhtml / related / iss-mode.el
1 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2 ;;; iss-mode.el --- Mode for InnoSetup install scripts
3
4 ;; Copyright (C) 2000-2007 by Stefan Reichoer
5
6 ;; Emacs Lisp Archive Entry
7 ;; Filename: iss-mode.el
8 ;; Author: Stefan Reichoer, <stefan@xsteve.at>
9 ;; Version: 1.1d
10
11 ;; iss-mode.el is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; iss-mode.el is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to
23 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary
27
28 ;; InnoSetup is an Application Installer for Windows
29 ;; See: http://www.jrsoftware.org/isinfo.php
30 ;; This version of iss-mode.el is tested with InnoSetup v5.0
31
32 ;; iss-mode provides the following features:
33 ;; * Syntax coloring for InnoSetup scripts
34 ;; * Integration of the InnoSetup commandline compiler iscc.exe
35 ;;   - Compilation via M-x iss-compile
36 ;;   - Jump to compilation error via M-x next-error
37 ;; * Start Innosetup help via M-x iss-compiler-help
38 ;; * Test the installation via M-x iss-run-installer
39
40 ;; Of course you can bind this commands to keys (e.g. in the iss-mode-hook)
41
42 ;; My initialization for InnoSetup looks like this:
43 ;; (autoload 'iss-mode "iss-mode" "Innosetup Script Mode" t)
44 ;; (setq auto-mode-alist (append '(("\\.iss$"  . iss-mode)) auto-mode-alist))
45 ;; (setq iss-compiler-path "c:/Programme/Inno Setup 5/")
46 ;; (add-hook 'iss-mode-hook 'xsteve-iss-mode-init)
47 ;; (defun xsteve-iss-mode-init ()
48 ;;       (interactive)
49 ;;       (define-key iss-mode-map [f6] 'iss-compile)
50 ;;       (define-key iss-mode-map [(meta f6)] 'iss-run-installer)))
51
52 ;; The latest version of iss-mode.el can be found at:
53 ;;   http://www.xsteve.at/prg/emacs/iss-mode.el
54
55 ;; Comments / suggestions welcome!
56
57 ;;; Change log:
58 ;;
59 ;; Version 1.1e:
60 ;;
61 ;; - Add some new flags to keywords
62
63 ;;; Code:
64
65 (eval-and-compile (require 'compile))
66
67 (defvar iss-compiler-path nil "Path to the iss compiler")
68
69 ;;; End of user settings
70
71 (defvar iss-mode-syntax-table
72   (let ((table (make-syntax-table)))
73     ;; ";" starts a comment
74     ;;(modify-syntax-entry ?\; "<" iss-mode-syntax-table)
75     (modify-syntax-entry ?\; ". 12" table)
76     ;; and \n and \^M end a comment
77     (modify-syntax-entry ?\n ">"    table)
78     (modify-syntax-entry ?\^M ">"   table)
79
80     (modify-syntax-entry ?\" "."    table)
81
82     (modify-syntax-entry ?_ "w"     table)
83     table)
84   "Syntax table in use in iss-mode buffers.")
85
86
87 (defvar iss-font-lock-keywords
88   (list
89    (cons (concat "^;\.*")
90          'font-lock-comment-face)
91    (cons (concat "\\sw+: ")
92          'font-lock-keyword-face)
93    (cons "^[ \t]*\\[\.+\\]" 'font-lock-function-name-face) ;font-lock-constant-face)
94    (cons "^[ \t]*#include[ \t]*\".+\"" 'font-lock-preprocessor-face)
95    (cons (concat "^[ \t]*\\<\\(appname\\|appvername\\|appversion\\|appcopyright\\|appid\\|"
96                  "appmutex\\|beveledlabel\\|defaultdirname\\|versioninfoversion"
97                  "\\|defaultgroupname\\|minversion\\|outputdir\\|outputbasefilename\\|"
98                  "allownoicons\\|uninstallfilesdir\\|"
99                  "sourcedir\\|disableprogramgrouppage\\|alwayscreateuninstallicon\\)\\>")
100          'font-lock-type-face)
101    (cons (concat "\\<\\(alwaysskipifsameorolder\\|uninsneveruninstall\\|"
102                  "comparetimestampalso\\|restartreplace\\|isreadme\\|"
103                  "unchecked\\|nowait\\|postinstall\\|skipifsilent\\|ignoreversion\\|"
104                  "uninsdeletekeyifempty\\|uninsdeletekey\\|"
105                  "runasoriginaluser\\|runascurrentuser"
106                  "\\)\\>")
107          'font-lock-variable-name-face)
108    (cons (concat "\\<\\(HKCU\\|HKLM\\|dirifempty\\|files\\|filesandordirs\\)\\>")
109          'font-lock-constant-face)
110    (list 'iss-fontify-options '(1 'font-lock-variable-name-face) '(2 'font-lock-keyword-face))
111    )
112   "Expressions to highlight in iss mode.")
113
114 (defun iss-fontify-options (bound)
115   (message "iss-fontify-options %s" bound)
116   (when (re-search-forward "^[ \t]*\\([^=]+\\)[ \t]*\\(=\\)" bound t)
117     (match-data)))
118
119 (defvar iss-mode-map (make-sparse-keymap)
120   "Keymap used in iss-mode buffers.")
121
122 (easy-menu-define
123  iss-menu
124  iss-mode-map
125  "InnoSetup script menu"
126  (list
127   "ISS"
128   ["Compile"         (iss-compile)  t]
129   ["Run Installer"   (iss-run-installer)  t]
130   ["InnoSetup Help"  (iss-compiler-help)  t]
131   ))
132 (easy-menu-add iss-menu)
133
134 (defvar compilation-file-regexp-alist) ;; silence compiler, don't know the var.
135
136 ;;;###autoload
137 (defun iss-mode ()
138   "Major mode for editing InnoSetup script files. Upon startup iss-mode-hook is run."
139   (interactive)
140   (kill-all-local-variables)
141   (use-local-map iss-mode-map)
142   (setq major-mode 'iss-mode)
143   (setq mode-name "iss")
144   (set-syntax-table iss-mode-syntax-table)
145   (set (make-local-variable 'comment-start) ";")
146   (set (make-local-variable 'comment-end) "")
147   (set (make-local-variable 'comment-multi-line) nil)
148
149   (set (make-local-variable 'compilation-error-regexp-alist)
150         '(("\\(Error on line\\) \\([0-9]+\\):" nil 2)))
151   (set (make-local-variable 'compilation-file-regexp-alist)
152           '(("iscc \\(.*\\)$" 1)))
153
154   ;; Font lock support
155   (make-local-variable 'font-lock-defaults)
156   (setq font-lock-defaults '(iss-font-lock-keywords nil t))
157   (run-hooks 'iss-mode-hook))
158
159 (defun iss-compiler-help ()
160   "Start the online documentation for the InnoSetup compiler"
161   (interactive)
162   (let ((default-directory (or iss-compiler-path default-directory)))
163     (w32-shell-execute 1 "ISetup.chm")))
164
165 (defun iss-compile ()
166   "Compile the actual file with the InnoSetup compiler"
167   (interactive)
168   (let ((default-directory (or iss-compiler-path default-directory))
169         (compilation-process-setup-function 'iss-process-setup))
170     (compile (concat "iscc " (buffer-file-name)))))
171
172 (defun iss-process-setup ()
173   "Set up `compilation-exit-message-function' for `iss-compile'."
174   (set (make-local-variable 'compilation-exit-message-function)
175        'iss-compilation-exit-message-function))
176
177 (defun iss-compilation-exit-message-function (process-status exit-status msg)
178   (interactive)
179   (save-excursion
180     (let ((buffer-read-only nil))
181       (goto-char (point-min))
182       ;;scroll down one line, so that the compile command is parsed to:
183       ;; -> get the filename of the compiled file
184       (insert "\n")))
185   (cons msg exit-status))
186
187 (defun iss-find-option (option)
188   (let ((search-regexp
189          (concat option "[ \t]*=[ \t]*\\(.*\\)$")))
190     (save-excursion
191       (goto-char (point-min))
192       (when (search-forward-regexp search-regexp nil t)
193             (buffer-substring-no-properties (match-beginning 1) (match-end 1))))))
194
195 (defun iss-run-installer ()
196   (interactive)
197   (let ((executable
198          (concat (or (iss-find-option "outputdir") "Output\\")
199                  (or (iss-find-option "outputbasefilename") "setup")
200                  ".exe")))
201     (w32-shell-execute 1 executable)))
202
203 (provide 'iss-mode)
204
205 ;; arch-tag: b07b7119-d591-465e-927f-d0be0bcf7cab