Function: treemacs-mode

treemacs-mode is an autoloaded, interactive and byte-compiled function defined in treemacs-mode.el.

Signature

(treemacs-mode)

Documentation

A major mode for displaying the file system in a tree layout.

In addition to any hooks its parent mode special-mode might have run, this mode runs the hook treemacs-mode-hook, as the final or penultimate step during initialization.

! treemacs-run-shell-command-for-current-node
< treemacs-decrease-width
<C-i> treemacs-TAB-action
<backtab> treemacs-collapse-all-projects
<double-mouse-1> treemacs-doubleclick-action
<down-mouse-1> treemacs-leftclick-action
<drag-mouse-1> treemacs-dragleftclick-action
<mouse-3> treemacs-rightclick-menu
<next> treemacs-next-page-other-window
<prior> treemacs-previous-page-other-window
<return> treemacs-RET-action
<tab> treemacs-TAB-action
= treemacs-fit-window-width
> treemacs-increase-width
? treemacs-common-helpful-hydra
C treemacs-cleanup-litter
C-? treemacs-advanced-helpful-hydra
C-c C-p a treemacs-add-project-to-workspace
C-c C-p c a treemacs-collapse-all-projects
C-c C-p c c treemacs-collapse-project
C-c C-p c o treemacs-collapse-other-projects
C-c C-p d treemacs-remove-project-from-workspace
C-c C-p r treemacs-rename-project
C-c C-w a treemacs-create-workspace
C-c C-w d treemacs-remove-workspace
C-c C-w e treemacs-edit-workspaces
C-c C-w f treemacs-set-fallback-workspace
C-c C-w n treemacs-next-workspace
C-c C-w r treemacs-rename-workspace
C-c C-w s treemacs-switch-workspace
C-j treemacs-next-project
C-k treemacs-previous-project
H treemacs-collapse-parent-node
M-! treemacs-run-shell-command-in-project-root
M-<down> treemacs-move-project-down
M-<up> treemacs-move-project-up
M-H treemacs-root-up
M-L treemacs-root-down
M-N treemacs-next-line-other-window
M-P treemacs-previous-line-other-window
M-h treemacs-COLLAPSE-action
M-l treemacs-RET-action
M-m treemacs-bulk-file-actions
M-n treemacs-next-neighbour
M-p treemacs-previous-neighbour
P treemacs-peek-mode(var)/treemacs-peek-mode(fun)
Q treemacs-kill-buffer
R treemacs-rename-file
RET treemacs-RET-action
TAB treemacs-TAB-action
W treemacs-extra-wide-toggle
b treemacs-add-bookmark
c d treemacs-create-dir
c f treemacs-create-file
d treemacs-delete-file
g treemacs-refresh
h treemacs-COLLAPSE-action
l treemacs-RET-action
m treemacs-move-file
n treemacs-next-line
o a a treemacs-visit-node-ace
o a h treemacs-visit-node-ace-horizontal-split
o a v treemacs-visit-node-ace-vertical-split
o c treemacs-visit-node-close-treemacs
o h treemacs-visit-node-horizontal-split
o o treemacs-visit-node-no-split
o r treemacs-visit-node-in-most-recently-used-window
o v treemacs-visit-node-vertical-split
o x treemacs-visit-node-in-external-application
p treemacs-previous-line
q treemacs-quit
r treemacs-refresh
s treemacs-resort
t a treemacs-filewatch-mode(var)/treemacs-filewatch-mode(fun)
t c treemacs-indicate-top-scroll-mode(var)/treemacs-indicate-top-scroll-mode(fun)
t d treemacs-git-commit-diff-mode(var)/treemacs-git-commit-diff-mode(fun)
t f treemacs-follow-mode(var)/treemacs-follow-mode(fun)
t g treemacs-git-mode(var)/treemacs-git-mode(fun)
t h treemacs-toggle-show-dotfiles
t i treemacs-hide-gitignored-files-mode(var)/treemacs-hide-gitignored-files-mode(fun)
t n treemacs-indent-guide-mode(var)/treemacs-indent-guide-mode(fun)
t v treemacs-fringe-indicator-mode(var)/treemacs-fringe-indicator-mode(fun)
t w treemacs-toggle-fixed-width
u treemacs-goto-parent-node
w treemacs-set-width
y a treemacs-copy-absolute-path-at-point
y f treemacs-copy-file
y n treemacs-copy-filename-at-point
y p treemacs-copy-project-path-at-point
y r treemacs-copy-relative-path-at-point
y v treemacs-paste-dir-at-point-to-minibuffer

