From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Sebastian Tennant Newsgroups: gmane.emacs.help Subject: Re: Macro used for dynamic setting of font-lock-keywords Date: Mon, 28 May 2007 12:22:44 +0300 Message-ID: <87sl9he1zv.fsf@moley.org> References: <874pm0573o.fsf@lion.rapttech.com.au> <87lkfb4nj4.fsf@lion.rapttech.com.au> <87d50n3pvk.fsf@lion.rapttech.com.au> <200705272145.l4RLjHGn005421@localhost.localdomain> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1180344109 1965 80.91.229.12 (28 May 2007 09:21:49 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 28 May 2007 09:21:49 +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 May 28 11:21:48 2007 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1HsbQB-0001PB-G9 for geh-help-gnu-emacs@m.gmane.org; Mon, 28 May 2007 11:21:47 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HsbQA-0006P1-2T for geh-help-gnu-emacs@m.gmane.org; Mon, 28 May 2007 05:21:46 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HsbPX-0006Ng-IR for help-gnu-emacs@gnu.org; Mon, 28 May 2007 05:21:07 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HsbPV-0006M3-VS for help-gnu-emacs@gnu.org; Mon, 28 May 2007 05:21:06 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HsbPV-0006Ll-QF for help-gnu-emacs@gnu.org; Mon, 28 May 2007 05:21:05 -0400 Original-Received: from main.gmane.org ([80.91.229.2] helo=ciao.gmane.org) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HsbPU-0000po-JO for help-gnu-emacs@gnu.org; Mon, 28 May 2007 05:21:05 -0400 Original-Received: from list by ciao.gmane.org with local (Exim 4.43) id 1HsbPI-00020X-Gq for help-gnu-emacs@gnu.org; Mon, 28 May 2007 11:20:52 +0200 Original-Received: from 85.105.17.65 ([85.105.17.65]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 May 2007 11:20:52 +0200 Original-Received: from sebyte by 85.105.17.65 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 28 May 2007 11:20:52 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 53 Original-X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 85.105.17.65 User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/22.0.95 (gnu/linux) Cancel-Lock: sha1:byItWm6kgCeoqWxyLwAVKuWex1M= X-detected-kernel: Linux 2.6, seldom 2.4 (older, 4) X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:44503 Archived-At: Quoth Xavier Maillard : > Hi, > > seem to get used as often as it probably should. I've seen people post 20+ > lines of elisp to this list to do something which could be achieved more > reliably with 4 or five lines of defadvice. > > Advice is considered as *dangerous* and not to be used extensively. > Indeed this is what I've been lead to believe. I think RMS' position on defadvice, which confirms this, is knocking about somewhere. IMHO macros (at a user-level) are useful whenever you would otherwise repeat yourself. For example, I like to keep technical notes in a ~/tech-notes directory and quotes in a ~/quotes directory. Rather than write an interactive command for each I wrote a macro which I called commandir: (defmacro commandir (call pmt dir def) `(defun ,call () (interactive) (let (checked-dir filename) ;; checked-dir will always ends with a '/' (setq checked-dir (file-name-as-directory ,dir)) ;;accept user input (setq filename (read-file-name ,pmt checked-dir)) (when (equal filename "") (setq filename ,def)) ;;read file or create new buffer if file does not exist ;;(buffer is automatically selected for editing) (find-file (concat checked-dir filename) nil) . . . I can now 'build' as many functions as I like, each providing quick access to the contents of my various directories, with simple macro calls like this one in my ~/.emacs file: (commandir tn "Tech note: " "~/tech-notes" "misc") Then it is a case of simply typing:: M-x tn and I am prompted for a filename (with filename completion based on the contents of ~/tech-notes"). If I enter the name of an exisitng file, that file is visited, if I enter a non-existing file name, that file will be created when the buffer is saved, and if I don't type anything, ~/tech-notes/misc is visited. Very handy indeed! Sebastian