[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: syntax highlighting on the fly
From: |
lee |
Subject: |
Re: syntax highlighting on the fly |
Date: |
Fri, 07 Mar 2014 16:24:30 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Rainer M Krug <Rainer@krugs.de> writes:
> lee <lee@yun.yagibdah.de> writes:
>
>> Hi,
>>
>> is something available with emacs to do to syntax highlighting on the
>> fly?
>>
>> "On the fly" means: You have a mode with syntax highlighting which does
>> most of the highlighting. Now you work on a file (source code for some
>> program) in a buffer with your mode enabled, and you decide that for
>> this particular file, you want "foobar" to be highlighted.
>>
>> You´d have to somehow tell emacs to do this, for example by adding a
>> comment like
>>
>>
>> // highlight: foobar
>>
>>
>> to your file. You could also do it like
>>
>>
>> #define foobar 25
>
> I like this idea - add highlighting of certain words by using
> file-local-variables.
>
> Please keep us posted.
Provided that hi-lock-mode is enabled, the following might be useful.
Bind to a key if you like, perhaps C-x w .
(defun my-hi-lock-add ()
"Add the symbol at point to the patterns highlighted through
hi-lock-mode; then write the current patterns to the beginning of
the file."
(interactive)
(let* ((regexp (hi-lock-regexp-okay (find-tag-default-as-symbol-regexp))))
(hi-lock-set-pattern regexp font-lock-comment-delimiter-face))
(save-excursion
(beginning-of-buffer)
(hi-lock-write-interactive-patterns)))
The point is that I wanted to use a particular face
(font-lock-comment-delimiter-face in this case) and not change the
defaults picked by hi-lock-mode (since they appear to be global). The
added benefit is that the current patterns are automatically written to
the top of the file.
What bothers me a little is that if hi-lock.el.gz changes, my function
might cease to work. Perhaps there´s a better way to do this?
--
Knowledge is volatile and fluid. Software is power.