From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mathias Dahl Newsgroups: gmane.emacs.help Subject: Re: Execute as a command a yanked text Date: Thu, 04 May 2006 10:03:30 +0200 Message-ID: References: NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1146732115 16330 80.91.229.2 (4 May 2006 08:41:55 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 4 May 2006 08:41:55 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu May 04 10:41:54 2006 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FbZP7-0003XP-9i for geh-help-gnu-emacs@m.gmane.org; Thu, 04 May 2006 10:41:46 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FbZP6-0005cs-NY for geh-help-gnu-emacs@m.gmane.org; Thu, 04 May 2006 04:41:44 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!newsfeed.gamma.ru!Gamma.RU!newsfeed.icl.net!newsfeed.fjserv.net!newsfeed.freenet.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 78 Original-X-Trace: individual.net 20TRfEhG6wIgkPTIEQEBvwcSHCDxg6Y8LEC1MQlnd8mKHHsLRw User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (windows-nt) Cancel-Lock: sha1:TVT3yPTqPLpEf21gwmmdXvzSedo= Original-Xref: shelby.stanford.edu gnu.emacs.help:139179 Original-To: help-gnu-emacs@gnu.org 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:34801 Archived-At: Stefan Horomnea writes: > Indeed, the code > (command-execute (intern (car kill-ring-yank-pointer))) > works ! And thanks to your post I learned about `intern' :) > The complete code (which is very short) is: > ______________________ > (defun your-fun () > "helps execute a template" > (interactive) > (backward-kill-word 1) > (command-execute (intern (car kill-ring-yank-pointer))) > ) > (global-set-key [(control return)] 'stefan-fun) > ______________________ > now, if I have to enter a template, I do: htb C-RET or div C-RET etc. I like this "trick" of yours very much! These are things which I am very interested in, how to make your computer environment easier and faster to use. For your information I experimented with abbrevs in a way that you might find interesting: Most people know how abbrevs work in Emacs. You define the abbrev (the "short" word) and you define what is should expand to, and when you are in abbrev-mode, each abbrev will be expanded to the expansion as you type. Simple. Useful. One thing that I don't think all users know about is that you can also make an abbrev execute code. Example: ;; Simple function to demonstrate (defun xtst-func () (message "xtst-func was called") ;; Need to return non-`nil' in order to inhibit inserting ;; the character that triggered the expansion. See the elisp ;; manual for more information. t) ;; Needed in combination with the `t' above. Again, read the manual. (put 'xtst-func 'no-self-insert t) ;; Let the expansion be an empty string, set the HOOK argument to our ;; new function. Did I say you should read the manual? ... :) (define-abbrev lisp-mode-abbrev-table "xtst" "" 'xtst-func) ;; Enable abbrev mode (abbrev-mode 1) To test it: 1. Go to the *scratch* buffer (should be in lisp-mode) and paste the above 2. Evaluate all of the above 3. Type xtst and then space (or return, both works) The result should be that the message "xtst-func was called" is printed in the echo area and the abbrev you wrote should be gone. I actually don't *use* this for anything (yet) but I think it is interesting functionality. It is also much more complex than you clever hack. When naming the abbrevs, makes sure you pick names that you will not type by mistake, so to speak. Maybe use a prefix that is easy/quick to type, before all your "commands". Anyway, about your example: maybe you should use normal abbrevs (create one called htb, for example) that expands into the text you want to insert in your code. Or use skeletons or some other expansion/template functionality that exists in Emacs and Emacs add-ons. /Mathias