From: Mathias Dahl <brakjoller@gmail.com>
Subject: Re: Execute as a command a yanked text
Date: Thu, 04 May 2006 10:03:30 +0200 [thread overview]
Message-ID: <u7j52tdwt.fsf@gmail.com> (raw)
In-Reply-To: mailman.1290.1146675647.9609.help-gnu-emacs@gnu.org
Stefan Horomnea <stefan@softexperience.ro> 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
next prev parent reply other threads:[~2006-05-04 8:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <E1FbJqy-0005FO-Rm@host1.softexperience.ro>
2006-05-03 17:01 ` Execute as a command a yanked text Stefan Horomnea
2006-05-03 18:38 ` Peter Dyballa
2006-05-03 19:52 ` Reiner Steib
[not found] ` <mailman.1290.1146675647.9609.help-gnu-emacs@gnu.org>
2006-05-04 8:03 ` Mathias Dahl [this message]
[not found] <E1FbCwb-0004RK-WD@host1.softexperience.ro>
2006-05-03 9:12 ` Stefan Horomnea
[not found] ` <mailman.1260.1146647515.9609.help-gnu-emacs@gnu.org>
2006-05-03 9:35 ` Mathias Dahl
2006-05-03 9:56 ` David Kastrup
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=u7j52tdwt.fsf@gmail.com \
--to=brakjoller@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.