all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#41868: [PATCH] Add project-clean-up command
@ 2020-06-15 10:00 Philip K.
  2020-06-15 11:04 ` Basil L. Contovounesios
  2020-06-15 12:28 ` Dmitry Gutov
  0 siblings, 2 replies; 31+ messages in thread
From: Philip K. @ 2020-06-15 10:00 UTC (permalink / raw)
  To: 41868

[-- Attachment #1: Type: text/plain, Size: 895 bytes --]


Hi,

I wanted to propose a command for project.el to kill all opened buffers
in a project, called when one finishes working on some specific
code-base. I gave it the name "project-clean-up", but maybe it should be
renamed? I have been using it in my local emacs branch for about a week,
and have found it to be useful.

One issue I ran into is that a buffer might be falsely associated with a
project, such as *Help*. That's why I added an user option
project-dont-clean-regexps to contain a list of regular expression of
what buffer names to spare. The reason I couldn't just stick to checking
the value of buffer-file-name is that Dired, VC, etc. buffers don't get
recognized. There might be a better way to do this, but I'm not sure if
it's worth the effort.

And it might be worth considering to add a prompt, to ask the user if
they actually want to kill all the buffers.

-- 
	Philip K.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Add-project-clean-up-command.patch --]
[-- Type: text/x-diff, Size: 1635 bytes --]

From d7d4127cc561b3f2d1650d19a3fb58895a4cabd1 Mon Sep 17 00:00:00 2001
From: Philip K <philip@warpmail.net>
Date: Fri, 12 Jun 2020 23:37:51 +0200
Subject: [PATCH] Add project-clean-up command

---
 lisp/progmodes/project.el | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/lisp/progmodes/project.el b/lisp/progmodes/project.el
index f3df44fa7b..9e55f3594c 100644
--- a/lisp/progmodes/project.el
+++ b/lisp/progmodes/project.el
@@ -744,6 +744,35 @@ project-compile
          (default-directory (project-root pr)))
     (compile command comint)))
 
+(defcustom project-dont-clean-regexps
+  '("\\*Help\\*")
+  "List of regular expressions to be ignored by `project-clean-up'."
+  :type '(repeat regexp))
+
+(defun project--list-buffers (pr)
+  "Return a list of all buffers in project PR."
+  (let ((root (project-root pr))
+        bufs)
+    (dolist (buf (buffer-list))
+      (when-let* ((path (or (buffer-file-name buf)
+                            (buffer-local-value 'default-directory buf)))
+                  (true (file-truename path)))
+        (when (file-in-directory-p true root)
+          (push buf bufs))))
+    bufs))
+
+;;;###autoload
+(defun project-clean-up ()
+  "Kill all opened buffers in a project."
+  (interactive)
+  (let* ((pr (project-current t)))
+    (dolist (buf (project--list-buffers pr))
+      (let ((match (mapcar (lambda (re)
+                             (and (string-match-p re (buffer-name buf)) t))
+                           project-dont-clean-regexps)))
+        (unless (memq t match)
+          (kill-buffer buf))))))
+
 \f
 ;;; Project list
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 31+ messages in thread

end of thread, other threads:[~2020-08-14 20:36 UTC | newest]

Thread overview: 31+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-15 10:00 bug#41868: [PATCH] Add project-clean-up command Philip K.
2020-06-15 11:04 ` Basil L. Contovounesios
2020-06-15 11:32   ` Philip K.
2020-06-15 11:38     ` Basil L. Contovounesios
2020-06-15 12:28 ` Dmitry Gutov
2020-06-15 18:18   ` Philip K.
2020-06-15 20:50     ` Dmitry Gutov
2020-06-15 21:50       ` Philip K.
2020-06-16 10:19         ` Dmitry Gutov
2020-06-16 10:52         ` Basil L. Contovounesios
2020-06-16 14:31           ` Eli Zaretskii
2020-06-16 17:12             ` Philip K.
2020-06-18  1:05               ` Dmitry Gutov
2020-06-18  6:46                 ` Philip K.
2020-06-18 13:04                   ` Dmitry Gutov
2020-06-18 14:11                     ` Philip K.
2020-06-18 15:36                       ` Dmitry Gutov
2020-06-18 22:06                 ` Juri Linkov
2020-06-18 22:57                   ` Dmitry Gutov
2020-06-18 23:02                     ` Juri Linkov
2020-06-18 23:10                       ` Dmitry Gutov
2020-06-18 23:18                         ` Juri Linkov
2020-06-18 23:29                           ` Dmitry Gutov
2020-06-26  0:49                             ` Dmitry Gutov
2020-06-19  6:28                       ` Philip K.
2020-08-14 17:05                         ` Lars Ingebrigtsen
2020-08-14 20:36                           ` Dmitry Gutov
2020-06-19  6:20                   ` Eli Zaretskii
2020-06-15 22:49       ` Juri Linkov
2020-06-16  0:23         ` Dmitry Gutov
2020-06-16 21:47           ` Juri Linkov

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.