I want to write a syntax highlighting extension for Emacs, but I Googling of variations on "emacs syntax highlight tutorial" have all failed. How do I go about learning how to write an Emacs highlighter? What good resources are there for learning how to do such things?
font-lock-mode is the standard way to have Emacs perform syntax highlighting in the current buffer. It is enabled by default. With font-lock-mode turned on, different types of text will appear in different colors.
In Emacs, syntax highlighting is performed using the module font-lock . It highlights a buffer in two phases: The syntactic phase, where comments and strings are highlighted. The keyword phase, where everything else is highlighted.
Gnu emacs is written almost entirely in Common Lisp! Unfortunately, this version of Common Lisp is so incomplete that it won't be sufficient for programming in our class. Instead, you can run and use lisp within emacs.
You're looking in the wrong place. Look at "font-lock-mode".
There's a related question, on how to define a major mode with syntax highlighting using 'define-generic-mode
. The question focuses on figuring out how to get the syntax highlighting working.
unfortunately you were searching for the wrong terms, "syntax highlighting" is not emacs vocabulary :). You should have searched for something like "write emacs mode".
There was already a question for this: "How to write an emacs mode for a new language" with some good pointers.
If you are interested in writing your own highlighting, another question covered this and may be of value to you. It included this code snippet:
(defun django-highlight-comments ()
(interactive "p")
(highlight-regexp "{%.*?%}" 'hi-orange))
(add-hook 'html-mode-hook 'django-highlight-comments)
Code courtesy of Ashutosh Mehra's answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With