Putting all options present in hydra to a right click menu is super useful if you are browsing files and projects. The click can be made aware of where it is clicked so that user can get different options at different places in treemacs buffer. Sure this is a secondary feature but it will make it so much more mouse friendly.
That has actually been the plan ever since I implemented the very first mouse interface. I even remember someone showing me a package or builtin framework that would make this much easier than I thought, but unfortunately I cannot find it anymore. Guess some research is to be done after all.
@TimoFreiberg you wanted more stuff to do, so how about this? You'll be repackaging many of treemacs' features into a new form, so there will be plenty to learn.
easymenu is quite nice but I am skeptic about it. I did some research and came up with the following from C-h v of menu-bar-edit-menu:
(define-key emacs-lisp-mode-map [mouse-3]
(let ((menu (make-sparse-keymap "Test Menu")))
(bindings--define-key menu [find-file] ; <- An id is needed to represent each menu item
`(menu-item "Find File" find-file ; menu-item is always needed at the beginning
:help "Open up a new file into Emacs buffer"))
(bindings--define-key menu [menu-bar-toggle]
`(menu-item "Toggle menu bar" menu-bar-mode
:help "Toggles visibility state of menu bar"))
menu))
easymenu is quite nice but I am skeptic about it.
Turns out it works pretty well, dired+ had a solid example I could base my work on. A first version of the menu is up on master now. The basics are in, I just need to flesh it out with some useful magit/projectile/grep etc commands.
Feedback welcome.
Waiting for melpa!
How will I access the menu?
Ah, looks like the evil integration never made it outside my scratch buffer. Try this:
(evil-define-key 'treemacs treemacs-mode-map [mouse-3] #'treemacs-rightclick-menu)
The more standard way should be (define-key treemacs-mode-map [mouse-3] #'treemacs-rightclick-menu).
I would suggest to move mostly used commands like New file, New folder, Delete, Rename, Cut, Copy, Paste, copy project path to clipboard, etc. into the main menu i.e. outside the submenu.
The more standard way should be (define-key treemacs-mode-map [mouse-3] #'treemacs-rightclick-menu)
True. I thought I needed the extra step for evil, turns out I had just forgotten to add a keybind at all :man_facepalming:
I would suggest to move mostly used commands like New file, New folder, Delete, Rename, Cut, Copy, Paste, copy project path to clipboard, etc. into the main menu i.e. outside the submenu.
Yeah, that's what I thought, too. I'll try and copy other editors' layout.
A simple thing left out. Can you see if the selection can be rendered in the UI before the right click happens using a mouse event.
Done in https://github.com/Alexander-Miller/treemacs/commit/6ebe4844c4318c08a20c881d72978b63f4f4c40f.
Any clue why I had to use that timer? Without it selection would only move after the popup is gone, no matter what I tried.
I don't know. What is the use of treemacs-without-following?
That just sets a flag that prevents follow-mode from doing its thing. Needed when you have code running that for example calls with-selected-window.
Extracted the common stuff to the top now. For projects I'll also be adding the org-editing from https://github.com/Alexander-Miller/treemacs/issues/247 once that's solidified and documented.
Anything else that's missing?
Net gschimpft isch globt gnug.