From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jambunathan K Newsgroups: gmane.emacs.help Subject: Re: replacing a function with another one Date: Wed, 12 Mar 2014 18:46:26 +0530 Message-ID: <87eh27iml1.fsf@gmail.com> References: <87vbvofsi6.fsf@yun.yagibdah.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: ger.gmane.org 1394630186 27927 80.91.229.3 (12 Mar 2014 13:16:26 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 12 Mar 2014 13:16:26 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Mar 12 14:16:33 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 1WNj1N-0003Do-6M for geh-help-gnu-emacs@m.gmane.org; Wed, 12 Mar 2014 14:16:33 +0100 Original-Received: from localhost ([::1]:60569 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNj1M-0000EC-Nh for geh-help-gnu-emacs@m.gmane.org; Wed, 12 Mar 2014 09:16:32 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:54969) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNj12-0008Vq-S3 for help-gnu-emacs@gnu.org; Wed, 12 Mar 2014 09:16:21 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WNj0u-0001MA-AN for help-gnu-emacs@gnu.org; Wed, 12 Mar 2014 09:16:12 -0400 Original-Received: from mail-pa0-x22c.google.com ([2607:f8b0:400e:c03::22c]:48916) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WNj0u-0001Lm-49 for help-gnu-emacs@gnu.org; Wed, 12 Mar 2014 09:16:04 -0400 Original-Received: by mail-pa0-f44.google.com with SMTP id bj1so1084626pad.17 for ; Wed, 12 Mar 2014 06:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:references:date:in-reply-to:message-id:user-agent :mime-version:content-type; bh=AWbO9Iu133I7JB2XBEJAwYAoKelV9mVy4acW46L/jdY=; b=GOG1HWqPMVBffTLnPnN0ONdCZWzhbA5qNEF3HkpNbt41exzZnxk5o1WWGIswfgh2F0 3DGgla/B5hOW+mMmpWwIJ87yDWYp0AGtc9LZThrWL2V4md6XIxVTmisKRGQnikjcr6BE MtGC2KnwhhjaR1WMQzGhI/eL5Kr9OlCTD11UX7c1FuC+ww2G+fnzQPCB721YpHzwUp9d lttaiPsENndvubPFvqy4rPPQTd1oFypKSQMooX7sTWyzEha3n1iiP0fmlJKzUOkvlSV2 iSl9orY/2iFTbt5zPZqA/rrxn+U0HQm4dy2ulO1DRpZ7HhNND8I3xuRFI5il+ILHrxJv KlBw== X-Received: by 10.66.119.172 with SMTP id kv12mr4901416pab.34.1394630163290; Wed, 12 Mar 2014 06:16:03 -0700 (PDT) Original-Received: from debian-6.05 ([115.242.198.125]) by mx.google.com with ESMTPSA id ei4sm7151271pbb.42.2014.03.12.06.16.00 for (version=TLSv1.1 cipher=RC4-SHA bits=128/128); Wed, 12 Mar 2014 06:16:02 -0700 (PDT) In-Reply-To: <87vbvofsi6.fsf@yun.yagibdah.de> (lee@yun.yagibdah.de's message of "Sat, 08 Mar 2014 20:43:36 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:400e:c03::22c 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:96454 Archived-At: --=-=-= Content-Type: text/plain Hello OP, It seems you don't mind digging in to elisp code. 1. Put the following snippet (see below) in to your .emacs. 2. Restart emacs 3. C-x C-f somefile.txt 4. M-x add-file-local-variable RET hi-lock-patterns-file RET "somefile.patterns" 5. C-x C-v 6. Highlight some strings here and there 7. Make some modifications to the file 8. C-x C-s Now, 1. C-x C-f somefile.txt. 2. You should see the highlights. When you highlight some text, the buffer is considered as *not* modified. So after-save-hook will not be called if there are no actual modifications in the current session. In that case, you can force a write of the patterns file with M-x hi-lock-file-save-patterns See the attached sample files for what I mean. ---------------------------------------------------------------- (add-hook 'find-file-hook 'hi-lock-find-file-hook) (add-hook 'after-save-hook 'hi-lock-file-save-patterns) (defun hi-lock-find-file-hook () (when (and (boundp 'hi-lock-patterns-file) (file-readable-p hi-lock-patterns-file)) (let ((patterns (with-current-buffer (find-file-noselect hi-lock-patterns-file) (goto-char (point-min)) (prog1 (ignore-errors (read (current-buffer))) (kill-buffer))))) (setq hi-lock-interactive-patterns patterns) (font-lock-add-keywords nil hi-lock-interactive-patterns t)))) (defun hi-lock-file-save-patterns () (interactive) (when (boundp 'hi-lock-patterns-file) (let ((patterns (append hi-lock-file-patterns hi-lock-interactive-patterns))) (with-current-buffer (find-file-noselect hi-lock-patterns-file) (erase-buffer) (insert (pp-to-string patterns)) (save-buffer 0))))) ---------------------------------------------------------------- --=-=-= Content-Type: application/octet-stream Content-Disposition: attachment; filename=somefile.patterns Content-Transfer-Encoding: base64 KCgiXFxfPGdvb2RieWVcXF8+IgogICgwICdoaWdobGlnaHQtMyBwcmVwZW5kKSkKICgiXFxfPHdv cmxkXFxfPiIKICAoMCAnaGlnaGxpZ2h0LTIgcHJlcGVuZCkpCiAoIlxcXzxoZWxsb1xcXz4iCiAg KDAgJ2hpZ2hsaWdodC0xIHByZXBlbmQpKSkK --=-=-= Content-Type: text/plain Content-Disposition: attachment; filename=somefile.txt hello world goodbye world ;; Local Variables: ;; hi-lock-patterns-file: "somefile.patterns" ;; End: --=-=-=--