[Top][All Lists]

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

Re: replacing a function with another one

From: lee
Subject: Re: replacing a function with another one
Date: Tue, 11 Mar 2014 00:35:33 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Stefan Monnier <address@hidden> writes:

>> (defadvice hi-lock-set-file-patterns (after my-test-obtain-patterns)
>>   ...
>>   (ad-deactivate 'hi-lock-set-file-patterns)
> [...]
>> (defun my-test ()
>>   ...
>>   (ad-activate 'hi-lock-set-file-patterns)
> I recommend you don't use ad-activate and ad-deactivate (among other
> reasons because they activate/deactivate all advices applied to the
> function rather than only the one you know about; but also because they
> hide the existence of an advice).
> 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.

Perhaps I can fork hi-lock.el and somehow make it work with multiple
buffers, but I doubt it.

> BTW, I recommend you then merge my-set-patterns-in-original-buffer and
> original-buffer, so the advice is always active but only does something
> if original-buffer is non-nil.

That doesn´t work with global variables because for one buffer, the
original-buffer may be nil when patterns are not read from another

> Also, use with-current-buffer rather than pop-to-buffer (pop-to-buffer
> has *many* side-effects, so using it in an advice is a recipe for
> disaster):


>                 ;; FIXME: usually from Lisp we should call find-file-noselect,
>                 ;; but I don't know what's the intention here.
>               (find-file filename)

The intention was to load the file so that hi-lock-mode reads the
patterns from it.  I simply didn´t know what else to use.  It would be
nice if things like this would be mentioned in the documentation ...

Knowledge is volatile and fluid.  Software is power.

reply via email to

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