From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: lee Newsgroups: gmane.emacs.help Subject: Re: replacing a function with another one Date: Tue, 11 Mar 2014 15:25:28 +0100 Organization: my virtual residence Message-ID: <87txb4izhj.fsf@yun.yagibdah.de> References: <87vbvofsi6.fsf@yun.yagibdah.de> <87bnxgs4r9.fsf@web.de> <87lhwj1cfz.fsf@yun.yagibdah.de> <87zjkz6vd5.fsf@web.de> <8738ir161u.fsf@yun.yagibdah.de> <87eh2b6nfm.fsf@web.de> <87r46anab5.fsf@yun.yagibdah.de> <87vbvleiey.fsf@yun.yagibdah.de> <87vbvlbm8p.fsf@web.de> <87siqpsdgs.fsf@yun.yagibdah.de> <87ob1djpkq.fsf@web.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1394564884 25825 80.91.229.3 (11 Mar 2014 19:08:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 11 Mar 2014 19:08:04 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Mar 11 20:08:13 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WNS28-0005Y8-S0 for geh-help-gnu-emacs@m.gmane.org; Tue, 11 Mar 2014 20:08:12 +0100 Original-Received: from localhost ([::1]:56989 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNS28-0000IL-9I for geh-help-gnu-emacs@m.gmane.org; Tue, 11 Mar 2014 15:08:12 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:52078) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNS1p-0000GF-01 for help-gnu-emacs@gnu.org; Tue, 11 Mar 2014 15:07:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNS1k-00024J-EI for help-gnu-emacs@gnu.org; Tue, 11 Mar 2014 15:07:52 -0400 Original-Received: from client-194-42-186-216.muenet.net ([194.42.186.216]:52391 helo=yun.yagibdah.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNS1k-00023v-3A for help-gnu-emacs@gnu.org; Tue, 11 Mar 2014 15:07:48 -0400 Original-Received: from lee by yun.yagibdah.de with local (Exim 4.80.1) (envelope-from ) id 1WNS1g-0002mQ-KV for help-gnu-emacs@gnu.org; Tue, 11 Mar 2014 20:07:44 +0100 In-Reply-To: <87ob1djpkq.fsf@web.de> (Michael Heerdegen's message of "Tue, 11 Mar 2014 06:01:57 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Mail-Followup-To: help-gnu-emacs@gnu.org X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 194.42.186.216 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:96427 Archived-At: Michael Heerdegen writes: > lee 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=C2=B4t do that with `with-current-buffer=C2=B4 because two different = functions need to be advised to do it, and I can=C2=B4t get add-advice to work with :around. Why shouldn=C2=B4t I switch buffers? They are switched back anyway. In any case, why doesn=C2=B4t it work? Is there a way to see what=C2=B4s g= oing on, like some debugger that allows me to run it line by line? I really want to know why it doesn=C2=B4t 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) >=20=20=20 > (with-current-buffer buffer-b > ;; set it to `foo's binding in buffer-b > (setq helper foo)) >=20=20=20 > ;;back in buffer-a > (setq foo helper)) That=C2=B4s why it might be better to make a fork of hi-lock.el. I could modify the functions directly and add other ones I=C2=B4d need. Or maybe I should just re-define some of the functions. In any case, when hi-lock.el changes, what I=C2=B4m 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=C2=B4t 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=C2=B4s "# 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=C2=B4t patterns found when an unexpected comment start= er is used with the patterns written to a buffer? [1]: http://www.emacswiki.org/emacs/RegularExpression --=20 Knowledge is volatile and fluid. Software is power.