I am trying to write a very basic emacs major mode to edit assembler source files (for a specific microcontroller). I used https://www.emacswiki.org/emacs-test/ModeTutorial as a starting point. It works but I would like to change two things but can't find a solution.
And yes, I am keen to develop a more thorough understanding of eLisp with time, but I also try to quickly hack my way to a working mode definition because I need it now (without really understanding the intricacies - I know, RTFM...).
Anyway, I hope to get an answer to two questions:
1) While syntax highlighting works, I don't get it to be case-insensitive. I tried adding (setq font-lock-keywords-case-fold-search t)
to the function below, but it does not seem to have the desired effect.
(defun xasm-mode ()
(interactive)
(kill-all-local-variables)
(use-local-map xasm-mode-map)
(set-syntax-table xasm-mode-syntax-table)
;; set up font-lock
(set (make-local-variable 'font-lock-defaults) '(xasm-font-lock-keywords))
(setq font-lock-keywords-case-fold-search t)
(setq major-mode 'xasm-mode)
(setq mode-name "XASM")
(run-hooks 'xasm-mode-hook))
2) The second question for sure demonstrates my ignorance... Basically, in an expression with the structure below, I'd like to substitute the "regexp" literal (which works) by a value that is in a variable (here: x, with x being (correctly) computed by regexp-opt)... But I don't know how to insert the value of x here :-(
(setq x 'xyz)
(defconst v2
(list
'( "regexp" . foo)
))
Thanks for your hints.
Check the documentation with C-h v font-lock-defaults RET
:
... Defaults should be of the form:
(KEYWORDS [KEYWORDS-ONLY [CASE-FOLD [SYNTAX-ALIST ...]]]) ...
Which tells you that you can set the "case-fold" behavior right there:
(set (make-local-variable 'font-lock-defaults)
'(xasm-font-lock-keywords nil t))
Also, do yourself a favor and use define-derived-mode (and update whichever doc you found that pointed you to defun+interactive+setqmode-name+...
so it refers to define-derived-mode
as well).