From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Michael Heerdegen Newsgroups: gmane.emacs.help Subject: Re: replacing a function with another one Date: Sun, 09 Mar 2014 23:02:05 +0100 Message-ID: <87eh2b6nfm.fsf@web.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> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1394402557 23686 80.91.229.3 (9 Mar 2014 22:02:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 9 Mar 2014 22:02:37 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 09 23:02:45 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 1WMlnx-0006mG-9R for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Mar 2014 23:02:45 +0100 Original-Received: from localhost ([::1]:45663 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMlnw-0005bO-Rj for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Mar 2014 18:02:44 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51612) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMlnf-0005bI-8p for help-gnu-emacs@gnu.org; Sun, 09 Mar 2014 18:02:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WMlnY-000283-T3 for help-gnu-emacs@gnu.org; Sun, 09 Mar 2014 18:02:27 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:38604) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMlnY-00027v-NB for help-gnu-emacs@gnu.org; Sun, 09 Mar 2014 18:02:20 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WMlnW-0006Sj-6o for help-gnu-emacs@gnu.org; Sun, 09 Mar 2014 23:02:18 +0100 Original-Received: from ip-90-187-97-239.web.vodafone.de ([90.187.97.239]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 09 Mar 2014 23:02:18 +0100 Original-Received: from michael_heerdegen by ip-90-187-97-239.web.vodafone.de with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 09 Mar 2014 23:02:18 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 73 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: ip-90-187-97-239.web.vodafone.de User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) Cancel-Lock: sha1:/nPC1MitCO/ezEN6F2aaGuJ8tKg= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:96365 Archived-At: lee writes: > So I guess should use advice-add instead --- and I can´t figure out how > to get that to work. I need to access the argument passed to the > function the advice is for, too. I tried to find examples, without > success. IMHO the best description how the advice types work is in C-h f add-function. > What I have is: > > > (defadvice hi-lock-set-file-patterns (after > lsl-hi-lock-set-file-patterns-advice activate) > (setq hi-lock-interactive-patterns (ad-get-arg 0))) > How would I do the same with add-advice (or whatever is appropriate)? (advice-add 'hi-lock-set-file-patterns :after (lambda (patterns) (setq hi-lock-interactive-patterns patterns))) You can also give the piece of advice a name like in defadvice: (advice-add 'hi-lock-set-file-patterns :after (lambda (patterns) (setq hi-lock-interactive-patterns patterns)) '((name . lsl-hi-lock-set-file-patterns-advice))) But you can instead just name the function instead of using an anonymous one: (defun my-hi-lock-set-file-patterns-after-ad (patterns) (setq hi-lock-interactive-patterns patterns)) (advice-add 'hi-lock-set-file-patterns :after 'my-hi-lock-set-file-patterns-after-ad) The advantage is that advices are functions with the new implementation, so referring to arguments and return values works transparently, instead of the need of using obscure pseudo variables. See C-h f add-function to learn how the other advice types work. > Yes, that´s exactly what I´m trying to avoid. There is no way to detect > when something changes in hi-lock.el in such a way that what I´m doing > doesn´t work anymore, or is there? No, not direct way. > Suddenly finding out that what I´m trying to do doesn´t work anymore > won´t be so great. Indeed. But if you only rely on documented behavior (docstring), the risk is low, since changes are backwards compatible most of the time. > One change I´m thinking about is keeping the highlighting-patterns in a > separate buffer and applying them to several buffers. That way, you can > have several files that all use the same highlighting-patterns which > were generated on the fly, centralised for the whole project (or some > files of it). That´ll probably require quite a few modifications. Don't hesitate to ask when you've questions, but I think you're on a good way. Regards, Michael.