unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* How do I bind a macro to a key?
@ 2003-10-10  1:40 Dan Anderson
  0 siblings, 0 replies; 3+ messages in thread
From: Dan Anderson @ 2003-10-10  1:40 UTC (permalink / raw)


Is it possible to create a macro and bind it to a key (or set of keys)
for the rest of the session?  Sometimes when programming I'll find I
need like 5 separate macros, and I don't know how to C-x e each one
separately except for creating one, running down the code and running
it, and creating another.  This seems very inefficient.  Is there a
better way?

Thanks in advance,

Dan

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do I bind a macro to a key?
       [not found] <mailman.1454.1065750051.21628.help-gnu-emacs@gnu.org>
@ 2003-10-10  4:04 ` roodwriter
  2003-10-15  8:10 ` David Vanderschel
  1 sibling, 0 replies; 3+ messages in thread
From: roodwriter @ 2003-10-10  4:04 UTC (permalink / raw)


Dan Anderson wrote:

> Is it possible to create a macro and bind it to a key (or set of keys)
> for the rest of the session?  Sometimes when programming I'll find I
> need like 5 separate macros, and I don't know how to C-x e each one
> separately except for creating one, running down the code and running
> it, and creating another.  This seems very inefficient.  Is there a
> better way?
> 
> Thanks in advance,
> 
> Dan

Sure. After you create your macro name it with:

M-x name-last-kbd-macro

Give it a name and it becomes a command beginning with the usual M-x.

If you want to go one step further and come up with a shortcut, use:

M-x global-set-key

That'll bind it to whatever shortcut you like. Emacs already has a bunch of 
shortcuts set aside for assignment. They begin with C-c and then a letter.

Unless you actually save these macros and shortcuts by inserting them into a 
file, they disappear when you close Emacs.

Enjoy!

--Rod

-- 
Author of "Linux for Non-Geeks--Clear-eyed Answered for Practical Consumers" 
and "Boring Stories from Uncle Rod." Both are available at 
http://www.rodwriterpublishing.com/index.html

To reply by e-mail, take the extra "o" out of the name.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: How do I bind a macro to a key?
       [not found] <mailman.1454.1065750051.21628.help-gnu-emacs@gnu.org>
  2003-10-10  4:04 ` roodwriter
@ 2003-10-15  8:10 ` David Vanderschel
  1 sibling, 0 replies; 3+ messages in thread
From: David Vanderschel @ 2003-10-15  8:10 UTC (permalink / raw)


"Dan Anderson" <dan@mathjunkies.com> in message
news:<mailman.1454.1065750051.21628.help-gnu-emacs@gnu.org> wondered:
> Is it possible to create a macro and bind it to a key (or set of keys)
> for the rest of the session?  ...

I do that so frequently that (many years ago) I
created a function to facilitate the operation:

(defun dv-functionize-kbd-macro (sym) "Make 'function' of kbd macro."
  (interactive "SName for last kbd macro and the 'function': ")
  (name-last-kbd-macro sym)
  (insert ";;  \n;;  \n")
  (insert-kbd-macro sym)
  (insert "(global-set-key \[")
  (save-excursion
    (insert (concat "\] '" (symbol-name sym) ")\n\n"))
    (fill-region (re-search-backward "^(") (re-search-backward "^ "))))
(global-set-key [f12 ?m] 'dv-functionize-kbd-macro)

I usually do it in a file which is loaded as part of
my initialization, so the 'function' derived from the
macro is not just for the current session.

Regards,
  David V.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-10-15  8:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-10  1:40 How do I bind a macro to a key? Dan Anderson
     [not found] <mailman.1454.1065750051.21628.help-gnu-emacs@gnu.org>
2003-10-10  4:04 ` roodwriter
2003-10-15  8:10 ` David Vanderschel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).