all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* A problem in using font-lock-add-keywords
@ 2013-03-05  2:54 source liu
  2013-03-05  4:58 ` Dmitry Gutov
  2013-03-05  8:50 ` Dmitry Gutov
  0 siblings, 2 replies; 5+ messages in thread
From: source liu @ 2013-03-05  2:54 UTC (permalink / raw)
  To: help-gnu-emacs

Hi, list


1. about font-lock-add-keywords
I'm new to elisp, and i want to add some keywords to a mode( say,
c-mode), a list is below,
(defvar my-list '("FIXME" "AND" "OR"))


and I find some hint in emacs help  C-h f "font-lock-add-keywords"

========= reference from the buff of help ===========
 (add-hook 'c-mode-hook
  (lambda ()
   (font-lock-add-keywords nil
    '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
      ("\\<\\(and\\|or\\|not\\)\\>" .
       font-lock-keyword-face)))))
==========================================

i've tested it, it works, but when i change the expression of
"\\<(FIXME\\):"  by (regexp-opt mylist t), it can't work.  does
someone give me some hint where my problem is?

2. by the way, does emacs list have a max length?
i find when the list is beyond about 4600 words, the bracket ")" cant match "("






-- 
Liu An
Institution of modern physics, Shanghai, China



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: A problem in using font-lock-add-keywords
  2013-03-05  2:54 A problem in using font-lock-add-keywords source liu
@ 2013-03-05  4:58 ` Dmitry Gutov
  2013-03-05  7:34   ` source liu
  2013-03-05  8:50 ` Dmitry Gutov
  1 sibling, 1 reply; 5+ messages in thread
From: Dmitry Gutov @ 2013-03-05  4:58 UTC (permalink / raw)
  To: source liu; +Cc: help-gnu-emacs

source liu <sourceonly@gmail.com> writes:
> 1. about font-lock-add-keywords
> I'm new to elisp, and i want to add some keywords to a mode( say,
> c-mode), a list is below,
> (defvar my-list '("FIXME" "AND" "OR"))
>
>
> and I find some hint in emacs help  C-h f "font-lock-add-keywords"
>
> ========= reference from the buff of help ===========
>  (add-hook 'c-mode-hook
>   (lambda ()
>    (font-lock-add-keywords nil
>     '(("\\<\\(FIXME\\):" 1 font-lock-warning-face prepend)
>       ("\\<\\(and\\|or\\|not\\)\\>" .
>        font-lock-keyword-face)))))
> ==========================================
>
> i've tested it, it works, but when i change the expression of
> "\\<(FIXME\\):"  by (regexp-opt mylist t), it can't work.  does
> someone give me some hint where my problem is?

The problem is likely with quoting. You need to expand the `regexp-opt'
call:

