all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / 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 ` How do I bind a macro to a key? 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 --
     [not found] <mailman.1454.1065750051.21628.help-gnu-emacs@gnu.org>
2003-10-10  4:04 ` How do I bind a macro to a key? roodwriter
2003-10-15  8:10 ` David Vanderschel
2003-10-10  1:40 Dan Anderson

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.