all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* global-set-key in text-mode
@ 2008-02-20 16:53 educkworth
  2008-02-20 18:24 ` Joel J. Adamson
  0 siblings, 1 reply; 5+ messages in thread
From: educkworth @ 2008-02-20 16:53 UTC (permalink / raw)
  To: help-gnu-emacs

I have the following key binding in my .emacs file

(global-set-key "\M-s" 'save-buffer)

and it works in most major modes, but not in text-mode.  Can anyone
explain to me why this is and/or teach me how to make it work there.

Thanks,


Ethan




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

* Re: global-set-key in text-mode
  2008-02-20 16:53 global-set-key in text-mode educkworth
@ 2008-02-20 18:24 ` Joel J. Adamson
  2008-02-20 19:01   ` educkworth
  0 siblings, 1 reply; 5+ messages in thread
From: Joel J. Adamson @ 2008-02-20 18:24 UTC (permalink / raw)
  To: help-gnu-emacs

educkworth@loyola.edu writes:

> I have the following key binding in my .emacs file
>
> (global-set-key "\M-s" 'save-buffer)

Notice the word "global" at the beginning of the function
`global-set-key'.  This means that it gets overridden by special modes.
The mode is buffer-local, meaning that if you switch to another major
mode, the binding is still there.  What you want to do is redefine it
for text mode: there's a great explanation of how to fix keybindings
that inadvertently get reset by major modes in Chapter 11, section
"Customizing Existing Modes" of _Learning GNU Emacs_ from O'Reilly.

Here's a summary:

(add-hook 'text-mode-hook
          '(lambda ()
                   (define-key text-mode-map "\M-s" 'save-buffer)))


Try "M-x describe-mode" for a listing of keybindings.  "\M-x where-is"
also tells you the keybinding of any command.

HTH,
Joel
-- 
Joel J. Adamson
Biostatistician
Pediatric Psychopharmacology Research Unit
Massachusetts General Hospital
Boston, MA  02114
(617) 643-1432
(303) 880-3109


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

* Re: global-set-key in text-mode
  2008-02-20 18:24 ` Joel J. Adamson
@ 2008-02-20 19:01   ` educkworth
  2008-02-20 19:04     ` educkworth
  0 siblings, 1 reply; 5+ messages in thread
From: educkworth @ 2008-02-20 19:01 UTC (permalink / raw)
  To: help-gnu-emacs

>
> (add-hook 'text-mode-hook
>           '(lambda ()
>                    (define-key text-mode-map "\M-s" 'save-buffer)))
>

Thanks, but this doesn't work for me.  M-s, in text-mode, is still
bound to center line.

I'll browse the manuals a little more about keymaps, define-key, etc.

Ethan




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

* Re: global-set-key in text-mode
  2008-02-20 19:01   ` educkworth
@ 2008-02-20 19:04     ` educkworth
  2008-02-24  6:12       ` Dave Benjamin
  0 siblings, 1 reply; 5+ messages in thread
From: educkworth @ 2008-02-20 19:04 UTC (permalink / raw)
  To: help-gnu-emacs

I've gotten it to work through dumb trial and error.  I didn't use the
add-hook command, just a straight

(define-key text-mode-map "\M-s" 'save-buffer)

in my .emacs.

Thanks for steering me in the right direction.

Ethan




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

* Re: global-set-key in text-mode
  2008-02-20 19:04     ` educkworth
@ 2008-02-24  6:12       ` Dave Benjamin
  0 siblings, 0 replies; 5+ messages in thread
From: Dave Benjamin @ 2008-02-24  6:12 UTC (permalink / raw)
  To: help-gnu-emacs

educkworth@loyola.edu wrote:
> I've gotten it to work through dumb trial and error.  I didn't use the
> add-hook command, just a straight
> 
> (define-key text-mode-map "\M-s" 'save-buffer)
> 
> in my .emacs.
> 
> Thanks for steering me in the right direction.

FWIW, I have the following in my .emacs:

;; keep text-mode from stealing M-s key binding
(define-key text-mode-map "\es" nil)
(define-key text-mode-map "\eS" nil)

This way, my global binding works as intended.

Dave


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

end of thread, other threads:[~2008-02-24  6:12 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-02-20 16:53 global-set-key in text-mode educkworth
2008-02-20 18:24 ` Joel J. Adamson
2008-02-20 19:01   ` educkworth
2008-02-20 19:04     ` educkworth
2008-02-24  6:12       ` Dave Benjamin

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.