This function has :around advice: treemacs--mode-check-advice.

Key Bindings

Source Code

;; Defined in ~/.emacs.d/elpa/treemacs-20251226.1307/treemacs-mode.el
;;;###autoload
(define-derived-mode treemacs-mode special-mode "Treemacs"
  "A major mode for displaying the file system in a tree layout."

  (setq buffer-read-only         t
        truncate-lines           t
        indent-tabs-mode         nil
        desktop-save-buffer      nil
        window-size-fixed        (when treemacs-width-is-initially-locked 'width)
        treemacs--in-this-buffer t)

  (unless treemacs-show-cursor
    (setq cursor-type nil))
  (when (boundp 'evil-treemacs-state-cursor)
    (with-no-warnings
      (setq evil-treemacs-state-cursor
            (if treemacs-show-cursor
                evil-motion-state-cursor
              (lambda () (setq cursor-type nil))))))

  ;; higher fuzz value makes it less likely to start a mouse drag
  ;; and make a switch to visual state
  (setq-local double-click-fuzz 15)
  (setq-local show-paren-mode nil)
  (setq-local tab-width 1)
  (setq-local eldoc-documentation-function #'treemacs--eldoc-function)
  (setq-local eldoc-message-commands treemacs--eldoc-obarray)
  (setq-local imenu-create-index-function #'treemacs--create-imenu-index-function)
  (when (boundp 'context-menu-functions)
    (setq-local context-menu-functions nil))

  ;; integrate with bookmark.el
  (setq-local bookmark-make-record-function #'treemacs--make-bookmark-record)
  (electric-indent-local-mode -1)
  (visual-line-mode -1)
  (font-lock-mode -1)
  (jit-lock-mode nil)
  (buffer-disable-undo)
  ;; fringe indicator must be set up right here, before hl-line-mode, since activating hl-line-mode will
  ;; invoke the movement of the fringe overlay that would otherwise be nil
  (when treemacs-fringe-indicator-mode
    (treemacs--enable-fringe-indicator))
  (if treemacs-user-header-line-format
      (setf header-line-format treemacs-user-header-line-format)
    (when header-line-format
      (setf header-line-format nil)))
  (hl-line-mode t)

  ;; needs to run manually the first time treemacs is loaded, since the hook is only added *after*
  ;; the window config was changed to show treemacs
  (unless (member #'treemacs--on-window-config-change (default-value 'window-configuration-change-hook))
    (treemacs--on-window-config-change))
  ;; set the parameter immediately so it can take effect when `treemacs' is called programatically
  ;; alongside other window layout chaning commands that might delete it again.
  ;; also check that the buffer has a window as other packages might call `treemacs-mode' on buffers
  ;; that have no window yet
  (when (get-buffer-window (current-buffer))
    (set-window-parameter (selected-window) 'no-delete-other-windows treemacs-no-delete-other-windows))

  (face-remap-add-relative 'default 'treemacs-window-background-face)
  (face-remap-add-relative 'fringe  'treemacs-window-background-face)
  (face-remap-add-relative 'hl-line 'treemacs-hl-line-face)

  (when treemacs-text-scale
    (text-scale-increase treemacs-text-scale))

  (add-hook 'window-configuration-change-hook #'treemacs--on-window-config-change)
  (add-hook 'kill-buffer-hook #'treemacs--on-buffer-kill nil t)
  (add-hook 'post-command-hook #'treemacs--post-command nil t)

  (treemacs--build-indentation-cache 6)
  (treemacs--select-icon-set)
  (treemacs--setup-mode-line)
  (treemacs--reset-dom))