6

Is there a way to tell Emacs to ignore a certain key binding and pass it to the OS unmodified? Eg. I am typing German from time to time and use Alt+u o to type ö in OS X apps.

With Alt set to Meta I would like to tell emacs to ignore the M-u binding, so that I can use M-u o to enter ö as in other applications. (global-unset-key (kbd "M-u")) does remove the binding from emacs, but pressing M-u does nothing, instead of adding an umlaut to the next pressed character.

1
  • The current defaults makes sense for US keyboards, but not for european. When I was acting as the NS-port maintainer I tried to change the defaults to better suit european keyboards but I didn't manage to get the idea accepted. See etc/TODO under NeXTstep port / Open issues for more information. Aug 20 '16 at 19:19
7

When Emacs is built --with-ns for OSX operating systems, the user has configuration options to disable the left and/or right meta key to achieve default OS behavior: ns-alternate-modifier for the left alt/option key, and ns-right-alternate-modifier for right alt/option key.

I keep the left alt/option key as meta and disable the right alt/option key within Emacs so that I can write in foreign languages (taking advantage of default OS behavior with the right alt/option key). Here are my settings for Emacs for OSX and Windows.

(cond
  ((eq system-type 'darwin)
    (setq ns-alternate-modifier 'meta)
    (setq ns-right-alternate-modifier 'none)
    (setq ns-command-modifier 'super)
    (setq ns-right-command-modifier 'left)
    (setq ns-control-modifier 'control)
    (setq ns-right-control-modifier 'left)
    (setq ns-function-modifier 'none))
  ((eq system-type 'windows-nt)
    (setq w32-pass-lwindow-to-system nil)
    (setq w32-pass-rwindow-to-system nil)
    (setq w32-lwindow-modifier 'super)
    (setq w32-rwindow-modifier 'super)))
3
  • And on OSX you can place this on ~/.emacs.d/customizations/stuff.el Jul 29 '17 at 23:18
  • 2
    @MicaelNussbaumer -- In the generic / vanilla build of Emacs for OSX --with-ns, there is no default location for a folder named customizations inside` the .emacs.d folder, nor does Emacs check for the existence of any file named stuff.el or any other filename inside a customizations directory. Perhaps this is an Aquamacs or Spacemacs something or other? In the generic build of Emacs for OSX (i.e., --with-ns), the default location for user customizations is .emacs or init.el or default.el -- see: gnu.org/software/emacs/manual/html_node/emacs/Init-File.html
    – lawlist
    Jul 30 '17 at 1:22
  • Ah, I add just gone through Clojure for the brave and true and it was stored there, but probably along the process it set that folder to be the default. Anyway I've put it there along the other customisations in order to make it work Aug 8 '17 at 22:51
0

The problem is that, for Emacs, keys call commands. Even simple events like entering characters are calling commands: every time you go to enter "o", for example, you are, in fact, calling self-insert-command (try hitting C-h k o to read about it).

For your case, the problem is that Emacs will ignore M-u (because you told it to) and see only the "o" keypress -- not the "ö" you think you're sending.

Instead, we can bind the sequence M-u o to insert "ö".

Usually, you can pass a string in place of a command to have it inserted:

(global-set-key (kbd "M-u o") "kittens")

It seems like we should be able to do this:

(global-set-key (kbd "M-u o") "ö")

But I get an odd error on my machine when I do it, so we're going with a more circuitous route:

(global-set-key (kbd "M-u o")
                (lambda ()
                  "Insert ö."
                  (interactive)
                  (insert "ö")))

(global-set-key (kbd "M-u O")
                (lambda ()
                  "Insert Ö."
                  (interactive)
                  (insert "Ö")))

Doing that for all of the characters is bound to get tedious, of course. Instead, you might consider using input methods, especially the TeX input method. See, for example, Olé! Diacritics in Emacs (from Mickey Petersen's Mastering Emacs).

3
  • Not really an answer to the question, but it does presumably help by telling the OP how to insert the character using Emacs.
    – Drew
    Aug 19 '16 at 22:35
  • Putting a binding in the global map to insert characters is not a good idea. That makes the characters unavailable in many contexts, e.g. incremental search. Instead, use key-translation-map: (define-key key-translation-map [(meta ?u) ?o] [?ö]). You do need to unset the global binding for M-u, otherwise the two-event sequence isn't translated (I think there's a way around that). I think it's also possible to arrange for ESC u to remain distinct from M-u. Aug 20 '16 at 0:08
  • @Gilles: fair enough; I'd used global-set-key to mirror OP's use of global-unset-key.
    – Dan
    Aug 20 '16 at 13:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.