help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: replacing a function with another one


From: Michael Heerdegen
Subject: Re: replacing a function with another one
Date: Tue, 11 Mar 2014 01:41:10 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

lee <address@hidden> writes:

> > Instead, use an auxiliary variable, e.g.
>
> Hm, I have experimented with variables and found that things don´t work
> when the variables are local.  But then, I can´t get add-advice to work,
> not even with global variables.  It´s too complicated, and the
> documentation is not understandable at all.
>
> It also seems that it is not possible at all to make a mode on top of
> hi-lock-mode which does what I want.  Variables have to be local per
> buffer, and with that, it´s not possible to read patterns from different
> buffers because the variables change because buffers must be switched to
> read the patterns.

Please don't get confused.  Use global auxiliary variables for things
that reflect buffer independent states.  And you can always get the
buffer local binding of a variable foo in any buffer b with

  (with-current-buffer b foo)

There is no limitation from the Emacs' side.

Mmh, ok, let's start from the beginning and simple.  Let's add some
mechanism that allows to specify additional, directory local hi-lock
patterns.  That should be simple as this:

    (defvar hi-lock-dir-patterns nil)  ;; use as dir local variable
    
    (advice-add
     'hi-lock-find-patterns :after
     (lambda (&rest _)
       (hi-lock-set-file-patterns
        (append hi-lock-file-patterns
                hi-lock-dir-patterns))))

The advice just merges in the additional patterns.  Note that using
directory local variables has the advantage that me must not explicitly
look up the patterns, because the directory local variable is
automatically bound when the file is opened.

This should be all to do as long as you don't want to automatically save
additional patterns - you have to add them yourself in the .dir-locals
file.

If you want such automatic saving, we would just have to substitute the
dir local variable with a mechanism that loads and saves explicitly.  Is
this what you want?


Regards,

Michael.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]