Var87
Var87

Reputation: 569

How to turn off standard osx text editing bindings in emacs on OSX

I want to not have any standard osx text editing bindings available in emacs anymore. I'm using standard gnu emacs. leaving only the "old school" emacs commands. In other words: no more command+c for copy, no command+z for undo, etc. Is there some way to do this without explicitly rebinding each key combination? I tried googling for a way to do this but did not find anything.

Upvotes: 1

Views: 426

Answers (3)

Shannon Severance
Shannon Severance

Reputation: 18410

The keybindings I find objectionable are the bindings to SUPER aka command. To disable these binding, though not all the NS bindings made:

File global-unset-all-super-key.el:

(defun global-unset-all-super-key ()
  "Will unset any single key in global keymap that has the super
modifier."
  (let ((km (current-global-map)))
    (while km
      (let ((maybe-event (and (listp (car km))
                              (caar km))))
        (if (and (eventp maybe-event) ; Also filters maybe-event when
                                      ; nil because (car km) was not a list.
                 (memq 'super (event-modifiers maybe-event)))
            (global-unset-key (vector maybe-event))))
      (setq km (cdr km)))))

(provide 'global-unset-all-super-key)

Place global-unset-all-super-key.el in the Emacs lisp load path and add the following to init.el or .emacs:

;; Remove default super bindings on Mac systems.
;; Do this early, before any mappings are added.
(when (string-equal system-type "darwin")
  (require 'global-unset-all-super-key)
  (global-unset-all-super-key))

Upvotes: 1

Lindydancer
Lindydancer

Reputation: 26134

In Emacs in OS X, the default setup is that the CMD key is bound to the SUPER qualifier, and the a number of keys like S-x, S-c, and S-v are bound to commands to minic the normal OS functions. The OPTION key is bound to META. Unfortunately, the basic setup doesn't allow you to type characters that normally would require the OPTION key, like "|" and "\".

The following will bind CMD to meta and make OPTION available for normal character composition.

(if (boundp 'ns-command-modifier)
    (setq ns-command-modifier 'meta))

(if (boundp 'ns-option-modifier)
    (setq ns-option-modifier nil))

Upvotes: 1

legoscia
legoscia

Reputation: 41618

These key bindings are defined here, in ns-win.el.

There seems to be no simple way to unbind all of them. You could copy all of those key bindings from ns-win.el into the scratch buffer. They look like this:

(define-key global-map [?\s-,] 'customize)

Then hit C-M-% for query-replace-regexp, type ^(define-key global-map \(.*\) '.*)$ as the search expression and (global-unset-key \1) as the replacement, turning those key bindings into:

(global-unset-key [?\s-,])

Then, select them all and type M-x eval-region.

Upvotes: 2

Related Questions