Jump to content
  • Advertisement
Sign in to follow this  
  • entries
  • comments
  • views

Emacs font locking: highlighting comment lines

Sign in to follow this  


Posted from http://jlongster.com/blog/2009/06/9/font-locking-highlighting-code-section-headers/.


Emacs font locking: highlighting comment lines

June 09, 2009

I recently tried an package called Quack which adds a bunch of commands for writing and running Scheme code in Emacs. Although I don't use it anymore, one thing I really like was how it highlighted comment lines with a depth of 3 or more (meaning ";;;" in Scheme, or "///" in C or javascript). It turns out this was really nice, since it ends up highlighting file-level comments at the top and section headers throughout the code.

I think this looks much nicer than other techniques, such as repeating the comment character 40 times to indicate a line (e.g. ";;;;;;;;;;;;" over and over). If everyone on a project wrote code this simple way, each person would get to choose how to view those kinds of comments.

I wanted to separate this functionality into its own package so that I could use it in languages other than Scheme. I have never written any Emacs Lisp before, so although it was pretty brutal, I ended up with something that works rather nicely. Use it if you want.

(defconst jwl-title-face 'jwl-title-face)
(defface jwl-title-face
'((((class color) (background light))
(:background "DarkSeaGreen1" :foreground "grey25"))
(((class color) (background dark))
(:background "DarkGrey")))
"Face used for titles.")

(defun jwl-generate-highlight-keywords (comment-char)
`((,(concat "^\\([ \t]*"
"[ \t]*"
1 jwl-title-face prepend)))

(lambda ()
(jwl-generate-highlight-keywords ";"))))

(lambda ()
(jwl-generate-highlight-keywords "#"))))

(lambda ()
(jwl-generate-highlight-keywords "/"))))

Sign in to follow this  


Recommended Comments

There are no comments to display.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!