Compare commits

...

2 commits

Author SHA1 Message Date
df29b3c7c8 Comments 2025-08-20 22:22:49 +08:00
e2cdbb2959 Swap neotree to tab project directory automatically 2025-08-20 22:21:56 +08:00
3 changed files with 12 additions and 105 deletions

4
ui.el
View file

@ -98,7 +98,9 @@
(setq tab-bar-close-button-show nil) ;; hide tab close / X button
(setq tab-bar-new-tab-choice "*enlight*");; buffer to show in new tabs
(setq tab-bar-tab-hints t) ;; show tab numbers
(setq tab-bar-format '(tab-bar-format-tabs tab-bar-separator))) ;; elements to include in bar
(setq tab-bar-format '(tab-bar-format-tabs tab-bar-separator)) ;; elements to include in bar
(defvar tab-bar-select-tab-hook nil "Hook for `tab-bar-select-tab'") ;; Hook for tab change, since it doesn't exist by default
(advice-add 'tab-bar-select-tab :after (lambda (x) (run-hooks 'tab-bar-select-tab-hook))))
;; Hideshow
(add-hook 'prog-mode-hook #'hs-minor-mode)

View file

@ -1,104 +0,0 @@
;;; dired-custom.el --- Custom dired config -*- lexical-binding: t -*-
;; This file is not part of GNU Emacs
;; This program is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
;;; Commentary:
;; commentary
;;; Code:
(require 'dired)
(setq dired-listing-switches "-lh")
(setq dired-recursive-deletes t)
(setq dired-recursive-copies t)
(defun dired-init ()
"Theurgy Dired config."
;; Hide file permissions
(dired-hide-details-mode 1)
;; Kill new buffers
(when (>= emacs-major-version 28)
(setq dired-kill-when-opening-new-dired-buffer t))
(when (< emacs-major-version 28)
(progn
(define-key dired-mode-map (kbd "RET") 'dired-find-alternate-file)
(define-key dired-mode-map (kbd "^") (lambda () (interactive) (find-alternate-file "..")))))
;; Human readable file size
(setq dired-listing-switches "-lh"))
(add-hook 'dired-mode-hook 'dired-init)
(add-hook 'dired-mode-hook 'auto-revert-mode)
;; Icons in dired
(use-package all-the-icons-dired
:config
(add-hook 'dired-mode-hook 'all-the-icons-dired-mode))
;; Multimedia and PDF viewing
(when (not (equal system-type 'windows-nt))
(use-package ready-player
:ensure t
:config
(setq ready-player-autoplay nil)
(ready-player-mode 1))
(use-package pdf-tools
:config (pdf-loader-install)))
;; Preview files
(defun dired-preview-to-the-right ()
"My preferred `dired-preview-display-action-alist-function'."
'((display-buffer-in-side-window)
(side . right)
(slot . 0)
(window-width . 0.3)))
(use-package dired-preview
:after (ready-player)
:config
(setq dired-preview-display-action-alist #'dired-preview-to-the-right)
(setq dired-preview-buffer-name-indicator "[Preview]")
(setq dired-preview-ignored-extensions-regexp
(concat "\\."
"\\(gz\\|"
"zst\\|"
"tar\\|"
"xz\\|"
"rar\\|"
"zip\\|"
"iso\\|"
"epub"
"\\)"))
(dired-preview-global-mode 1))
;; Automatically kill preview buffers when opening a file
(add-hook 'find-file-hook (lambda ()
(dolist (buf (buffer-list))
(when (string-match-p "\\[Preview\\]" (buffer-name buf))
(kill-buffer buf)))))
(use-package neotree
:config
(define-key global-map (kbd "<f8>") 'neotree-toggle)
(setq neo-theme (if (display-graphic-p) 'icons 'arrow)))
(provide 'dired-custom)
;;; dired-custom.el ends here

View file

@ -49,8 +49,17 @@
(whaler :action (lambda (dir)
(find-file (get-project-default-file dir))
(tab-rename (file-name-nondirectory (string-remove-suffix "/" dir)))
(tab-bar-change-tab-group (concat "project: " dir)) ;; We use the tab group name to store the project working directory
(neotree-dir dir))))
(defun theurgy-swap-to-tab-project ()
"Go to the project dir of the tab group."
(let ((tab-group-name (tab-bar-tab-group-default (tab-bar--current-tab))))
(when (string-match-p "^project:" tab-group-name)
(neotree-dir (string-remove-prefix "project: " tab-group-name)))))
(add-hook 'tab-bar-select-tab-hook #'theurgy-swap-to-tab-project)
(defun theurgy-edit-projects-list ()
"Open list of projects in customize."
(interactive)