Skip to content

Commit

Permalink
adding nasm-mode, moving ESS init up so we can override .s files as n…
Browse files Browse the repository at this point in the history
…asm-mode
  • Loading branch information
Steve Jenson committed Jan 18, 2013
1 parent 9a202f6 commit 031691d
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 6 deletions.
16 changes: 10 additions & 6 deletions customizations/modes.el
Expand Up @@ -9,6 +9,14 @@
(setq haskell-program-name "ghci") (setq haskell-program-name "ghci")
(require 'inf-haskell) (require 'inf-haskell)


;; this trollish wizardry is required for ESS, which I use
;; to integrate Emacs with R.

(load "~/.emacs.d/utilities/ess-12.09/lisp/ess-site")
(require 'ess-site)
(ess-toggle-underscore nil)


;; Put backup files (ie foo~) in one place too. (The backup-directory-alist ;; Put backup files (ie foo~) in one place too. (The backup-directory-alist
;; list contains regexp=>directory mappings; filenames matching a regexp are ;; list contains regexp=>directory mappings; filenames matching a regexp are
;; backed up in the corresponding directory. Emacs will mkdir it if necessary.) ;; backed up in the corresponding directory. Emacs will mkdir it if necessary.)
Expand Down Expand Up @@ -115,6 +123,8 @@


(setq my-modes (setq my-modes
'(("\\.bashrc" . sh-mode) '(("\\.bashrc" . sh-mode)
("\\.s$" . nasm-mode) ;; TODO: support other assemblers
("\\.asm$" . nasm-mode)
("\\.v" . coq-mode) ("\\.v" . coq-mode)
("\\.js$" . js-mode) ("\\.js$" . js-mode)
("\\.json$" . js-mode) ("\\.json$" . js-mode)
Expand Down Expand Up @@ -182,9 +192,3 @@
(autoload 'run-coq-other-frame "coq-inferior" (autoload 'run-coq-other-frame "coq-inferior"
"Run an inferior Coq process in a new frame." t) "Run an inferior Coq process in a new frame." t)


;; this trollish wizardry is required for ESS, which I use
;; to integrate Emacs with R.

(load "~/.emacs.d/utilities/ess-12.09/lisp/ess-site")
(require 'ess-site)
(ess-toggle-underscore nil)
1 change: 1 addition & 0 deletions init.el
Expand Up @@ -41,6 +41,7 @@
(vendor 'markdown-mode) (vendor 'markdown-mode)
(vendor 'multi-web-mode) (vendor 'multi-web-mode)
(vendor 'magit) (vendor 'magit)
(vendor 'nasm-mode)
(vendor 'nav) (vendor 'nav)
(vendor 'nxml-mode) (vendor 'nxml-mode)
(vendor 'piglatin-mode) (vendor 'piglatin-mode)
Expand Down
76 changes: 76 additions & 0 deletions vendor/nasm-mode/nasm-mode.el
@@ -0,0 +1,76 @@
;; Major mode for nasm assembly
;; Made by Matthieu Hauglustaine

;; Put the following code in your .emacs to use nasm-mode
;;
;; (autoload 'nasm-mode "~/.emacs.d/nasm-mode.el" "" t)
;; (add-to-list 'auto-mode-alist '("\\.\\(asm\\|s\\)$" . nasm-mode))

;; To set your own indentation level to LEVEL:
;;
;; (add-hook 'nasm-mode-hook
;; (lambda () (setq-default nasm-basic-offset LEVEL)))

(defvar nasm-mode-hook nil)
(defcustom nasm-basic-offset 8 "Indentation level.")

;; Use make-sparse-keymap if keymap have very few entries.
(defvar nasm-mode-map
(let ((kmap (make-keymap)))
(define-key kmap (kbd "C-j") 'newline-and-indent)
kmap)
"Keymap for nasm major mode")

(defconst nasm-font-lock-keywords
(list
;; Labels
'("^[ \t]*[a-zA-Z0-9_.?][a-zA-Z0-9_$#@~.?]*:" . font-lock-type-face)
;; Directive operands and registers
'("\\<\\(\\$\\$?\\|%[0-9]\\|\\.\\(?:bss\\|data\\|text\\)\\|a\\(?:16\\|32\\|[hlx]\\)\\|b\\(?:yte\\|[hlpx]\\)\\|c\\(?:r[0234]\\|[hlsx]\\)\\|d\\(?:r[0-367]\\|word\\|[hilsx]\\)\\|e\\(?:ax\\|b[px]\\|cx\\|d[ix]\\|s[ip]?\\)\\|f\\(?:ar\\|lat\\|s\\)\\|gs\\|large\\|mm[0-7]\\|n\\(?:ear\\|osplit\\)\\|o\\(?:16\\|32\\)\\|s\\(?:eq\\|mall\\|t[0-7]\\|[ipst]\\)\\|tr[3-7]\\|w\\(?:ord\\|rt\\)\\|xmm[0-7]\\)\\>" . font-lock-variable-name-face)
;; Instructions
'("\\<\\(a\\(?:a[adms]\\|d\\(?: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\\(?:npck\\(?:h\\(?:bw\\|dq\\|qdq\\|wd\\)\\|l\\(?:bw\\|dq\\|qdq\\|wd\\)\\)\\|sh\\(?:a[dw]\\|f[dw]\\|[adfw]\\)?\\)\\|xor\\)\\|r\\(?:c\\(?:p\\(?:[ps]s\\)\\|[lr]\\)\\|d\\(?:msr\\|pmc\\|shr\\|tsc\\)\\|e\\(?:p\\(?:n[ez]\\|[ez]\\)\\|t[fn]\\|[pt]\\)\\|o[lr]\\|s\\(?:dc\\|ldt\\|m\\|\\(?:qrt[ps]\\|t\\)s\\)\\)\\|s\\(?:a\\(?:hf\\|lc\\|[lr]\\)\\|bb\\|cas[bdw]?\\|et\\(?:ae\\|be\\|ge\\|le\\|n\\(?:[abgl]e\\|[abceglopsz]\\)\\|p[eo]\\|[abceglopsz]\\)\\|fence\\|gdt\\|h\\(?:ld\\|rd\\|ufp[ds]\\|[lr]\\)\\|idt\\|ldt\\|m\\(?:i\\(?:nt\\(?:old\\)?\\)?\\|sw\\)\\|qrt\\(?:p[ds]\\|s[ds]\\)\\|t\\(?:mxcsr\\|os[bdw]?\\|[cdir]\\)\\|ub\\(?:p[ds]\\|s[ds]\\)?\\|v\\(?:dc\\|ldt\\|ts\\)\\|ys\\(?:call\\|e\\(?:nter\\|xit\\)\\|ret\\)\\)\\|test\\|u\\(?:comis[ds]\\|d[012]\\|mov\\|npck\\(?:hp[ds]\\|lp[ds]\\)\\)\\|ver[rw]\\|w\\(?:ait\\|binvd\\|r\\(?:\\(?:ms\\|sh\\)r\\)\\)\\|x\\(?:add\\|bts\\|chg\\|latb?\\|or\\(?:p[ds]\\)?\\)\\)\\>" . font-lock-keyword-face)
;; Directives
'("\\<\\(%\\(?:a\\(?:rg\\|ssign\\)\\|define\\|e\\(?:l\\(?:if\\(?:ctk\\|def\\|id\\(?:ni?\\)?\\|macro\\|n\\(?:ctk\\|def\\|id\\(?:ni?\\)?\\|macro\\|num\\|str\\|um\\)\\|str\\)?\\|se\\)\\|nd\\(?:if\\|macro\\|rep\\)\\|rror\\|xitrep\\)\\|i\\(?:assign\\|define\\|f\\(?:ctk\\|def\\|id\\(?:ni?\\)?\\|macro\\|n\\(?:ctk\\|def\\|id\\(?:ni?\\)?\\|macro\\|num\\|str\\|um\\)\\|str\\)?\\|macro\\|nclude\\)\\|l\\(?:ine\\|ocal\\)\\|macro\\|p\\(?:op\\|ush\\)\\|r\\(?:epl?\\|otate\\)\\|s\\(?:t\\(?:acksize\\|rlen\\)\\|ubstr\\)\\|undef\\|x\\(?:i?define\\)\\)\\|\\.nolist\\|a\\(?:bsolute\\|lignb?\\|t\\)\\|bits\\|c\\(?:ommon\\|pu\\)\\|d[bdqtw]\\|e\\(?:n\\(?:d\\(?:\\(?:pro\\|stru\\)c\\)\\|try\\)\\|qu\\|x\\(?:port\\|tern\\)\\)\\|g\\(?:lobal\\|roup\\)\\|i\\(?:end\\|mport\\|ncbin\\|struc\\)\\|org\\|proc\\|res[bdqtw]\\|s\\(?:ection\\|truct\\)\\|times\\|use\\(?:16\\|32\\|64\\)\\)\\>" . font-lock-preprocessor-face)
)
"Highlight the registers")

(defvar nasm-mode-syntax-table
(let ((stable (make-syntax-table)))
(modify-syntax-entry ?_ "w" stable)
(modify-syntax-entry ?. "w" stable)
(modify-syntax-entry ?\; "<" stable) ; Comment starter
(modify-syntax-entry ?\n ">" stable) ; Comment ender
(modify-syntax-entry ?\" "\"" stable) ; String quote
(modify-syntax-entry ?\' "\"" stable) ; String quote
stable)
"Syntax table for nasm-mode")

(defun nasm-set-offset offset
(setq nasm-basic-offset offset))

(defun nasm-indent-line ()
"Indent current line as nasm assembly code."
(interactive)
(beginning-of-line)
(if (or (looking-at "^[ \t]*\\(%\\(?:a\\(?:rg\\|ssign\\)\\|define\\|e\\(?:l\\(?:if\\(?:ctk\\|def\\|id\\(?:ni?\\)?\\|macro\\|n\\(?:ctk\\|def\\|id\\(?:ni?\\)?\\|macro\\|num\\|str\\|um\\)\\|str\\)?\\|se\\)\\|nd\\(?:if\\|macro\\|rep\\)\\|rror\\|xitrep\\)\\|i\\(?:assign\\|define\\|f\\(?:ctk\\|def\\|id\\(?:ni?\\)?\\|macro\\|n\\(?:ctk\\|def\\|id\\(?:ni?\\)?\\|macro\\|num\\|str\\|um\\)\\|str\\)?\\|macro\\|nclude\\)\\|l\\(?:ine\\|ocal\\)\\|macro\\|p\\(?:op\\|ush\\)\\|r\\(?:epl?\\|otate\\)\\|s\\(?:t\\(?:acksize\\|rlen\\)\\|ubstr\\)\\|undef\\|x\\(?:i?define\\)\\)\\|\\.nolist\\|a\\(?:bsolute\\|lignb?\\|t\\)\\|bits\\|c\\(?:ommon\\|pu\\)\\|d[bdqtw]\\|e\\(?:n\\(?:d\\(?:\\(?:pro\\|stru\\)c\\)\\|try\\)\\|qu\\|x\\(?:port\\|tern\\)\\)\\|g\\(?:lobal\\|roup\\)\\|i\\(?:end\\|mport\\|ncbin\\|struc\\)\\|org\\|proc\\|res[bdqtw]\\|s\\(?:ection\\|truct\\)\\|times\\|use\\(?:16\\|32\\|64\\)\\)")
(looking-at "^[ \t]*[a-zA-Z0-9_.?][a-zA-Z0-9_$#@~.?]*:")
(looking-at "^[ \t]*;"))
(indent-line-to 0) ; line is a directive, a label or a comment
(indent-line-to nasm-basic-offset)))

(defun nasm-mode ()
"Major mode for editing nasm assembler source code."
(interactive)
(kill-all-local-variables)

(set-syntax-table nasm-mode-syntax-table)
(use-local-map nasm-mode-map)
(set (make-local-variable 'font-lock-defaults) '(nasm-font-lock-keywords))
(set (make-local-variable 'indent-line-function) 'nasm-indent-line)

(setq major-mode 'nasm-mode)
(setq mode-name "Nasm")
(setq comment-start ";")
(run-hooks 'nasm-mode-hook))

(provide 'nasm-mode)

0 comments on commit 031691d

Please sign in to comment.