1 ;;; novaboot-mode.el --- Major mode for novaboot scripts
3 ;; Copyright (C) 2014 Michal Sojka
5 ;; Author: Michal Sojka <sojkam1@fel.cvut.cz>
6 ;; Keywords: languages, tools, files
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
28 (defvar novaboot-mode-syntax-table
29 (let ((table (make-syntax-table))
38 (modify-syntax-entry (pop list) (pop list) table))
41 (defvar novaboot-mode-font-lock-keywords
42 `(("^#.*" . font-lock-comment-face)
43 ("^load\\>.*\\(<<EOF\\)\n\\(\\(?:.*\n\\)*?\\)\\(EOF\\)\n"
44 (1 font-lock-preprocessor-face)
45 (2 font-lock-string-face)
46 (3 font-lock-preprocessor-face))
47 ("^\\(load\\)\\s-+\\([^ \n\t]*\\)"
48 (1 font-lock-keyword-face)
49 (2 font-lock-function-name-face))
50 ("^load\\>.*?< \\(.*\\)"
51 (1 font-lock-string-face))
52 ("^run\\>" . font-lock-keyword-face)
53 ("^\\([A-Z_]+\\)=" (1 font-lock-variable-name-face))
56 (defun novaboot-font-lock-extend-region ()
58 (goto-char font-lock-beg)
59 (when (re-search-forward "^EOF\\>" font-lock-end t)
60 (re-search-backward "<<EOF$" nil t)
61 (when (< (point) font-lock-beg)
62 (setq changed t font-lock-beg (point))))
63 (goto-char font-lock-end)
64 (when (re-search-backward "<<EOF$" font-lock-beg t)
65 (re-search-forward "^EOF\\>" nil t)
66 (when (> (point) font-lock-end)
67 (setq changed t font-lock-end (point))))
70 (defun novaboot-post-self-insert ()
71 (when (looking-back "<<$" (- (point) 2))
76 (define-derived-mode novaboot-mode prog-mode "Novaboot"
77 :syntax-table novaboot-mode-syntax-table
78 (set (make-local-variable 'font-lock-defaults)
79 '(novaboot-mode-font-lock-keywords t))
80 (set (make-local-variable 'font-lock-verbose) t)
81 (setq font-lock-multiline t)
82 (add-hook 'font-lock-extend-region-functions 'novaboot-font-lock-extend-region)
83 (add-hook 'post-self-insert-hook 'novaboot-post-self-insert))
87 (add-to-list 'auto-mode-alist '("/\\.novaboot\\'" . perl-mode))
88 (add-to-list 'interpreter-mode-alist '("novaboot" . novaboot-mode)))
91 (provide 'novaboot-mode)
92 ;;; novaboot-mode.el ends here