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: Mon, 10 Mar 2014 01:53:34 +0100 Organization: my virtual residence Message-ID: <87r46anab5.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> 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 1394412840 24279 80.91.229.3 (10 Mar 2014 00:54:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Mar 2014 00:54:00 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Mar 10 01:54:08 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 1WMoTn-0006kU-P8 for geh-help-gnu-emacs@m.gmane.org; Mon, 10 Mar 2014 01:54:07 +0100 Original-Received: from localhost ([::1]:46258 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMoTn-0005mV-EL for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Mar 2014 20:54:07 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:48237) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMoTY-0005lS-2F for help-gnu-emacs@gnu.org; Sun, 09 Mar 2014 20:53:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WMoTT-0007GD-08 for help-gnu-emacs@gnu.org; Sun, 09 Mar 2014 20:53:52 -0400 Original-Received: from client-194-42-186-216.muenet.net ([194.42.186.216]:51375 helo=yun.yagibdah.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMoTS-0007G3-PD for help-gnu-emacs@gnu.org; Sun, 09 Mar 2014 20:53:46 -0400 Original-Received: from lee by yun.yagibdah.de with local (Exim 4.80.1) (envelope-from ) id 1WMoTN-0001UU-UZ for help-gnu-emacs@gnu.org; Mon, 10 Mar 2014 01:53:41 +0100 In-Reply-To: <87eh2b6nfm.fsf@web.de> (Michael Heerdegen's message of "Sun, 09 Mar 2014 23:02:05 +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:96368 Archived-At: Michael Heerdegen writes: > lee writes: >> >> (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: > [...] Thank you! It seems rather complicated --- I=C2=B4ll look into it tomorrow and try to figure it out. >> Suddenly finding out that what I=C2=B4m trying to do doesn=C2=B4t work a= nymore >> won=C2=B4t 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. /How/ the functions I=C2=B4m advising do their work may change even when th= ey still do the same thing --- like a variable or an argument I=C2=B4m using might change or no longer be available ... >> One change I=C2=B4m 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=C2=B4ll probably require quite a few modifications. > > Don't hesitate to ask when you've questions, but I think you're on a > good way. It=C2=B4s somewhat frustrating when you have to figure out how things work and stare at error messages that make you ask what they are supposed to tell you --- but I=C2=B4m learning :) So far, I figured out this: (defvar patterns-other-buffer nil) (defvar original-buffer nil) (defadvice hi-lock-set-file-patterns (after my-test-obtain-patterns) (setq patterns-other-buffer (ad-get-arg 0)) (ad-deactivate 'hi-lock-set-file-patterns) (pop-to-buffer original-buffer) (hi-lock-set-file-patterns patterns-other-buffer)) (defadvice hi-lock-find-patterns (before hi-lock-find-other-patterns activa= te) (my-test)) (defun my-test () (interactive) (ad-activate 'hi-lock-set-file-patterns) (save-excursion (save-restriction (widen) (goto-char (point-min)) (when (re-search-forward "^// ext-fontify-defs: " nil t) (message "found marker") (let ((filename (thing-at-point 'filename))) (message "filename at %d: %s/%s for buffer %s" (point) filename (thing-a= t-point 'filename) (buffer-name original-buffer)) (when filename (when (file-exists-p filename) (setq original-buffer (current-buffer)) (find-file filename) (set-auto-mode-0 'hi-lock-mode t)))))))) This actually works, i. e. it lets me save hi-lock-mode highlighting-patterns to an arbitrary file and put a line like "// ext-fontify-defs: name-of-file-with-patterns" into the file to load the highlighting-patterns from the file the name of which is specified in that line. The patterns are then applied. But I don=C2=B4t like this. It=C2=B4s a really terrible hack. Or is this the way to go (letting aside the two obvious glitches)? And I would end up with two defadvices on the same function ... but as far as I understand the documentation, that should work fine. Hm ... --=20 Knowledge is volatile and fluid. Software is power.