unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Selective Font Lock Case Sensitivity
@ 2014-04-13 18:39 Jacob Gerlach
  2014-04-14  1:57 ` Stefan Monnier
       [not found] ` <mailman.19585.1397440822.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: Jacob Gerlach @ 2014-04-13 18:39 UTC (permalink / raw)
  To: help-gnu-emacs

I understand that I can make all of the regex's used for font lock case sensitive or not using 'font-lock-defaults'.

I'd like more granular control. Is there a way to specify case (in)sensitivity for only some font lock entries or do I need to manually achieve this by altering my regex's?

A similar question was asked here: http://lists.gnu.org/archive/html/help-gnu-emacs/2013-03/msg00140.html, but never answered.


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

* Re: Selective Font Lock Case Sensitivity
  2014-04-13 18:39 Selective Font Lock Case Sensitivity Jacob Gerlach
@ 2014-04-14  1:57 ` Stefan Monnier
       [not found] ` <mailman.19585.1397440822.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2014-04-14  1:57 UTC (permalink / raw)
  To: help-gnu-emacs

> I'd like more granular control. Is there a way to specify case
> (in)sensitivity for only some font lock entries or do I need to manually
> achieve this by altering my regex's?

You can use

            (lambda (limit)
              (let ((case-fold-search t))
                (re-search-forward RE limit t)))

instead of RE.


        Stefan




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

* Re: Selective Font Lock Case Sensitivity
       [not found] ` <mailman.19585.1397440822.10748.help-gnu-emacs@gnu.org>
@ 2014-04-16  2:08   ` Jacob Gerlach
  2014-04-16 17:16     ` Stefan Monnier
       [not found]     ` <mailman.19711.1397668616.10748.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: Jacob Gerlach @ 2014-04-16  2:08 UTC (permalink / raw)
  To: help-gnu-emacs

> You can use
> 
> 
> 
>             (lambda (limit)
> 
>               (let ((case-fold-search t))
> 
>                 (re-search-forward RE limit t)))

I'm trying to do this in font lock. Are you saying I could do something like:

((lambda...) . font-lock-keyword-face)

instead of the usual
("RE" . font-lock-keyword-face) 


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

* Re: Selective Font Lock Case Sensitivity
  2014-04-16  2:08   ` Jacob Gerlach
@ 2014-04-16 17:16     ` Stefan Monnier
       [not found]     ` <mailman.19711.1397668616.10748.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2014-04-16 17:16 UTC (permalink / raw)
  To: help-gnu-emacs

> I'm trying to do this in font lock. Are you saying I could do something like:

> ((lambda...) . font-lock-keyword-face)

> instead of the usual
> ("RE" . font-lock-keyword-face) 

Yes.


        Stefan




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

* Re: Selective Font Lock Case Sensitivity
       [not found]     ` <mailman.19711.1397668616.10748.help-gnu-emacs@gnu.org>
@ 2014-04-16 18:41       ` Jacob Gerlach
  2014-04-17  2:46         ` Jacob Gerlach
  0 siblings, 1 reply; 7+ messages in thread
From: Jacob Gerlach @ 2014-04-16 18:41 UTC (permalink / raw)
  To: help-gnu-emacs

I'm having trouble implementing this, I think because of some more basic lisp understanding deficiency. 

I'm constructing entries for my-font-lock-keywords by using mapc to work from a master list.

The function called by mapc adds a backquoted list to my keyword list. Before trying to adjust case sensitivity, it looked like:

(defun add-to-my-keyword-list (input)
   (add-to-list 'my-font-lock-keywords
	       `( 
		,(;;non-buggy-code here for anchor)
                ,(regexp-opt (cadr input))
                (my-pre-form)
                nil
                (0 font-lock-keyword-face))))

My trouble is getting (regexp-opt (cadr input)) to properly expand to an argument for re-search-forward.

The closest I've been able to come is to use

(lambda (limit)
  (let ((case-fold-search t))
    `(re-search-forward ,(regexp-opt ,@(cadr input)) limit t)))

In this case, (cadr input) is evaluated, but (regexp-opt is not. The constructed list reads
...
(\` (re-search-forward (\,@ (regexp-opt
...

Is this an easy fix?


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

* Re: Selective Font Lock Case Sensitivity
  2014-04-16 18:41       ` Jacob Gerlach
@ 2014-04-17  2:46         ` Jacob Gerlach
  2014-04-17  3:51           ` Stefan Monnier
  0 siblings, 1 reply; 7+ messages in thread
From: Jacob Gerlach @ 2014-04-17  2:46 UTC (permalink / raw)
  To: help-gnu-emacs

>> (lambda (limit)
>>   (let ((case-fold-search t))
>>     (re-search-forward ,(regexp-opt (cadr input)) limit t)))

This indeed fixed the expansion. This now expands to something that looks right, but it still doesn't work.

I am trying to use an anchored matcher with a pre-form.

What I think I understand from the documentation is that I should end up with something like:

("anchor"
 (lambda (limit)
  (let ((case-fold-search t))
   (re-search-forward "keywords-re") limit t))
 (pre-form)
 nil
 (0 font-lock-keyword-face))

What I don't understand is if the list as I've written it here is properly formatted, or if I need to construct it as sub-lists, cons cells, etc.

Thanks for all the help so far, I hope it is not too tedious dealing with such a lisp novice.


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

* Re: Selective Font Lock Case Sensitivity
  2014-04-17  2:46         ` Jacob Gerlach
@ 2014-04-17  3:51           ` Stefan Monnier
  0 siblings, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2014-04-17  3:51 UTC (permalink / raw)
  To: help-gnu-emacs

> What I think I understand from the documentation is that I should end up with something like:

> ("anchor"
>  (lambda (limit)
>   (let ((case-fold-search t))
>    (re-search-forward "keywords-re") limit t))
>  (pre-form)
>  nil
>  (0 font-lock-keyword-face))

IIRC you need

   ("anchor"
    ((lambda (limit)
      (let ((case-fold-search t))
       (re-search-forward "keywords-re") limit t))
     (pre-form)
     nil
     (0 font-lock-keyword-face)))

-- Stefan


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

end of thread, other threads:[~2014-04-17  3:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-13 18:39 Selective Font Lock Case Sensitivity Jacob Gerlach
2014-04-14  1:57 ` Stefan Monnier
     [not found] ` <mailman.19585.1397440822.10748.help-gnu-emacs@gnu.org>
2014-04-16  2:08   ` Jacob Gerlach
2014-04-16 17:16     ` Stefan Monnier
     [not found]     ` <mailman.19711.1397668616.10748.help-gnu-emacs@gnu.org>
2014-04-16 18:41       ` Jacob Gerlach
2014-04-17  2:46         ` Jacob Gerlach
2014-04-17  3:51           ` Stefan Monnier

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).