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: Mon, 10 Mar 2014 03:18:39 +0100 Message-ID: <87wqg2u77k.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> <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: 8bit X-Trace: ger.gmane.org 1394417951 5463 80.91.229.3 (10 Mar 2014 02:19:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 10 Mar 2014 02:19:11 +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 03:19:19 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 1WMpoF-00026K-7I for geh-help-gnu-emacs@m.gmane.org; Mon, 10 Mar 2014 03:19:19 +0100 Original-Received: from localhost ([::1]:46409 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMpoE-00054K-QH for geh-help-gnu-emacs@m.gmane.org; Sun, 09 Mar 2014 22:19:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56855) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMpny-00054D-MT for help-gnu-emacs@gnu.org; Sun, 09 Mar 2014 22:19:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WMpns-0003rZ-Gd for help-gnu-emacs@gnu.org; Sun, 09 Mar 2014 22:19:02 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:55216) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WMpns-0003rV-AR for help-gnu-emacs@gnu.org; Sun, 09 Mar 2014 22:18:56 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WMpnr-0001n0-JJ for help-gnu-emacs@gnu.org; Mon, 10 Mar 2014 03:18:55 +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 ; Mon, 10 Mar 2014 03:18:55 +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 ; Mon, 10 Mar 2014 03:18:55 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 82 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:W8qtuDUl6dTfDBL+NIcCIHD7E5U= 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:96372 Archived-At: lee writes: > Thank you! It seems rather complicated --- I´ll look into it tomorrow > and try to figure it out. Actually, it's only abstract, but quite simple. About the original question you raised (not forgetting patterns), would something like this do what you want: (advice-add 'hi-lock-write-interactive-patterns :around ;; also include `hi-lock-file-patterns' (lambda (f &rest args) (let ((hi-lock-interactive-patterns (append hi-lock-interactive-patterns hi-lock-file-patterns)))) (apply f args))) > It´s 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´m 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 activate) > (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-at-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´t like this. It´s a really terrible hack. I'm not sure I completely understand what you are trying to do. Generally, you could use directory local variables for storing your patterns, but these would of course not be automatically updated, what you presumably want. Nitpick: instead of activating and deactivating pieces of advice, define a variable and use it as a flag. The flag says whether the advice should kick in. In the advice's body, look at the variable and decide what to do. > 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 ... Yes, that should work fine. But you can anytime combine any number of advices into one around advice. Michael.