Skip to content

Instantly share code, notes, and snippets.

Created January 16, 2013 10:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4546274 to your computer and use it in GitHub Desktop.
Save anonymous/4546274 to your computer and use it in GitHub Desktop.
20 minute hack to highlight labels in assembler listings. Very limited, only suitable for the output of gcc -S or similar.
(defun define-label-colors (colors)
(loop for color in colors
for i from 0
for face-symbol = (intern (format "rotate-%d" i))
do
(custom-declare-face face-symbol
(list (list t (list :background color))) "")
(set face-symbol face-symbol)))
(defvar asm-label-colors
'("#0000cd"
"#ff4500"
"#528b8b"
"#006400"
"#8a2be2"
"#191970"
"#cd3700"
"#698b22"
"#104e8b"
"#8b1a1a"
"#6b8e23"
"#27408b"
"#5d478b"
"#2e8b57"
"#8b0000"
"#4682b4"
"#556b2f"
"#4169e1"
"#cd9b1d"
"#2f4f4f"
"#008b8b"
"#00008b"))
(defvar asm-label-font-lock-list
(let ((num-colors (length asm-label-colors)))
(loop for i from 0 below num-colors collect
(list
(format "\\.L[0-9]*\\(%s\\)\\b"
(mapconcat 'number-to-string
(loop for j from i below 100 by num-colors
collect j)
"\\|"))
0
(intern (format "rotate-%d" i)) t))))
(eval-after-load "asm-mode"
'(progn
(define-label-colors asm-label-colors)
(define-key asm-mode-map (kbd "C-c l") 'toggle-asm-label-colors)))
(defun asm-label-colors-on ()
(interactive)
(font-lock-add-keywords nil asm-label-font-lock-list)
(font-lock-fontify-buffer))
(defun asm-label-colors-off ()
(interactive)
(font-lock-remove-keywords nil asm-label-font-lock-list)
(font-lock-fontify-buffer))
(defvar asm-label-colors-enabled nil)
(defun toggle-asm-label-colors ()
(interactive)
(if asm-label-colors-enabled
(asm-label-colors-off)
(asm-label-colors-on))
(setq asm-label-colors-enabled (not asm-label-colors-enabled)))
(provide 'color-asm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment