123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- (defgroup asm nil
- "Mode for editing assembler code."
- :link '(custom-group-link :tag "Font Lock Faces group" font-lock-faces)
- :group 'languages)
- (defcustom asm-comment-char ?\
- "*The comment-start character assumed by Asm mode."
- :type 'character
- :group 'asm)
- (defvar asm-mode-syntax-table
- (let ((st (make-syntax-table)))
- (modify-syntax-entry ?\n "> b" st)
- (modify-syntax-entry ?/ ". 124b" st)
- (modify-syntax-entry ?* ". 23" st)
- st)
- "Syntax table used while in Asm mode.")
- (defvar asm-mode-abbrev-table nil
- "Abbrev table used while in Asm mode.")
- (define-abbrev-table 'asm-mode-abbrev-table ())
- (defvar asm-mode-map
- (let ((map (make-sparse-keymap)))
-
- (define-key map ":" 'asm-colon)
- (define-key map "\C-c;" 'comment-region)
- (define-key map "\C-j" 'newline-and-indent)
- (define-key map "\C-m" 'newline-and-indent)
- (define-key map [menu-bar asm-mode] (cons "Asm" (make-sparse-keymap)))
- (define-key map [menu-bar asm-mode comment-region]
- '(menu-item "Comment Region" comment-region
- :help "Comment or uncomment each line in the region"))
- (define-key map [menu-bar asm-mode newline-and-indent]
- '(menu-item "Insert Newline and Indent" newline-and-indent
- :help "Insert a newline, then indent according to major mode"))
- (define-key map [menu-bar asm-mode asm-colon]
- '(menu-item "Insert Colon" asm-colon
- :help "Insert a colon; if it follows a label, delete the label's indentation"))
- map)
- "Keymap for Asm mode.")
- (defconst asm-font-lock-keywords
- (append
- '(("^\\(\\(\\sw\\|\\s_\\)+\\)\\>:?[ \t]*\\(\\sw+\\(\\.\\sw+\\)*\\)?"
- (1 font-lock-function-name-face) (3 font-lock-keyword-face nil t))
-
- ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>:"
- 1 font-lock-function-name-face)
- ("^\\((\\sw+)\\)?\\s +\\(\\(\\.?\\sw\\|\\s_\\)+\\(\\.\\sw+\\)*\\)"
- 2 font-lock-keyword-face)
-
- ("^\\(\\.\\(\\sw\\|\\s_\\)+\\)\\>[^:]?"
- 1 font-lock-keyword-face)
-
- ("%\\sw+" . font-lock-variable-name-face))
- cpp-font-lock-keywords)
- "Additional expressions to highlight in Assembler mode.")
- (define-derived-mode asm-mode prog-mode "Assembler"
- "Major mode for editing typical assembler code.
- Features a private abbrev table and the following bindings:
- \\[asm-colon]\toutdent a preceding label, tab to next tab stop.
- \\[tab-to-tab-stop]\ttab to next tab stop.
- \\[asm-newline]\tnewline, then tab to next tab stop.
- \\[asm-comment]\tsmart placement of assembler comments.
- The character used for making comments is set by the variable
- `asm-comment-char' (which defaults to `?\\;').
- Alternatively, you may set this variable in `asm-mode-set-comment-hook',
- which is called near the beginning of mode initialization.
- Turning on Asm mode runs the hook `asm-mode-hook' at the end of initialization.
- Special commands:
- \\{asm-mode-map}"
- (setq local-abbrev-table asm-mode-abbrev-table)
- (set (make-local-variable 'font-lock-defaults) '(asm-font-lock-keywords))
- (set (make-local-variable 'indent-line-function) 'asm-indent-line)
-
- (set (make-local-variable 'tab-always-indent) nil)
- (run-hooks 'asm-mode-set-comment-hook)
-
-
- (use-local-map (nconc (make-sparse-keymap) asm-mode-map))
- (local-set-key (vector asm-comment-char) 'asm-comment)
- (set-syntax-table (make-syntax-table asm-mode-syntax-table))
- (modify-syntax-entry asm-comment-char "< b")
- (set (make-local-variable 'comment-start) (string asm-comment-char))
- (set (make-local-variable 'comment-add) 1)
- (set (make-local-variable 'comment-start-skip)
- "\\(?:\\s<+\\|/[/*]+\\)[ \t]*")
- (set (make-local-variable 'comment-end-skip) "[ \t]*\\(\\s>\\|\\*+/\\)")
- (set (make-local-variable 'comment-end) "")
- (setq fill-prefix "\t"))
- (defun asm-indent-line ()
- "Auto-indent the current line."
- (interactive)
- (let* ((savep (point))
- (indent (condition-case nil
- (save-excursion
- (forward-line 0)
- (skip-chars-forward " \t")
- (if (>= (point) savep) (setq savep nil))
- (max (asm-calculate-indentation) 0))
- (error 0))))
- (if savep
- (save-excursion (indent-line-to indent))
- (indent-line-to indent))))
- (defun asm-calculate-indentation ()
- (or
-
- (and (looking-at "\\(\\sw\\|\\s_\\)+:") 0)
-
- (and (looking-at "\\s<\\s<\\s<") 0)
-
- (and (looking-at "\\s<\\(\\S<\\|\\'\\)") comment-column)
-
- (or (car tab-stop-list) tab-width)))
- (defun asm-colon ()
- "Insert a colon; if it follows a label, delete the label's indentation."
- (interactive)
- (let ((labelp nil))
- (save-excursion
- (skip-syntax-backward "w_")
- (skip-syntax-backward " ")
- (if (setq labelp (bolp)) (delete-horizontal-space)))
- (call-interactively 'self-insert-command)
- (when labelp
- (delete-horizontal-space)
- (tab-to-tab-stop))))
- (defalias 'asm-newline 'newline-and-indent)
- (defun asm-comment ()
- "Convert an empty comment to a `larger' kind, or start a new one.
- These are the known comment classes:
- 1 -- comment to the right of the code (at the comment-column)
- 2 -- comment on its own line, indented like code
- 3 -- comment on its own line, beginning at the left-most column.
- Suggested usage: while writing your code, trigger asm-comment
- repeatedly until you are satisfied with the kind of comment."
- (interactive)
- (-normalize-vars)
- (let (comempty comment)
- (save-excursion
- (beginning-of-line)
- (with-no-warnings
- (setq comment (-search-forward (line-end-position) t)))
- (setq comempty (looking-at "[ \t]*$")))
- (cond
-
-
- ((save-excursion (beginning-of-line) (looking-at "^[ \t]*$"))
- (indent-according-to-mode)
- (insert asm-comment-char asm-comment-char ?\ ))
-
-
- ((or (null comment) (< (point) comment))
- (indent-for-comment))
-
- ((or (not comempty) (save-excursion (goto-char comment) (bolp)))
- (insert asm-comment-char))
-
- ((save-excursion (goto-char comment) (skip-chars-backward " \t") (bolp))
- (goto-char comment)
- (insert asm-comment-char)
- (indent-for-comment))
-
- (t
- (goto-char comment)
- (skip-chars-backward " \t")
- (delete-region (point) (line-end-position))
- (beginning-of-line) (insert "\n") (backward-char)
- (asm-comment)))))
- (provide 'asm-mode)
|