0

I'm using emacs on MacOS (v11.4 Big Sur) installed from homebrew-emacs-plus and, every time I want to open a file for a quick edit on the terminal (on iTerm2) using emacsclient, a character gets inserted at the beginning the file (please check the attached image).

Other function keys like delete also insert sequences like [3~] and, I know there must be a simple solution I can find a direct reference to this.

How can I fix this so that I can do quick edits on directly on my terminal?

Regards,

enter image description here

Hugo
  • 111
  • 3
  • 1
    If you start your emacs with `emacs -q` and then start the server with `M-x emacs-server` and then try to edit a file with `emacsclient `, do you get the extra characters? – NickD Jun 15 '21 at 03:37
  • Calling like that, `emacs -q`, throws some other errors but, opening with `open -a Emacs --args -q`, starting the server and then editing a file in the terminal do not inserts any other char! – Hugo Jun 15 '21 at 17:31
  • 1
    Which probably means that the culprit is something in your init file. You will have to debug that and fix it. Probably the best way is to bisect your init file in order to zero in on the culprit. – NickD Jun 15 '21 at 17:51

1 Answers1

1

Following the advice from @NickD, I found the offending config on my init.el:

(global-set-key (kbd "M-[") 'insert-pair)
(global-set-key (kbd "M-{") 'insert-pair)
(global-set-key (kbd "M-\"") 'insert-pair)

Thanks!

Hugo
  • 111
  • 3
  • 1
    You made the same mistake as https://emacs.stackexchange.com/questions/68703/m-causes-emacs-to-print-weird-possibly-escape-sequences. Your terminal sent 0x1b 0x5b 0x49, which looks to Emacs like `M-[` followed by a simple `I`. You may want to look in the iTerm documentation for the meaning, but xterm sends it when it gains focus. When running in a terminal, Emacs comes with a keymap for `M-[` that handles escape sequences coming from the terminal for things like the mouse wheel, the arrow keys, the function keys, and so on. Adding a new keybinding for `M-[` breaks all of that. – db48x Nov 18 '21 at 18:34