|
From: | Dmitry Gutov |
Subject: | Re: [PATCH] Speed up project-kill-buffers |
Date: | Tue, 25 May 2021 04:30:57 +0300 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 |
On 20.05.2021 15:16, Stephen Leake wrote:
Stephen Leake <stephen_leake@stephe-leake.org> writes:Hmm. I just found project-kill-buffer-conditions; maybe I could customize that; it allows arbitrary predicate functions. It would be more efficient if the predicate function were also passed the project object, so it doesn't have to call project-current again (hmm - shades of project-delete-this-buffer-p :).This works for wisi projects, but not for the elisp project (it signals an error):
I suppose if you set project-find-functions to a local value in emacs-lisp-mode buffers (which is IMO unusual), you could also set project-kill-buffer-conditions to a different local value in those buffers?
(defun wisi-prj-kill-buffer-condition (buffer) "Return non-nil if BUFFER should be killed. For `project-kill-buffer-conditions'." (let* ((source-path (wisi-prj-source-path (project-current)))
Are those just project sources or dependency dirs as well?
(buf-file-name (buffer-file-name buffer)) (done (not (buffer-file-name buffer))) (result nil) dir) (while (and source-path (not done)) (setq dir (pop source-path)) (when (and dir (file-in-directory-p buf-file-name dir)) (setq done t) (setq result t))) result))
On the face of it, project-kill-buffer-conditions could use a PROJECT argument to improve efficiency, but if you have a var which points to the global project, your 'project-current' probably works very quickly. So there wouldn't be much actual speedup in your case.
You can prove me wrong with (benchmark 1 '...) or (benchmark-progn ...).
[Prev in Thread] | Current Thread | [Next in Thread] |