Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emacs 29.1 - button.el's button-map overrides TAB key when on tree root's button. #1052

Closed
ed9w2in6 opened this issue Aug 15, 2023 · 8 comments

Comments

@ed9w2in6
Copy link

ed9w2in6 commented Aug 15, 2023

From emacs source (NEWS):

Incompatible changes in Emacs 29.1

 ---
 ** 'TAB' and '<backtab>' is now bound in 'button-map'.
 This means that if you're standing on a button, 'TAB' will take you to
 the next button, even if the mode has bound it to something else.
 This also means that 'TAB' on a button in an 'outline-minor-mode'
 heading will move point instead of collapsing the outline.

In GUI treemacs-TAB-action seems to work fine on root but in terminal treemacs-TAB-action got overridden when cursor is on button for tree root. (Only beginning of line and end of line are non-button for root)

I have yet created a work around for this as I can always do C-e or C-a before pressing TAB but it is a bit annoying.


README Update at [2023-10-20]:
The last statement applies to when cursor is not on a button. With a minimal setup C-a will also NOT work. It works for me because I use an icon package which adds some padding in front, that is not part of the button.

Please read this comment for some clarification:
#1052 (comment)

@stale
Copy link

stale bot commented Oct 14, 2023

This issue has been automatically marked as stale because it has not had recent activity (this bot only works as a reminder, it will not close issues).

@stale stale bot added the stale label Oct 14, 2023
@Alexander-Miller
Copy link
Owner

Looking into it.

@Alexander-Miller
Copy link
Owner

I can't reproduce the problem. What does your config look like? What do you see when you describe-key TAB on a button?

@ed9w2in6
Copy link
Author

ed9w2in6 commented Oct 20, 2023

@Alexander-Miller Thank you for looking into this issue.

I can confirm that this issue still exist with the latest version available on Melpa, reproducible with a minimal setup.

I tested with a minimal setup this time so here are some clarification of the symptoms:
Please note that this issue only exists on terminal.
The issue only exist for top level buttons (i.e. project buttons) when cursor is NOT at end of line.
That is:

  • doing C-e first, tab triggers treemacs-TAB-action as expected.
  • for folders of a project, pressing tab works as expected.

Here is the output of describe-key on a terminal:

TAB runs the command forward-button (found in button-map), which is an
interactive byte-compiled Lisp function in ‘button.el’.

It is bound to TAB.

--> Note that this is TAB but NOT <tab>

For GUI, pressing tab key (the physical action) always triggers treemacs-TAB-action, output of describe-key

<tab> runs the command treemacs-TAB-action (found in
treemacs-mode-map), which is an interactive byte-compiled Lisp
function in ‘treemacs-interface.el’.

--> This is <tab>, NOT TAB. I am not familiar with the code so I am not sure if this can be any clue.


Minimal setup

My Emacs is: GNU Emacs 29.1

I can reproduce this issue with this minimal setup:

  1. Create a new directory and cd into it
  2. Two options:
    a. Do mkdir elpa and symlink relavent packages into it.
    b. Do M-x package-install then type treemacs, needs Melpa. I used this method.
  3. Use this init.el:
(package-initialize)
;; uncomment these if you do `M-x package-install`
;; (require 'package)
;; (add-to-list
;;  'package-archives '("melpa" . "http://melpa.org/packages/"))

(global-set-key (kbd "C-c t") 'treemacs-select-window) ; this is NOT needed to reproduce the error.

(custom-set-variables
   '(package-selected-packages
     '(treemacs))
)

Here are the version numbers from melpa that I used for the dependencies for treemacs:

  • treemacs-20231016.2107
  • ace-window-20220911.358
  • avy-20230420.404
  • cfrs-20220129.1149
  • dash-20230714.723
  • ht-20230703.558
  • hydra-20220910.1206
  • lv-20200507.1518
  • pfuture-20220913.1401
  • posframe-20230714.227
  • s-20220902.1511

Other (possibly irrelevant) environment informations:

system-configuration-features is:

system-configuration-features is a variable defined in ‘C source code’.

Its value is
"ACL GLIB GMP GNUTLS JPEG JSON LIBXML2 MODULES NOTIFY KQUEUE NS PDUMPER PNG RSVG THREADS TIFF TOOLKIT_SCROLL_BARS TREE_SITTER ZLIB"

--> I do NOT have NATIVE-COMP so should the problem should be fairly reproducible.

system info:

OS: macOS Big Sur 11.4 20F71 x86_64
Shell: zsh 5.8
Terminal: kitty 0.30.0
CPU: Intel(R) Core(TM) i5-1038NG7 (8) @ 2 GHz

--> I do NOT think these are relevant

Please tell me if you need more info.
I can sent you an archive of the said minimal setup if you need it.

@Alexander-Miller
Copy link
Owner

I have reproduced the problem now, but I've been unable to come up with a fix that's limited to treemacs. I don't know what's different about projects vs other nodes, but this tab misbind is really persistent.

However I do have a solution you can use. I've the following like in my config: (define-key input-decode-map "\C-i" [C-i]). It's supposed to differentiate between tab vs C-i in the terminal, but it should also fix your particular problem.

@ed9w2in6
Copy link
Author

ed9w2in6 commented Nov 7, 2023

@Alexander-Miller Your work around is better than mine as mines involves more keypresses with my pinky. Thank you from my future self.

As a summary:

My understanding of the culprit (cause) of this issue:

  1. button-buffer-map (button.el) binds TAB as a minor mode key map, which take precedence over buffer local ones
  2. The "tab keyboard press" sends TAB in (most) terminal emulator
  3. The "tab keyboard press" sends <tab> in Emacs GUI

1 + 3 -> symptom: tab still works in GUI
1 + 2 -> symptom: tab does NOT works only in terminal

With the above understanding there are only a few possible fixes:

  • [addresses 1.] remove the TAB binding from button-buffer-map (e.g. at init.el)

  • [addresses 1.] use a smaller button (e.g. only the icon)

  • [addresses 1.] use keymap for mouse instead of button

  • [addresses 2.] send a different key

    • via Emacs <-- your suggestion
    • via your terminal emulator

    --> Is your understanding same as mine?

@Alexander-Miller
Copy link
Owner

I had another go at debugging this, and this time I have found how the button-map is actually injected into treemacs (despite it mostly using its own stripped down version of buttons for a very long time). Long story short: a proper solution is possible after all, the latest treemacs should fix your problem now.

@ed9w2in6
Copy link
Author

ed9w2in6 commented Nov 8, 2023

Thanks for the fix, I would not have known that the keymap is actually bind at the text properties instead of minor mode.
May I ask how you debug this? Do you bisect or use any other tools or tricks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants