[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newby trying to do a macro key binding, I think

From: harven
Subject: Re: Newby trying to do a macro key binding, I think
Date: Wed, 18 Nov 2009 10:11:48 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.1 (darwin)

Paul Heinrich Dietrich <address@hidden> writes:

> How do you write the code for a macro and key binding (I think that's how to
> do it) in your .emacs file so that you can hit a key, say f5, and the
> following command is automatically entered:
> C-x d /address@hidden:/home/directory/path/

If you want to put it in your .emacs file, it is probably faster
to write a bit of elisp code.

(global-set-key (kbd "<f5>") (lambda () (interactive)
         (dired "/address@hidden:/home/directory/path/")))

If you never wrote elisp code, take the first line for granted, it binds
the key f5 to the instructions that come next. C-x d calls the command dired.
When you want to know what command is bound to the shortcut C-x d, just type

                            C-h k C-x d 

You will get the name and syntax of the command together with a few informations
that, hopefully, are sufficient to write the code you need.

> I've tried a billion variations on a theme, but can't get it to work.  For
> example, I tried
> C-x (C-x d /address@hidden:/home/directory/path/C-x)
> and I forget the routine now, but did something with kbd and names and
> managed to get the code into my .emacs file.  The first problem is that the
> main part of it (/address@hidden:/home/directory/path/) wouldn't appear
> because as I created the macro, Emacs tried to suggest a path that was
> wildly different, so I had to backspace about 15 times and then type it, but
> when I get the macro code into the .emacs file, all I see are a lot of
> backspace backspace backspace...and no path.
> No biggee, so I tried putting quotes around it, ?\ in front of it, etc.
> What did I do wrong?  Go easy, I'm in the earliest learning stages of Emacs.

If something goes wrong, you can edit the current macro with
                      M-x edit-kbd-macro RET
You can then change the path (erase the backspace lines, whatever) 
and get it right.

> Next, I'm guessing I want to use a key binding.  Let's say I called the
> macro pathfinder.  I think I would establish the key binding like this:
> (global-set-key "\C-c a") 'pathfinder)
> or
> ;(global-set-key [f5] 'pathfinder)
> depending on whether I want to call it with f5 or C-c a. 

well, I think it depends on your emacs flavor.
(global-set-key (kbd "C-c a") 'pathfinder)  
(global-set-key (kbd "<f5>")  'pathfinder)  
would have worked for me ( gnu emacs version > 21 ).

reply via email to

[Prev in Thread] Current Thread [Next in Thread]