Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

adding nasm-mode, moving ESS init up so we can override .s files as n…

…asm-mode
  • Loading branch information...
commit 031691d7f772387e7b79a2ca3d9ea90ad5018bbc 1 parent 9a202f6
Steve Jenson authored January 18, 2013
16  customizations/modes.el
@@ -9,6 +9,14 @@
9 9
 (setq haskell-program-name "ghci")
10 10
 (require 'inf-haskell)
11 11
 
  12
+;; this trollish wizardry is required for ESS, which I use
  13
+;; to integrate Emacs with R.
  14
+
  15
+(load "~/.emacs.d/utilities/ess-12.09/lisp/ess-site")
  16
+(require 'ess-site)
  17
+(ess-toggle-underscore nil)
  18
+
  19
+
12 20
 ;; Put backup files (ie foo~) in one place too. (The backup-directory-alist
13 21
 ;; list contains regexp=>directory mappings; filenames matching a regexp are
14 22
 ;; backed up in the corresponding directory. Emacs will mkdir it if necessary.)
@@ -115,6 +123,8 @@
115 123
 
116 124
 (setq my-modes
117 125
   '(("\\.bashrc"  . sh-mode)
  126
+    ("\\.s$"      . nasm-mode) ;; TODO: support other assemblers
  127
+    ("\\.asm$"    . nasm-mode)
118 128
     ("\\.v"       . coq-mode)
119 129
     ("\\.js$"     . js-mode)
120 130
     ("\\.json$"   . js-mode)
@@ -182,9 +192,3 @@
182 192
 (autoload 'run-coq-other-frame "coq-inferior"
183 193
   "Run an inferior Coq process in a new frame." t)
184 194
 
185  
-;; this trollish wizardry is required for ESS, which I use
186  
-;; to integrate Emacs with R.
187  
-
188  
-(load "~/.emacs.d/utilities/ess-12.09/lisp/ess-site")
189  
-(require 'ess-site)
190  
-(ess-toggle-underscore nil)
1  init.el
@@ -41,6 +41,7 @@
41 41
 (vendor 'markdown-mode)
42 42
 (vendor 'multi-web-mode)
43 43
 (vendor 'magit)
  44
+(vendor 'nasm-mode)
44 45
 (vendor 'nav)
45 46
 (vendor 'nxml-mode)
46 47
 (vendor 'piglatin-mode)
76  vendor/nasm-mode/nasm-mode.el
... ...
@@ -0,0 +1,76 @@
  1
+;; Major mode for nasm assembly
  2
+;; Made by Matthieu Hauglustaine
  3
+
  4
+;; Put the following code in your .emacs to use nasm-mode
  5
+;;
  6
+;; (autoload 'nasm-mode "~/.emacs.d/nasm-mode.el" "" t)
  7
+;; (add-to-list 'auto-mode-alist '("\\.\\(asm\\|s\\)$" . nasm-mode))
  8
+
  9
+;; To set your own indentation level to LEVEL:
  10
+;;
  11
+;; (add-hook 'nasm-mode-hook
  12
+;;           (lambda () (setq-default nasm-basic-offset LEVEL)))
  13
+
  14
+(defvar nasm-mode-hook nil)
  15
+(defcustom nasm-basic-offset 8 "Indentation level.")
  16
+
  17
+;; Use make-sparse-keymap if keymap have very few entries.
  18
+(defvar nasm-mode-map
  19
+  (let ((kmap (make-keymap)))
  20
+    (define-key kmap (kbd "C-j") 'newline-and-indent)
  21
+    kmap)
  22
+  "Keymap for nasm major mode")
  23
+
  24
+(defconst nasm-font-lock-keywords
  25
+  (list
  26
+   ;; Labels
  27
+   '("^[ \t]*[a-zA-Z0-9_.?][a-zA-Z0-9_$#@~.?]*:" . font-lock-type-face)
  28
+   ;; Directive operands and registers
  29
+   '("\\<\\(\\$\\$?\\|%[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)
  30
+   ;; Instructions
  31
+   '("\\<\\(a\\(?:a[adms]\\|d\\(?:d\\(?:p[ds]\\|s[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: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)
  32
+   ;; Directives
  33
+   '("\\<\\(%\\(?: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)
  34
+   )
  35
+  "Highlight the registers")
  36
+
  37
+(defvar nasm-mode-syntax-table
  38
+  (let ((stable (make-syntax-table)))
  39
+    (modify-syntax-entry ?_ "w" stable)
  40
+    (modify-syntax-entry ?. "w" stable)
  41
+    (modify-syntax-entry ?\; "<" stable)  ; Comment starter
  42
+    (modify-syntax-entry ?\n ">" stable)  ; Comment ender
  43
+    (modify-syntax-entry ?\" "\"" stable) ; String quote
  44
+    (modify-syntax-entry ?\' "\"" stable) ; String quote
  45
+    stable)
  46
+  "Syntax table for nasm-mode")
  47
+
  48
+(defun nasm-set-offset offset
  49
+  (setq nasm-basic-offset offset))
  50
+
  51
+(defun nasm-indent-line ()
  52
+  "Indent current line as nasm assembly code."
  53
+  (interactive)
  54
+  (beginning-of-line)
  55
+  (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\\)\\)")
  56
+	  (looking-at "^[ \t]*[a-zA-Z0-9_.?][a-zA-Z0-9_$#@~.?]*:")
  57
+	  (looking-at "^[ \t]*;"))
  58
+      (indent-line-to 0)   ; line is a directive, a label or a comment
  59
+    (indent-line-to nasm-basic-offset)))
  60
+
  61
+(defun nasm-mode ()
  62
+  "Major mode for editing nasm assembler source code."
  63
+  (interactive)
  64
+  (kill-all-local-variables)
  65
+
  66
+  (set-syntax-table nasm-mode-syntax-table)
  67
+  (use-local-map nasm-mode-map)
  68
+  (set (make-local-variable 'font-lock-defaults) '(nasm-font-lock-keywords))
  69
+  (set (make-local-variable 'indent-line-function) 'nasm-indent-line)
  70
+
  71
+  (setq major-mode 'nasm-mode)
  72
+  (setq mode-name "Nasm")
  73
+  (setq comment-start ";")
  74
+  (run-hooks 'nasm-mode-hook))
  75
+
  76
+(provide 'nasm-mode)

0 notes on commit 031691d

Please sign in to comment.
Something went wrong with that request. Please try again.