commit 2a05c31001b2be7de7aab1531b8a108c38b78db2 Author: andsy10 <andsy1016@gmail.com> Date: Wed, 22 Jul 2026 08:39:52 +0800 Initial commit Diffstat:
| A | project-ibuffer.el | | | 57 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 file changed, 57 insertions(+), 0 deletions(-)
diff --git a/project-ibuffer.el b/project-ibuffer.el @@ -0,0 +1,57 @@ +;;; project-ibuffer.el --- IBuffer integration for project.el -*- lexical-binding: t; -*- + +;;; Commentary: + +;; This package provides an ibuffer filter that allows viewing buffers +;; belonging to a specific project.el project. + +;; Usage: +;; +;; M-x project-ibuffer +;; +;; With a prefix argument, prompt for a project. Otherwise, use the +;; current project. + +;;; Code: + +(require 'project) + +(with-eval-after-load 'ibuffer + (require 'ibuf-ext nil t) + (define-ibuffer-filter project-files + "Show Ibuffer with all buffers in the current project." + (:description "project root dir" + :reader (read-directory-name "Project root: " + (when-let* ((pr (project-current))) + (project-root pr)))) + (with-current-buffer buf + (and (or buffer-file-name + dired-directory + list-buffers-directory) + (let ((file-name (or buffer-file-name + dired-directory + list-buffers-directory))) + (file-in-directory-p file-name qualifier)))))) + +;;;###autoload +(defun project-ibuffer-by-project (project-root) + "Open an IBuffer window showing all buffers in PROJECT-ROOT." + (require 'ibuf-ext nil t) + (let ((project-name (file-name-nondirectory + (directory-file-name project-root)))) + (ibuffer nil (format "*%s Buffers*" project-name) + (list (cons 'project-files project-root))))) + +;;;###autoload +(defun project-ibuffer (prompt-for-project) + "Open an IBuffer window showing all buffers in the current project. + +Let user choose another project when PROMPT-FOR-PROJECT is supplied." + (interactive "P") + (let ((project-root (if prompt-for-project + (project-prompt-project-dir) + (project-root (project-current t))))) + (project-ibuffer-by-project project-root))) + +(provide 'project-ibuffer) +;;; project-ibuffer.el ends here