;;; jil-mode.el --- mode for editing AutoSys JIL scripts ;; Author: Erik Gillespie ;; Keywords: tools, languages ;;; Commentary: ;; This minor mode is based on text mode. It defines a private abbrev table ;; that can be used to save abbrevs for JIL mnemonics. It binds just ;; five keys: ;; ;; TAB tab to next tab stop ;; : outdent preceding label, tab to tab stop ;; C-j, C-m newline and tab to tab stop ;; comment char place or move comment ;; jil-comment-char specifies which character this is; ;; you can use a different character in different ;; JIL mode buffers. ;; ;; This mode runs the following hooks: ;; 1) A jil-mode-set-comment-hook before the part of the initialization ;; depending on asm-comment-char, and ;; 2) an jil-mode-hook at the end of initialization. ;;; Code: (defgroup jil nil "Mode for editing AutoSys JIL scripts." :group 'languages) (defcustom jil-comment-char ?# "*The comment-start character assumed by JIL mode." :type 'character :group 'jil) (defvar jil-param-column 20 "Column to indent to after a label.") (defvar jil-mode-syntax-table nil "Syntax table used while in JIL mode.") (defvar jil-mode-abbrev-table nil "Abbrev table used while in JIL mode.") (define-abbrev-table 'jil-mode-abbrev-table ()) (defvar jil-mode-map nil "Keymap for JIL mode.") (if jil-mode-map nil (setq jil-mode-map (make-sparse-keymap)) (define-key jil-mode-map ":" 'jil-colon) (define-key jil-mode-map "\C-i" 'jil-tab-to-tab-stop)) (defconst jil-font-lock-keywords '(("^\\(\\(\\sw\\|\\s_\\)+\\)\\>:" (1 font-lock-constant-face)) ("<\\([^>\t ]+\\)\\([\t ]*\\([^=>]+\\)=\\([^>\t ]+\\)\\)*>" (1 font-lock-builtin-face) (3 font-lock-type-face nil t) (4 font-lock-variable-name-face nil t)) ("\\<\\(SUCCESS\\|FAIL\\|AND\\|EXITCODE\\)\\>" (1 font-lock-function-name-face))) "Additional expressions to highlight in Assembler mode.") (defvar jil-code-level-empty-comment-pattern nil) (defvar jil-flush-left-empty-comment-pattern nil) (defvar jil-inline-empty-comment-pattern nil) ;;;###autoload (defun jil-mode () "Major mode for editing AutoSys JIL scripts. Implements the following customizable variables: jil-param-column\tColumn indented to after inserting a label. The character used for making comments is set by the variable `jil-comment-char' (which defaults to `?#'). Alternatively, you may set this variable in `jil-mode-set-comment-hook', which is called near the beginning of mode initialization. Features a private abbrev table and the following bindings: \\[jil-colon]\toutdent a preceding label, tab to next tab stop. \\[jil-tab-to-tab-stop]\ttab to next tab stop. Turning on JIL mode runs the hook `jil-mode-hook' at the end of initialization. Special commands: \\{jil-mode-map} " (interactive) (kill-all-local-variables) (setq mode-name "JIL") (setq major-mode 'jil-mode) (setq local-abbrev-table jil-mode-abbrev-table) (make-local-variable 'font-lock-defaults) (setq font-lock-defaults '(jil-font-lock-keywords)) (make-local-variable 'jil-mode-syntax-table) (setq jil-mode-syntax-table (make-syntax-table)) (set-syntax-table jil-mode-syntax-table) (run-hooks 'jil-mode-set-comment-hook) ;; Add the custom keymap (use-local-map (nconc (make-sparse-keymap) jil-mode-map)) ; (local-set-key (vector jil-comment-char) 'jil-comment) ;; Make our own local child of jil-mode-map ;; so we can define our own comment character. (modify-syntax-entry jil-comment-char "< b" jil-mode-syntax-table) (modify-syntax-entry ?\n "> b" jil-mode-syntax-table) (modify-syntax-entry ?/ ". 14" jil-mode-syntax-table) (modify-syntax-entry ?* ". 23" jil-mode-syntax-table) (let ((cs (regexp-quote (char-to-string jil-comment-char)))) (make-local-variable 'comment-start) (setq comment-start (concat (char-to-string jil-comment-char) " ")) (make-local-variable 'comment-start-skip) (setq comment-start-skip (concat cs "+[ \t]*")) (setq jil-inline-empty-comment-pattern (concat "^.+" cs "+ *$")) (setq jil-code-level-empty-comment-pattern (concat "^[\t ]+" cs cs " *$")) (setq jil-flush-left-empty-comment-pattern (concat "^" cs cs cs " *$")) ) (make-local-variable 'comment-end) (setq comment-end "") (setq fill-prefix "\t") (run-hooks 'jil-mode-hook)) (defun jil-colon () "Insert a colon; if it follows a label, delete the label's indentation." (interactive) (save-excursion (beginning-of-line) (if (looking-at "[ \t]+\\(\\sw\\|\\s_\\)+$") (delete-horizontal-space))) (insert ":") (jil-tab-to-tab-stop)) (defun jil-tab-to-tab-stop () "Indents to parameter column or inserts tab if already beyond that column." (interactive) (while (< (current-column) jil-param-column) (insert " ")) (if (> (current-column) jil-param-column) (tab-to-tab-stop))) (provide 'jil-mode) ;;; jil-mode.el ends here