[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 15:25:28 +0100 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
Michael Heerdegen <michael_heerdegen@web.de> writes:
> lee <lee@yun.yagibdah.de> writes:
>
>> Sigh ... Any idea why the following does not work:
>
> Your code does something you definitely shouldn't do: your advices make
> `hi-lock-set-file-patterns' and `hi-lock-find-patterns' switch to a
> different buffer (persistently!). When you need the context of another
> buffer, use `with-current-buffer' to switch to it temporarily.
The idea is very simple: When patterns are to be read from another
buffer, switch to that buffer before they are being read. Before
applying them, switch back to the original buffer.
I can´t do that with `with-current-buffer´ because two different functions
need to be advised to do it, and I can´t get add-advice to work with
:around.
Why shouldn´t I switch buffers? They are switched back anyway.
In any case, why doesn´t it work? Is there a way to see what´s going
on, like some debugger that allows me to run it line by line? I really
want to know why it doesn´t work.
> Maybe the following illustration may help:
>
> (defvar-local foo)
>
> Suppose we have two buffers buffer-a and buffer-b. buffer-a is current,
> and we want to set `foo's binding in buffer-a to `foo's value in
> buffer-b (I think this is what you try to do, more or less). This is
> how you can do it
>
> (let (helper) ; temporary variable (not buffer local)
>
> (with-current-buffer buffer-b
> ;; set it to `foo's binding in buffer-b
> (setq helper foo))
>
> ;;back in buffer-a
> (setq foo helper))
That´s why it might be better to make a fork of hi-lock.el. I could
modify the functions directly and add other ones I´d need. Or maybe I
should just re-define some of the functions.
In any case, when hi-lock.el changes, what I´m doing may not work
anymore. So what difference does it make?
> BTW, did you have a look at my example? I think it's quite close to
> what you want to achieve.
Yes, it looks very interesting :)
One thing I haven´t been able to figure out is how hi-lock.el decides
what the lines it writes to the buffer are prepended with. In one
buffer, it puts "// Hi-lock ...", in another one, it´s "# Hi-lock ...".
Then it searches patterns with '"\\<" hi-lock-file-patterns-prefix ":"',
and apparently it will not find patterns prepended with "//" when it
figures that they should be prepended with "#".
The regexp for a comment starter is "\s<"[1], and it is not used in the
search. So why aren´t patterns found when an unexpected comment starter
is used with the patterns written to a buffer?
[1]: http://www.emacswiki.org/emacs/RegularExpression
--
Knowledge is volatile and fluid. Software is power.
- Re: replacing a function with another one, (continued)
- Re: replacing a function with another one, Michael Heerdegen, 2014/03/10
- Re: replacing a function with another one, lee, 2014/03/11
- Re: replacing a function with another one, Michael Heerdegen, 2014/03/11
- Re: replacing a function with another one, lee, 2014/03/12
- Re: replacing a function with another one, Stefan Monnier, 2014/03/12
- Re: replacing a function with another one, lee, 2014/03/12
- Re: replacing a function with another one, Michael Heerdegen, 2014/03/13
- Re: replacing a function with another one, lee, 2014/03/15
- Re: replacing a function with another one, lee, 2014/03/11
- Re: replacing a function with another one, Michael Heerdegen, 2014/03/11
- Re: replacing a function with another one,
lee <=
- Re: replacing a function with another one, Michael Heerdegen, 2014/03/11
- Re: replacing a function with another one, lee, 2014/03/12
- Re: replacing a function with another one, Michael Heerdegen, 2014/03/13
- Re: replacing a function with another one, Stefan Monnier, 2014/03/13
- Re: replacing a function with another one, lee, 2014/03/15
- Re: replacing a function with another one, Stefan, 2014/03/16
- Re: replacing a function with another one, Michael Heerdegen, 2014/03/11
- Re: replacing a function with another one, lee, 2014/03/11
- Re: replacing a function with another one, Michael Heerdegen, 2014/03/11
- Re: replacing a function with another one, lee, 2014/03/12