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 19:43:43 +0100 Organization: my virtual residence Message-ID: <878usl26jk.fsf@yun.yagibdah.de> References: <87zjl2kzdv.fsf@yun.yagibdah.de> <871tyeghg1.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 1394219740 32448 80.91.229.3 (7 Mar 2014 19:15:40 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 7 Mar 2014 19:15:40 +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 20:15:49 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 1WM0FI-0000mA-Ci for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Mar 2014 20:15:48 +0100 Original-Received: from localhost ([::1]:37967 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WM0FH-0004Ia-TZ for geh-help-gnu-emacs@m.gmane.org; Fri, 07 Mar 2014 14:15:47 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:43713) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WM0Et-0004IV-Lu for help-gnu-emacs@gnu.org; Fri, 07 Mar 2014 14:15:28 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WM0Eo-000665-0p for help-gnu-emacs@gnu.org; Fri, 07 Mar 2014 14:15:23 -0500 Original-Received: from client-194-42-186-216.muenet.net ([194.42.186.216]:44769 helo=yun.yagibdah.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WM0En-00062U-P1 for help-gnu-emacs@gnu.org; Fri, 07 Mar 2014 14:15:17 -0500 Original-Received: from lee by yun.yagibdah.de with local (Exim 4.80.1) (envelope-from ) id 1WM0Em-0003YG-2A for help-gnu-emacs@gnu.org; Fri, 07 Mar 2014 20:15:16 +0100 In-Reply-To: (Drew Adams's message of "Fri, 7 Mar 2014 09:06:40 -0800 (PST)") 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:96302 Archived-At: Drew Adams writes: > See http://stackoverflow.com/a/21997150/729907, which is about > highlighting the symbol at point or under the mouse pointer. > There are multiple approaches with different advantages. Thanks! Those don=C2=B4t really seem to be what I=C2=B4m looking for, thou= gh. > (Remember too that `C-s C-w C-w...' will also highlight > occurrences of text at point, albeit transiently.) Hm, I have bound C-s to isearch-forward-regexp ... So far, hi-lock-mode is great. I have found that when writing new patterns to the buffer, they first need to be removed to avoid adding them multiple times. This has lead to: (defun lsl-hi-lock-remove () "Remove hi-lock-mode patterns from the beginning of the buffer. You may want to customize hi-lock-file-patterns-range when you have many patterns." (interactive) (let ((startpos nil) (target-regexp (concat "\\<" hi-lock-file-patterns-prefix ":"))) (save-excursion (save-restriction (widen) (goto-char (point-min)) (re-search-forward target-regexp (+ (point) hi-lock-file-patterns-range) t) (beginning-of-line) (setq startpos (point)) (while (and (re-search-forward target-regexp (+ (point) 100) t) (not (looking-at "\\s-*end"))) (end-of-line) (condition-case nil (delete-region startpos (point)) (error (message "Invalid pattern list expression at %d" (line-number-a= t-pos))))))))) (defun lsl-hi-lock-add (whichface) "Add the symbol at point to the patterns highlighted through hi-lock-mode; then write the current patterns to the beginning of the file. The argument whichface specifies which face to use for the highlighting. You may want to customize hi-lock-file-patterns-range when you have many patterns." (lsl-hi-lock-remove) (let* ((regexp (hi-lock-regexp-okay (find-tag-default-as-symbol-regexp)))) (hi-lock-set-pattern regexp whichface)) (save-excursion (goto-char (point-min)) (hi-lock-write-interactive-patterns))) (defun lsl-hi-lock-constant () (interactive) (lsl-hi-lock-add font-lock-comment-delimiter-face)) (defun lsl-hi-lock-functionlike () (interactive) (lsl-hi-lock-add font-lock-warning-face)) I have bound (lsl-hi-lock-constant) and (lsl-hi-lock-functionlike) to C-w c and C-w f, respectively. But there is a problem: When I restart emacs and visit a buffer that has hi-lock patterns at the beginning, they are applied just fine, but they cannot be written to the buffer again. It=C2=B4s like hi-lock-mode doesn=C2=B4t know that they exist, though the highlighting works as expecte= d. Only newly created patterns can be written to the buffer. That means when I use (lsl-hi-lock-constant), the existing patterns are removed and only the new one is added. Is there a way to make the existing patterns, as specified in the buffer, known to hi-lock-mode in such a way that they can be added to the buffer again like the new ones can with (hi-lock-write-interactive-patterns)? Is this a bug? Isn=C2=B4t hi-lock-mode supposed to know which patterns are in use and to be able to write them to the buffer? And another question: Is there a way to apply the patterns for a number of buffers? Suppose I work on some project which involves several files. Some of these files use a constant "foobar". Now I would have to add to all of these files a pattern to highlight "foobar". How do I make it so that, let=C2=B4s say, hi-lock-mode reads the patterns from a common file that holds all patterns relevant for the project so that I don=C2=B4t need to add them to every file in question? Please don=C2=B4t tell me that what I=C2=B4m looking for doesn=C2=B4t exist= ... --=20 Knowledge is volatile and fluid. Software is power.