0

With quoted-insert (C-q) I can enter ‘Option-something’ extended characters, but Emacs apparently understands them as ISO 8859-1. Meanwhile, MacOS has its own layout for these characters (changed with the input language or custom layouts), and there's a cheatsheet in the form of ‘Keyboard viewer.’

Is there any way to make Emacs use the same layout for M-something in quoted-insert as native applications do?

I could conceivably edit a keymap by hand to reflect the system one, but 1) I don't see a mention of a special keymap for quoted-insert, and 2) I'd prefer not to.

Apparently Emacs does receive native characters if Option keys aren't set up as Meta, however I don't have an abundance of modifier keys on my keyboard so I'd prefer to keep Option as Meta and use quoted-insert when needed.

1
  • 1
    While formulating the question I found out that unmapping Meta from Option apparently lets one use native special characters, and realized that I could probably make a wrapper that does the unmapping and then launches quoted-insert. Will try that and post results.
    – aaa
    Sep 16, 2019 at 12:45

1 Answer 1

1

As I learned that Emacs enters native special symbols if Option isn't mapped to Meta, I went ahead and made a wrapper for quoted-insert that does the unmapping:

(defun my/quoted-insert-wrapper (arg)
  "For quoted-insert, unmap Option from Meta so special symbols can be entered with the native Mac layout"
  (interactive "*p")
  (let ((mac-option-modifier 'none))
    (quoted-insert arg)))

;;; this should work for non-Evil setups, but haven't tested it
;; (global-set-key (kbd "C-v") #'my/quoted-insert-wrapper)

(define-key evil-insert-state-map (kbd "C-v") #'my/quoted-insert-wrapper)

Works like a charm so far, even for diacritic modifiers. Users of non-Latin layouts will probably also want to add a mapping for keys in their language on the same location as Latin C-v.

However, I'm not sure whether hijacking the option with let would work if lexical binding is enabled—but that's a different issue. Presumably I still could setq the option and then revert it after quoted-insert.

2
  • Some additional backgound: The variable mac-option-modifier is an alias for ns-alternate-modifier, which is defined in nsterm.m. The user also free to set the left/right Option keys differently; e.g., (setq ns-alternate-modifier 'meta ns-right-alternate-modifier 'none) will permit the right option key to behave with system defaults, and the left will be have as Meta.
    – lawlist
    Sep 16, 2019 at 18:16
  • @lawlist True, however afaik there's little point in keeping around methods to enter symbols in both Mac layout and ISO 8859-1. Meanwhile, touch typing advises to press the key with one hand and the modifier with the other; furthermore Option-Shift-key becomes rather cumbersome if you have to stick to one of the two Options.
    – aaa
    Sep 16, 2019 at 20:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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