[gnu.emacs] simple question: global-set-key

holtz@csmil.umich.edu (Brian Holtz) (02/07/90)

How do I reset a keymap entry to a function with an argument?

When I do

(global-unset-key "\C-o")

(global-set-key "\C-of" 'x-set-font)
(global-set-key "\C-og" 'goto-line)
(global-set-key "\C-oh" 'help-command)
(global-set-key "\C-om" 'set-mark-command)
(global-set-key "\C-on" 'search-forward-regexp)
(global-set-key "\C-oq" 'quoted-insert)
(global-set-key "\C-op" 'search-backward-regexp)
(global-set-key "\C-or" 'replace-regexp)
(global-set-key "\C-os" 'save-buffer)
(global-set-key "\C-ot" 'recenter 0)     ;; WITH ARGUMENT

the last global-set-key doesn't take.

mikem+@ANDREW.CMU.EDU (Michael Meyer) (02/07/90)

> Excerpts from internet.info-gnu-emacs: 6-Feb-90 simple question:
> global-set.. Brian Holtz@csmil.umich. (569)

> How do I reset a keymap entry to a function with an argument?

> (global-set-key "\C-os" 'save-buffer)
> (global-set-key "\C-ot" 'recenter 0)     ;; WITH ARGUMENT

> the last global-set-key doesn't take.


Here is what I do
(define-key esc-map "!" '(lambda (arg) (interactive "p") (recenter 0)))
I'd be happy to see a better solution (but this one works).
--Mike

jym@APPLE.COM (02/08/90)

> Here is what I do
> (define-key esc-map "!" '(lambda (arg) (interactive "p") (recenter 0)))
> I'd be happy to see a better solution (but this one works).

You can, of course, use global-set-key as well:

(global-set-key "\C-ot" '(lambda (arg) (interactive "p") (recenter 0)))

Formally creating a function is "better" if you'd like to take
 advantage of Emacs' self-documenting features:

(defun my-recenter (arg)
  "Puts current line to top of window."
  (interactive "p")
  (recenter 0) )
;defun;

(global-set-key "\e?" 'my-recenter)

:::.-----.::: <_Jym_> ::::::::::::::::::::::::::::::::::.-----.:::
::/   |   \:::::::::::::::::::::::::::::::: Jym Dyer ::/  o o  \::
::\  /|\  /::::::::::::::::::::::: nli!jym@apple.com ::\ \___/ /::
:::`-----':::::::::::::::::: Berserkeley, California :::`-----':::