Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Emacs Lisp syntax highlighting

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?

like image 643
Chris Lutz Avatar asked May 15 '09 04:05

Chris Lutz


People also ask

How to enable syntax highlighting in Emacs?

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.

Does Emacs have syntax highlighting?

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.

Is Emacs Lisp A Common Lisp?

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.


4 Answers

You're looking in the wrong place. Look at "font-lock-mode".

like image 91
Charlie Martin Avatar answered Oct 11 '22 09:10

Charlie Martin


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.

like image 41
Trey Jackson Avatar answered Oct 11 '22 08:10

Trey Jackson


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.

like image 29
danielpoe Avatar answered Oct 11 '22 09:10

danielpoe


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.

like image 29
Alex B Avatar answered Oct 11 '22 10:10

Alex B