bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#41868: [PATCH] Add project-clean-up command


From: Basil L. Contovounesios
Subject: bug#41868: [PATCH] Add project-clean-up command
Date: Mon, 15 Jun 2020 12:04:51 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

"Philip K." <philip@warpmail.net> writes:

> 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.

Thanks, just some minor nits from me.

[...]

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

Something like "Kill <N> buffers under <root>? "?

[...]

> +(defcustom project-dont-clean-regexps
> +  '("\\*Help\\*")
> +  "List of regular expressions to be ignored by `project-clean-up'."
> +  :type '(repeat regexp))

This needs a :version tag.

> +(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)
                      ^^^^
Nit: Paths in Emacs are directory lists, whereas this is a file name.

> +                            (buffer-local-value 'default-directory buf)))
> +                  (true (file-truename path)))

Doesn't file-in-directory-p do this for us?

> +        (when (file-in-directory-p true root)
> +          (push buf bufs))))
> +    bufs))

Maybe the list should be returned in the same order as (buffer-list), by
using either nreverse or seq-filter?

> +;;;###autoload
> +(defun project-clean-up ()
> +  "Kill all opened buffers in a project."
               ^^^^^^
               live?

> +  (interactive)
> +  (let* ((pr (project-current t)))

Nit: No need for let*.

> +    (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))))))

Nit: AKA

  (unless (seq-some (lambda (re)
                      (string-match-p re (buffer-name buf)))
                    project-dont-clean-regexps)
    ...)

Thanks,

-- 
Basil





reply via email to

[Prev in Thread] Current Thread [Next in Thread]