Function: treemacs-rightclick-menu
treemacs-rightclick-menu is an autoloaded, interactive and
byte-compiled function defined in treemacs-mouse-interface.el.
Signature
(treemacs-rightclick-menu EVENT)
Documentation
Show a contextual right click menu based on click EVENT.
Key Bindings
Source Code
;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-mouse-interface.el
;;;###autoload
(defun treemacs-rightclick-menu (event)
"Show a contextual right click menu based on click EVENT."
(interactive "e")
(treemacs-without-following
(unless (eq major-mode 'treemacs-mode)
;; no when-let - the window must exist or this function would not be called
(select-window (treemacs-get-local-window)))
(goto-char (posn-point (cadr event)))
(hl-line-highlight)
;; need to redisplay manually so hl-line and point move correctly
;; and visibly
(redisplay)
(cl-labels ((check (value) (not (null value))))
(let* ((node (treemacs-node-at-point))
(state (-some-> node (treemacs-button-get :state)))
(project (treemacs-project-at-point))
(menu
(easy-menu-create-menu
nil
`(["Paste here"
treemacs-paste-dir-at-point-to-minibuffer
:visible ,(string-match-p "\\(\\(Move\\)\\|\\(Copy\\)\\) to: " (or (minibuffer-prompt) ""))]
("New"
["New File" treemacs-create-file]
["New Directory" treemacs-create-dir])
["Open" treemacs-visit-node-no-split :visible ,(check node)]
("Open With" :visible ,(not (null node))
["Open Directly" treemacs-visit-node-no-split]
["Open In External Application" treemacs-visit-node-in-external-application]
["Open With Vertical Split" treemacs-visit-node-vertical-split]
["Open With Horizontal Split" treemacs-visit-node-horizontal-split]
["Open With Ace" treemacs-visit-node-ace]
["Open With Ace & Vertical Split" treemacs-visit-node-ace-vertical-split]
["Open With Ace & Horizontal Split" treemacs-visit-node-ace-horizontal-split])
["Open Tags" treemacs-toggle-node :visible ,(check (memq state '(file-node-closed tag-node-closed)))]
["Close Tags" treemacs-toggle-node :visible ,(check (memq state '(file-node-open tag-node-open)))]
["--" #'ignore :visible ,(check node)]
["Rename" treemacs-rename-file :visible ,(check node)]
["Delete" treemacs-delete-file :visible ,(check node)]
["Move" treemacs-move-file :visible ,(check node)]
("Copy"
["Copy File" treemacs-copy-file :visible ,(check node)]
["Copy Absolute Path" treemacs-copy-absolute-path-at-point :visible ,(check node)]
["Copy Relative Path" treemacs-copy-relative-path-at-point :visible ,(check node)]
["Copy Project Path" treemacs-copy-project-path-at-point :visible ,(check node)]
["Copy Filename" treemacs-copy-filename-at-point :visible ,(check node)])
["--" #'ignore t]
("Projects"
["Add Project" treemacs-add-project]
,@(--map `(,(car it) ,@(funcall (cdr it)))
treemacs--mouse-project-list-functions)
["Remove Project" treemacs-remove-project-from-workspace :visible ,(check project)]
["Rename Project" treemacs-rename-project :visible ,(check project)])
("Workspaces"
["Edit Workspaces" treemacs-edit-workspaces]
["Create Workspace" treemacs-create-workspace]
["Remove Workspace" treemacs-remove-workspace]
["Rename Workspace" treemacs-rename-workspace]
["Switch Workspace" treemacs-switch-workspace]
["Set Fallback Workspace" treemacs-set-fallback-workspace])
("Toggles"
[,(format "Dotfile Visibility (Currently %s)"
(if treemacs-show-hidden-files "Enabled" "Disabled"))
treemacs-toggle-show-dotfiles]
[,(format "Follow-Mode (Currently %s)"
(if treemacs-follow-mode "Enabled" "Disabled"))
treemacs-follow-mode]
[,(format "Filewatch-Mode (Currently %s)"
(if treemacs-filewatch-mode "Enabled" "Disabled"))
treemacs-filewatch-mode]
[,(format "Fringe-Indicator-Mode (Currently %s)"
(if treemacs-fringe-indicator-mode "Enabled" "Disabled"))
treemacs-fringe-indicator-mode])
("Help"
["Show Helpful Hydra" treemacs-helpful-hydra]
["Show Active Extensions" treemacs-show-extensions]
["Show Changelog" treemacs-show-changelog]))))
(choice (x-popup-menu event menu))
(cmd (lookup-key menu (apply 'vector choice))))
;; In the terminal clicking on a nested menu item does not expand it, but actually
;; selects it as the chosen use option. So as a workaround we need to manually go
;; through the menus until we land on an executable command.
(while (and (not (commandp cmd))
(not (eq cmd menu)))
(setf menu choice
choice (x-popup-menu event cmd)
cmd (lookup-key cmd (apply 'vector choice))))
(when (and cmd (commandp cmd))
(call-interactively cmd))
(hl-line-highlight)))))