Lo, on Thursday, March 22, Oliver Elphick did write:

> "Richard C. Cobbe" wrote:
>   >Lo, on Thursday, March 22, Oliver Elphick did write:
>   >
>   >> (If it matters, I'm using xemacs 21).
>   >> 
>   >> I want to define a function key to run a macro. 
>   >> 
>   >> I can do it within a session:
>   >> 
>   >>   ESC x global-set-key RET <f9> eif-indent-buffer RET
>   >> 
>   >> but I can't get it to work in the initialisation file ~/.emacs:
>   >> 
>   >> (defalias 'eif-indent-buffer (read-kbd-macro
>   >> "ESC x mark- whole- buffer RET ESC x eif- indent- region RET"))
>   >> (global-set-key <f9> 'eif-indent-buffer)
>   >> 
>   >> 
>   >> What should I put for <f9>?  I've tried "f9", <f9>, "<f9>", (<f9>)
>   >> and it doesn't like any of them.  I can't see anything about it in
>   >> the docs either.
>   >
>   >(global-set-key [f9] 'eif-indent-buffer)
>   >
>   >See the xemacs info page, `Key Sequences' node.
>  
> In fact, that caused xemacs to hang for a long while, but your pointer to
> documentation led me to the correct answer, in the node "Programmatic
> Rebinding":
> 
>   (global-set-key 'f9 'eif-indent-buffer)

That's surprising.  According to that node, 'f9 is an abbreviation for
'(f9), which is in turn an abbreviation for [(f9)].  My solution, [f9], is
also an abbreviation for [(f9)].

This is all the stranger because I have the following in my .emacs, and
they work just fine:

(global-set-key [delete] 'delete-char)
(global-set-key [kp-delete] 'delete-char)
(global-set-key [(control m)] 'newline-and-indent)
(global-set-key [(control x) (control g)] 'goto-line)
(global-set-key [(control x) (control k)] 'rcc-save-and-kill-current-buffer)
(global-set-key [f5] 'call-last-kbd-macro)
(global-set-key [f9] 'compile)
(global-set-key [f12] 'repeat-complex-command)
(global-set-key [home] 'beginning-of-buffer)
(global-set-key [end] 'end-of-buffer)
(global-set-key [kp-home] 'rcc-beginning-of-buffer-no-mark)
(global-set-key [kp-end] 'rcc-end-of-buffer-no-mark)

My only guess is that the behavior you noticed has something to do with the
fact that you're binding a key to a macro, whereas I'm binding all of my
keys to functions.  I'd probably have written your particular situation
like this:

(defun rcc-eif-indent-buffer ()
"Indents the entire buffer according to Eiffel mode's indentation rules."
  (interactive nil)
  (eif-indent-region (point-min) (point-max)))
(global-set-key [f9] 'rcc-eif-indent-buffer)

This is a mite cleaner, and it has the advantage that it doesn't change
mark's location as it runs.  Still, your solution is perfectly valid.

Glad you got it working,

Richard

Reply via email to