From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.ciao.gmane.io!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.bugs Subject: bug#41868: [PATCH] Add project-clean-up command Date: Mon, 15 Jun 2020 12:04:51 +0100 Message-ID: <87sgewr3n0.fsf@tcd.ie> References: <87k108wsvb.fsf@warpmail.net> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="ciao.gmane.io:159.69.161.202"; logging-data="103970"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: 41868@debbugs.gnu.org To: "Philip K." Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Jun 15 13:06:29 2020 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jkmwe-000QqP-4D for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 Jun 2020 13:06:28 +0200 Original-Received: from localhost ([::1]:60020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jkmwd-0000kS-5V for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 15 Jun 2020 07:06:27 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jkmwE-0000Wc-13 for bug-gnu-emacs@gnu.org; Mon, 15 Jun 2020 07:06:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:33793) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1jkmwD-0003u5-No for bug-gnu-emacs@gnu.org; Mon, 15 Jun 2020 07:06:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1jkmwD-0004oz-IZ for bug-gnu-emacs@gnu.org; Mon, 15 Jun 2020 07:06:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 Jun 2020 11:06:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 41868 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 41868-submit@debbugs.gnu.org id=B41868.159221910218445 (code B ref 41868); Mon, 15 Jun 2020 11:06:01 +0000 Original-Received: (at 41868) by debbugs.gnu.org; 15 Jun 2020 11:05:02 +0000 Original-Received: from localhost ([127.0.0.1]:45339 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jkmvG-0004nQ-0z for submit@debbugs.gnu.org; Mon, 15 Jun 2020 07:05:02 -0400 Original-Received: from mail-wm1-f47.google.com ([209.85.128.47]:53043) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1jkmvD-0004n2-Db for 41868@debbugs.gnu.org; Mon, 15 Jun 2020 07:05:00 -0400 Original-Received: by mail-wm1-f47.google.com with SMTP id r9so14195913wmh.2 for <41868@debbugs.gnu.org>; Mon, 15 Jun 2020 04:04:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=cVaDLxyxPPCYzCSp/SIOSpl9FZJ+3W08yCt1Av+6V9M=; b=YMRoOfPdZ9zKgZWMAhIBiwmfyWZBxRVfwpNkXVHtNd8n6GiS8Kx82GUk8YHDKQ7JTP bP5pEhbvd04ToiwfCeNyPrsiY4LUht96cKT1U6ufyxCsmBr2ntnuzT8MOJzPfXf0ly9n AEEFoI5OwdgGdb1heJq4/mTPZEZaSk6mPJ0Vwje9jcPkKc1fz2UZkgHYKCQGE9wJ0LNW akfZh/94mS58KP1GcvzlDGlbaWG/xUdkNEDKsqIne99DhD/nXNbh2Sn4ipsvQd2NuTN2 XN1k6zkfTwaP9W8jqSB4BIUXo4qG7Hl63vaa/TTVo9qhidLTkyKdEEEUNrwmQzokm0AI 8QkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=cVaDLxyxPPCYzCSp/SIOSpl9FZJ+3W08yCt1Av+6V9M=; b=JgKQM5JgOl44kzHobGwx07KVeQRPUahKvioUiJo1+lQTxCmjTEJTUVKY7fYtnl5o26 zOSj78074KcmkfVfqi0OGGoqS3Zk7jPQr3oNvxYjmoBqgqPqvCHRi8HBE8nFX5ozkuvK vaw0tpirSn8sUfFe7FJUqBkBPg6FjGc2hugg8PPYiFJWcq2yTCH/yUHIUw+3T3Y6GtlZ x+VJFBV1ozlYBdFdFtbNodO28mMHyaA/0sDsITxJ4hPLj/2iwPL/gjp1WFeySkOo+4+o uPitymlDGCze7PCvxSWgh5ZShlBoAlxWp0vUm36muh5KpNE761EcfypEQ/nFaMLvaNru 0Gyw== X-Gm-Message-State: AOAM531+wne0bUCdChaNIj6nI0oKFuuaedkdgxjm6kqDvutFjf/UdR+4 5UV37CsfGMq0MmRY5+jVzl9D3Q== X-Google-Smtp-Source: ABdhPJz3vKWWoZ5NdVow1cX4Y6szm7euzFZExnnGntxT9po2Z05KGmy7KKHTXXN9Nj4Xzfngfsd79A== X-Received: by 2002:a7b:c3c6:: with SMTP id t6mr12036322wmj.159.1592219093489; Mon, 15 Jun 2020 04:04:53 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:1f68:7ff5:120d:64e]) by smtp.gmail.com with ESMTPSA id a1sm21641558wmj.29.2020.06.15.04.04.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 04:04:52 -0700 (PDT) In-Reply-To: <87k108wsvb.fsf@warpmail.net> (Philip K.'s message of "Mon, 15 Jun 2020 12:00:56 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:181980 Archived-At: "Philip K." 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 buffers under ? "? [...] > +(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