2

some times i have comments to my code at different structure levels, for example the following python code:

# level one comment
for i in list:
    # level two comment
    if mod(i, 2):
        # level three comment
        print 'odd number'
    else:
        print 'even number

i want to have different font size (or slightly different color) for different level of comments, is there such a package to do something like this? also, for example for elisp code, i usually add comments to different levels with different number of heading chars ;, for example:

;;; level 1 comments
(sexp level 1
  ;; level 2 comments
  (sexp level 2
     ; level 3 and >3 coments 
       (sexp level 3)))

if i can display the comments of different levels using different faces, that can greatly help to review and understand the structures of my code. thanks!

Drew
  • 29,895
  • 7
  • 74
  • 104
shelper
  • 10,053
  • 8
  • 41
  • 67
  • So what's stopping you? It should be simple to modify the elisp highlighting code. – stark Jun 23 '13 at 01:16
  • i dont know much about elips, just started learning, i also wonder if there is a package available to do this to save some trouble – shelper Jun 23 '13 at 13:43

1 Answers1

4

The face used to display comments and strings is decided by the function set in font-lock-syntactic-face-function. So you can just set that variable to a function of your own which can take the number of semi-colons, or the indentation as a cue to choose different faces.

Stefan
  • 27,908
  • 4
  • 53
  • 82
  • i 've tried to look into the function that pointed to by `font-lock-syntactic-face-function`, which is `lisp-font-lock-syntactic-face-function`, and then the Emacs says: no document for this function .... i am new to elisp, so i am lost now... anyway, thanks for point the direction, i will just leave it until i get more experience – shelper Jun 23 '13 at 14:34
  • The value of `font-lock-syntactic-face-function` can be different in each buffer. `lisp-font-lock-syntactic-face-function` is not documented, but that doesn't matter since what you really want is to see its code, which you can do by clicking on the `lisp-mode.el` link at the top of the \*Help\* buffer (tho, in some systems, you may need to intall extra packages, such as `emacs-el` to get this source code). – Stefan Jun 23 '13 at 16:26