From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: lee Newsgroups: gmane.emacs.help Subject: Re: syntax highlighting on the fly Date: Fri, 07 Mar 2014 16:24:30 +0100 Organization: my virtual residence Message-ID: <871tyeghg1.fsf@yun.yagibdah.de> References: <87zjl2kzdv.fsf@yun.yagibdah.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1394206124 25779 80.91.229.3 (7 Mar 2014 15:28:44 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 7 Mar 2014 15:28:44 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Mar 07 16:28:52 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WLwhg-0003MQ-FG for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Mar 2014 16:28:52 +0100 Original-Received: from localhost ([::1]:37091 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLwhf-0000GG-Tj for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Mar 2014 10:28:51 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:50117) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLwhK-0000E8-WA for help-gnu-emacs@gnu.org; Fri, 07 Mar 2014 10:28:35 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WLwhG-0000fF-De for help-gnu-emacs@gnu.org; Fri, 07 Mar 2014 10:28:30 -0500 Original-Received: from client-194-42-186-216.muenet.net ([194.42.186.216]:44564 helo=yun.yagibdah.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WLwhG-0000f6-7X for help-gnu-emacs@gnu.org; Fri, 07 Mar 2014 10:28:26 -0500 Original-Received: from lee by yun.yagibdah.de with local (Exim 4.80.1) (envelope-from ) id 1WLwhF-0000Fe-Bl for help-gnu-emacs@gnu.org; Fri, 07 Mar 2014 16:28:25 +0100 In-Reply-To: (Rainer M. Krug's message of "Fri, 07 Mar 2014 13:24:12 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Mail-Followup-To: help-gnu-emacs@gnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 194.42.186.216 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:96295 Archived-At: Rainer M Krug writes: > lee 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=C2=B4d 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=C2=B4s a better way to do this? --=20 Knowledge is volatile and fluid. Software is power.