1 ;;; novaboot-mode.el --- Major mode for novaboot scripts
3 ;; Copyright (C) 2014, 2015, 2016 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 (setq novaboot-mode-font-lock-keywords
43 `(("^#.*" . font-lock-comment-face)
44 ("^\\(?:load\\|copy\\|chld\\)\\>.*\\(<<EOF\\)\n\\(\\(?:.*\n\\)*?\\)\\(EOF\\)\n"
45 (1 font-lock-preprocessor-face)
46 (2 font-lock-string-face)
47 (3 font-lock-preprocessor-face))
48 ("^\\(load\\|copy\\|chld\\)\\s-+\\([^ \n\t]*\\)"
49 (1 font-lock-keyword-face)
50 (2 font-lock-function-name-face))
51 ("^\\(?:load\\|copy\\|chld\\)\\>.*?< \\(.*\\)"
52 (1 font-lock-string-face))
53 ("^\\(run\\|uboot\\)\\>" . font-lock-keyword-face)
54 ("^\\([A-Z_]+\\)=" (1 font-lock-variable-name-face))
55 ("\\$\\(NB_\\(MYIP\\|PREFIX\\)\\)\\>" (1 font-lock-variable-name-face))
58 (defun novaboot-font-lock-extend-region ()
60 (goto-char font-lock-beg)
61 (when (re-search-forward "^EOF\\>" font-lock-end t)
62 (re-search-backward "<<EOF$" nil t)
63 (when (< (point) font-lock-beg)
64 (setq changed t font-lock-beg (point))))
65 (goto-char font-lock-end)
66 (when (re-search-backward "<<EOF$" font-lock-beg t)
67 (re-search-forward "^EOF\\>" nil t)
68 (when (> (point) font-lock-end)
69 (setq changed t font-lock-end (point))))
72 (defun novaboot-post-self-insert ()
73 (when (looking-back "<<$" (- (point) 2))
78 (define-derived-mode novaboot-mode prog-mode "Novaboot"
79 :syntax-table novaboot-mode-syntax-table
80 (set (make-local-variable 'font-lock-defaults)
81 '(novaboot-mode-font-lock-keywords t))
82 (set (make-local-variable 'font-lock-verbose) t)
83 (set (make-local-variable 'comment-start) "# ")
84 (set (make-local-variable 'comment-end) "")
85 (setq font-lock-multiline t)
86 (add-hook 'font-lock-extend-region-functions 'novaboot-font-lock-extend-region)
87 (add-hook 'post-self-insert-hook 'novaboot-post-self-insert))
91 (add-to-list 'auto-mode-alist '("/\\.novaboot\\'" . perl-mode))
92 (add-to-list 'interpreter-mode-alist '("novaboot" . novaboot-mode)))
95 (provide 'novaboot-mode)
96 ;;; novaboot-mode.el ends here