.emacs.d

the most bloated Emacs config on this planet
git clone https://git.trogloxene.org/.emacs.d.git
Log | Files | Refs

commit 73432e5149e99f5490d613657b7070f281d113c5
parent 6dccc6653478caca1389cb9b9b6e21c3d4a29891
Author: andsy10 <andsy1016@gmail.com>
Date:   Mon, 28 Sep 2026 00:56:42 +0800

Enhance perspective integration

Diffstat:
Mlisp/init-base.el | 10++++------
Mlisp/init-kbd-func.el | 11-----------
Mlisp/init-kbd.el | 8++++----
Mlisp/init-package.el | 55+++++++++++++++++++++++++++++++++++++++----------------
4 files changed, 47 insertions(+), 37 deletions(-)

diff --git a/lisp/init-base.el b/lisp/init-base.el @@ -221,11 +221,9 @@ (mode . vundo-diff-mode))) ("Process" (predicate get-buffer-process (current-buffer)))))) - (add-hook 'ibuffer-hook - (lambda () - (ibuffer-switch-to-saved-filter-groups "Main") - (unless (eq ibuffer-sorting-mode 'alphabetic) - (ibuffer-do-sort-by-alphabetic)))) + (defun my-ibuffer-setup () + (ibuffer-switch-to-saved-filter-groups "Main")) + (add-hook 'ibuffer-hook #'my-ibuffer-setup) (setq ibuffer-formats '((mark modified read-only locked @@ -235,7 +233,7 @@ (mark " " (name 16 -1) " " filename))) (setq ibuffer-show-empty-filter-groups nil - ibuffer-use-other-window t + ibuffer-default-sorting-mode 'alphabetic ibuffer-human-readable-size t)) (use-package simple diff --git a/lisp/init-kbd-func.el b/lisp/init-kbd-func.el @@ -9,17 +9,6 @@ (interactive) (find-file user-init-file)) -(defun my-scratch-buffer (&optional arg) - "Switch to the *scratch* buffer. -With a prefix ARG create a new *scratch* buffer." - (interactive "P") - (let ((default-directory (expand-file-name "~/"))) - (if arg - (let ((buf (generate-new-buffer "*scratch*"))) - (switch-to-buffer buf) - (funcall initial-major-mode)) - (scratch-buffer)))) - ;; from Bozhidar Batsov's crux (defun my-kill-line-backwards () "Kill line backwards and adjust the indentation." diff --git a/lisp/init-kbd.el b/lisp/init-kbd.el @@ -178,7 +178,7 @@ "]" #'forward-paragraph "." #'repeat "y" #'yank - "C-c C-<f12>" #'my-scratch-buffer + "C-c C-<f12>" #'my-persp-scratch-buffer "z" #'avy-goto-char "'" #'avy-goto-word-1 "<f2>" #'open-init-file) @@ -244,7 +244,7 @@ (general-def persp-mode-map "C-c p c" nil "C-c p d" #'persp-kill - "C-x C-b" #'persp-ibuffer) + "C-x C-b" #'my-persp-ibuffer) ;; pilish (general-def (pilish-input-mode-map @@ -447,8 +447,8 @@ ;; scratch buffer (if *is-mac* - (general-def "C-c <f12>" #'my-scratch-buffer) - (general-def "C-c <delete>" #'my-scratch-buffer)) + (general-def "C-c <f12>" #'my-persp-scratch-buffer) + (general-def "C-c <delete>" #'my-persp-scratch-buffer)) (provide 'init-kbd) ;;; init-kbd.el ends here diff --git a/lisp/init-package.el b/lisp/init-package.el @@ -65,30 +65,53 @@ Like normal Emacs `C-k'. Kill to end of line and put content in kill-ring." ;; workspace (use-package perspective - :bind - ("C-x M-b" . persp-list-buffers) :custom (persp-mode-prefix-key (kbd "C-c p")) :hook (after-init . persp-mode) + :commands my-persp-ibuffer my-persp-scratch-buffer :config - (defun persp-ibuffer (arg) - "Invoke IBUFFER with a configuration enabled for Perspective. -With a prefix arg, show buffers in all perspectives. -This respects ido-ignore-buffers, since we automatically add -buffer filtering to ido-mode already (see use of -PERSP-SET-IDO-BUFFERS)." + (defun my-persp-scratch-buffer (arg) + "Switch to the current perspective's scratch buffer. +With a prefix ARG create a new *scratch* buffer." + (interactive "P") + (let ((default-directory (expand-file-name "~/"))) + (if arg + (let* ((name (persp-current-name)) + (initial-persp (equal name persp-initial-frame-name)) + (buf (generate-new-buffer (concat "*scratch*" + (unless initial-persp + (format " (%s)" name)))))) + (switch-to-buffer buf) + (funcall initial-major-mode)) + (persp-switch-to-scratch-buffer)))) + + (defun my-persp-scratch-set-default-dir (fun &rest name) + (let ((default-directory (expand-file-name "~/"))) + (apply fun name))) + (advice-add #'persp-get-scratch-buffer :around #'my-persp-scratch-set-default-dir) + + (defvar my-persp-ibuffer-predicates + (list (lambda (buf) (persp-buffer-filter buf t)) + (lambda (buf) (persp--ignore-buffer-p (buffer-name buf))))) + + (with-eval-after-load 'ibuffer + (setq ibuffer-maybe-show-predicates + (append ibuffer-maybe-show-predicates + my-persp-ibuffer-predicates))) + + (defun my-persp-ibuffer (arg) + "Like `persp-ibuffer' but better." (interactive "P") (unless (featurep 'ibuffer) (require 'ibuffer)) - (defvar ibuffer-maybe-show-predicates) - (if (and persp-mode (null arg)) - (let ((ibuffer-maybe-show-predicates (append ibuffer-maybe-show-predicates - (list #'(lambda (buf) (persp-buffer-filter buf t))) - (list #'(lambda (buf) - (persp--ignore-buffer-p (buffer-name buf))))))) - (ibuffer)) - (ibuffer))) + (ibuffer) + (setq-local ibuffer-maybe-show-predicates + (if (and persp-mode (null arg)) + (append ibuffer-maybe-show-predicates + my-persp-ibuffer-predicates) + '(ibuffer-hidden-buffer-p))) + (ibuffer-update nil t)) (defun my-persp-remove-marked-ibuffers () "Remove marked buffers from perspective."