0

I have a very weird problem, I cannot type left open bracket character ([) into any buffer. Bracket itself is recognized when I:

  • type anywhere outside emacs
  • type in minibuffer
  • use it as part of command ([[ in evil normal state or C-c [ in reftex work as expected)
  • launch emacs -Q, then it works in buffers

After typing [ it looks like this:

left bracket as prefix

When I try to describe [ with C-h k, it's treated as prefix, not as all the other chars (which do self-insert-command).

I can't manually bind inserting [ to [, it's not recognized. My current workaround is like this:

(global-set-key (kbd "M-[") (kbd "C-x 8 RET L S B R RET")) This interactively selects "LEFT SQUARE BRACKET" in C-x 8 RET (insert char) command in my ivy-flx, but it's slower and annoying.

I'm not on macbook, as they seem to have related problems (https://stackoverflow.com/questions/3376863/unable-to-type-braces-and-square-braces-in-emacs), I'm on Arch Linux, with emacs 25.2.1.

After turning evil-mode off the problem persists, so I guess that's not that.

My config is here: https://pastebin.com/8FLSkbAA.

Any feedback really appreciated!

3
  • 4
    You already know it works fine when you start without your init file (emacs -Q). So it's something in your init file. You need to bisect it recursively to isolate the problem.
    – Dan
    Commented May 9, 2017 at 17:51
  • 1
    If you hit [ <f1> it should show you what [ is a prefix of, which might be helpful.
    – npostavs
    Commented May 9, 2017 at 18:05
  • @Dan thanks, I started disabling minor modes and soon found out that yasnippet is the culprit here. @npostavs amazing! I had this binding overriden by which-key, but once I got it working it gave me the yasnippet answer right away! imgur.com/a/aXX7F now the question is how to fix it, but now I'm much closer!
    – tlegutko
    Commented May 9, 2017 at 18:26

1 Answer 1

3

EDIT and final answer: Okay, so thanks to the @npostavs (can't thank you enough :D) I can finally tell the real problem was me not understanding the use-package binding syntax, we can have either

  • ("C-c x" . some-fun) "string syntax" or
  • ([tab] . some-fun) "vector syntax" (mainly for special characters)

Syntax is based on this part of manual.

I was mixing both and in the process use-package interpreted my shortcut "[backtab]" as literal sequence of 9 characters [ b a c k t a b ], which was quite far from what I was trying to do :D.

As a bonus, working code (can be launched in emacs -Q and M-x eval-buffer to properly rebind yasnippet tab and shift tab using use-package.

(package-initialize)
(require 'use-package)
(require 'bind-key)
(use-package yasnippet
  :bind
  (:map yas-minor-mode-map
    ([tab] . nil)
    ([?\t] . nil)
    ([(shift tab)] . nil)
    ([backtab] . nil)
    ("C-c r" . yas-prev-field)
    ("C-c t" . yas-next-field-or-maybe-expand)
    :map yas-keymap
    ([tab] . nil)
    ([?\t] . nil)
    ([(shift tab)] . nil)
    ([backtab] . nil)
    ("C-c r" . yas-prev-field)
    ("C-c t" . yas-next-field-or-maybe-expand)))

(yas-minor-mode 1)

Initial post:

Okay, the reason was in yasnippet's interpretation of this part of my config:

(use-package yasnippet
  :diminish yas-minor-mode
  :bind
  (:map yas-minor-mode-map
  ("<tab>" . yas-expand)
  ("TAB" . yas-expand)
  ;; ("[(shift tab)]" . nil) ;; THIS made "[" act like prefix
  ;; ("[backtab]" . nil) ;; THIS made "[" act like prefix
  ("<S-iso-lefttab>" . yas-prev-field))
  :config
  (yas-global-mode 1))

My keyboard on Shift+Tab is understood by emacs as <S-iso-lefttab> (as described in this comment), so, according to yasnippet faq I tried to unbind other keys with notation they provided, but well, that bug was really unexpected. Maybe a bug with interaction with use-package's bind macro? I'll try to provide minimal config to reproduce it, and file an issue on yasnippet.

Huge thanks to @npostavs for suggestion that if [ acted as prefix, hitting [ <f1> allows to quickly find what follows after it, in my case: enter image description here

3
  • 1
    Yeah, this is a misuse of use-package's :bind form, you mixed the string kbd notation with vector notation for keybindings. See (emacs) Init Rebinding.
    – npostavs
    Commented May 9, 2017 at 19:13
  • 1
    I'm not convinced that you need to file an issue with use-package or yasnippet, unless one of them provided the faulty code. What would you have them fix? Looking that the yasnippet FAQ, I don't see any problem with what they did.
    – nispio
    Commented May 9, 2017 at 19:25
  • @nispio you're right, the fault was on my side, as npostavs correctly saw. I've updated the answer, thanks for help and your time!
    – tlegutko
    Commented May 9, 2017 at 21:17

Your Answer

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

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