all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: lee <lee@yun.yagibdah.de>
To: help-gnu-emacs@gnu.org
Subject: Re: syntax highlighting on the fly
Date: Fri, 07 Mar 2014 19:43:43 +0100	[thread overview]
Message-ID: <878usl26jk.fsf@yun.yagibdah.de> (raw)
In-Reply-To: <f92986c7-232e-4b7b-a512-52ba8eb7c157@default> (Drew Adams's message of "Fri, 7 Mar 2014 09:06:40 -0800 (PST)")

Drew Adams <drew.adams@oracle.com> 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´t really seem to be what I´m looking for, though.

> (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-at-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´s like hi-lock-mode
doesn´t know that they exist, though the highlighting works as expected.

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´t 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´s say, hi-lock-mode reads the patterns from a
common file that holds all patterns relevant for the project so that I
don´t need to add them to every file in question?

Please don´t tell me that what I´m looking for doesn´t exist ...


-- 
Knowledge is volatile and fluid.  Software is power.



      reply	other threads:[~2014-03-07 18:43 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-07 11:43 syntax highlighting on the fly lee
2014-03-07 12:20 ` Jambunathan K
2014-03-07 13:17   ` lee
2014-03-07 12:24 ` Rainer M Krug
2014-03-07 15:24   ` lee
2014-03-07 17:06     ` Drew Adams
2014-03-07 18:43       ` lee [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=878usl26jk.fsf@yun.yagibdah.de \
    --to=lee@yun.yagibdah.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.