(font-lock-add-keywords nil
 `((,(regexp-opt mylist t) 1 font-lock-warning-face prepend)
   ("\\<\\(and\\|or\\|not\\)\\>" . font-lock-keyword-face))

By the way, as long as you want to highlight the whole match, you can
use the group number 0 and no grouping.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: A problem in using font-lock-add-keywords
  2013-03-05  4:58 ` Dmitry Gutov
@ 2013-03-05  7:34   ` source liu
  0 siblings, 0 replies; 5+ messages in thread
From: source liu @ 2013-03-05  7:34 UTC (permalink / raw)
  To: Dmitry Gutov; +Cc: help-gnu-emacs

done!
the quote teach me a lesson.  Thank you, Dmitry

by the way, if i use this way, are there any restriction to the list,
i mean, length, or size of the 'mylist' as metioned below.


> The problem is likely with quoting. You need to expand the `regexp-opt'
> call:
>
> (font-lock-add-keywords nil
>  `((,(regexp-opt mylist t) 1 font-lock-warning-face prepend)
>    ("\\<\\(and\\|or\\|not\\)\\>" . font-lock-keyword-face))
>
> By the way, as long as you want to highlight the whole match, you can
> use the group number 0 and no grouping.



-- 
Liu An
Institution of modern physics, Shanghai, China



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: A problem in using font-lock-add-keywords
  2013-03-05  2:54 A problem in using font-lock-add-keywords source liu
  2013-03-05  4:58 ` Dmitry Gutov
@ 2013-03-05  8:50 ` Dmitry Gutov
       [not found]   ` <CAAzVxgMu3EnA1_FMG9oLshCxhPV03=qkVNoWKhygUJKa8C6DwA@mail.gmail.com>
  1 sibling, 1 reply; 5+ messages in thread
From: Dmitry Gutov @ 2013-03-05  8:50 UTC (permalink / raw)
  To: source liu; +Cc: help-gnu-emacs

source liu <sourceonly@gmail.com> writes:
> 2. by the way, does emacs list have a max length?
> i find when the list is beyond about 4600 words, the bracket ")" cant
> match "("

I'm not aware of any limits, aside from the obvious ones (the RAM size,
etc). This returns a list with 100000 elements:

(cl-loop for i from 1 to 100000 collect i)

If my matching you mean visual display, then it's something to do with
the minor mode that performs it. For example, see
`blink-matching-paren-distance'.



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: A problem in using font-lock-add-keywords
       [not found]   ` <CAAzVxgMu3EnA1_FMG9oLshCxhPV03=qkVNoWKhygUJKa8C6DwA@mail.gmail.com>
@ 2013-03-05 10:14     ` Dmitry Gutov
  0 siblings, 0 replies; 5+ messages in thread
From: Dmitry Gutov @ 2013-03-05 10:14 UTC (permalink / raw)
  To: source liu; +Cc: help-gnu-emacs@gnu.org

On 05.03.2013 13:33, source liu wrote:
> My value of `blink-matching-paren-distance' is 102400
> and when I type M-102400 C-f, it jump to the very place from where it
> can't match ")",

That's to be expected, see the description of the above variable.

it failed "M-x eval-buff" when the chars are beyond
> the range

This isn't. Works for me, I don't have any problems with evaluating your 
buffer.

> Come back to font-lock problem,  i can customize the font-lock
> keywords when the list is short, but it is not the case when i use the
> list defined in my attach.
> if you have time, please take a look at it.  many thanks
>
> in my .emacs file, i wrote
>   ================================================================
> (load-file  "~/.hyperworks.el")
> (add-hook 'tcl-mode-hook
> 	  (lambda ()
> 	    (font-lock-add-keywords nil
> 	     `((,(regexp-opt hypermesh-command-list2  t) . font-lock-constant-face)))))
>
> (display-time)
> =================================================================
>
> and hypermesh-command-list2 is defined in .hyperworks.el, in the attach file.
>
> The case is that, when i use `hypermesh-command-list2', it works ok,
> and i changed to `hypermesh-command-list1', it doesn't work, and it
> ruined the default font-lock-mode in tcl-mode.  the only deference
> between the two list is list length, i think.
>
> could you help? many thanks.

Here's how I debugged it:

1. Have the buggy buffer selected.
2. M-x toggle-debug-on-error
3. M-: (font-lock-fontify-region (point-min) (point-max))

At this point you should see the backtrace and that `re-search-forward' 
aborts complaining that the regexp is too big. It's not a restriction on 
the size of any Emacs primitive, the restriction is in the regexp engine.

I'm sure what to recommend here. Split the list into several, maybe.



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-03-05 10:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-05  2:54 A problem in using font-lock-add-keywords source liu
2013-03-05  4:58 ` Dmitry Gutov
2013-03-05  7:34   ` source liu
2013-03-05  8:50 ` Dmitry Gutov
     [not found]   ` <CAAzVxgMu3EnA1_FMG9oLshCxhPV03=qkVNoWKhygUJKa8C6DwA@mail.gmail.com>
2013-03-05 10:14     ` Dmitry Gutov

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.