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 00:35:33 +0100 Organization: my virtual residence Message-ID: <87vbvleiey.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> 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 1394494555 1733 80.91.229.3 (10 Mar 2014 23:35:55 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Mar 2014 23:35:55 +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 00:36:02 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 1WN9jm-0000Q2-A6 for geh-help-gnu-emacs@m.gmane.org; Tue, 11 Mar 2014 00:36:02 +0100 Original-Received: from localhost ([::1]:51681 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN9jl-0000JI-T4 for geh-help-gnu-emacs@m.gmane.org; Mon, 10 Mar 2014 19:36:01 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60689) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN9jX-0000AV-6f for help-gnu-emacs@gnu.org; Mon, 10 Mar 2014 19:35:52 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WN9jS-00053X-CL for help-gnu-emacs@gnu.org; Mon, 10 Mar 2014 19:35:47 -0400 Original-Received: from client-194-42-186-216.muenet.net ([194.42.186.216]:52020 helo=yun.yagibdah.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WN9jS-00053F-3R for help-gnu-emacs@gnu.org; Mon, 10 Mar 2014 19:35:42 -0400 Original-Received: from lee by yun.yagibdah.de with local (Exim 4.80.1) (envelope-from ) id 1WN9jQ-0001jH-E2 for help-gnu-emacs@gnu.org; Tue, 11 Mar 2014 00:35:40 +0100 In-Reply-To: (Stefan Monnier's message of "Mon, 10 Mar 2014 08:44:38 -0400") 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:96417 Archived-At: Stefan Monnier 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=C2=B4t work when the variables are local. But then, I can=C2=B4t get add-advice to wor= k, not even with global variables. It=C2=B4s 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=C2=B4s not possible to read patterns from differe= nt 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=C2=B4t work with global variables because for one buffer, the original-buffer may be nil when patterns are not read from another buffer. > 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): ok > ;; FIXME: usually from Lisp we should call find-file-nose= lect, > ;; 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=C2=B4t know what else to use. It would be nice if things like this would be mentioned in the documentation ... --=20 Knowledge is volatile and fluid. Software is power.