unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Rolf Ade <rolf@pointsman.de>
To: help-gnu-emacs@gnu.org
Subject: Re: List of buffers under version control?
Date: Thu, 28 Jul 2016 23:52:24 +0200	[thread overview]
Message-ID: <87d1lxv3af.fsf@linux-qg7d.fritz.box> (raw)
In-Reply-To: mailman.2252.1469740513.26859.help-gnu-emacs@gnu.org


John Mastro <john.b.mastro@gmail.com> writes:
> Rolf Ade <rolf@pointsman.de> wrote:
>>
>> (loop for buffer in (buffer-list)
>>       until (if (vc-backend (buffer-file-name buffer))
>>                 (buffer-modified-p buffer))
>>       finally return (if (and (buffer-modified-p buffer)
>>                               (vc-backend (buffer-file-name buffer)))
>>                          1
>>                        0))
>>
>
> Glad it helps. You could do something like this to avoid repeating the
> calls to `vc-backend' and `buffer-modified-p':
>
> (if (loop for buffer in (buffer-list)
>           thereis (and (vc-backend (buffer-file-name buffer))
>                        (buffer-modified-p buffer)))
>     1
>   0)

It's probably not so much about avoiding unnecessary calls (my version
does only 1 call of vc-backend and 1 call of buffer-modified-p more than
yours, no matter how long the buffer-list is (mine currently is 385)).

Your version is not only lesser code but also more to the point written
and better to understand. Thanks again.

(And learned about thereis. And tooked the opportunity, to refresh my
understanding of (the capabilities of) loop.)


  parent reply	other threads:[~2016-07-28 21:52 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-28  0:03 List of buffers under version control? Rolf Ade
2016-07-28  4:05 ` Rusi
2016-07-28 19:31   ` Rolf Ade
2016-07-28 19:52     ` John Mastro
2016-07-28 19:58       ` John Mastro
2016-07-28 19:56     ` Marcin Borkowski
     [not found]     ` <mailman.2241.1469735551.26859.help-gnu-emacs@gnu.org>
2016-07-28 21:01       ` Rolf Ade
2016-07-28 21:14         ` John Mastro
2016-07-28 21:25           ` Drew Adams
     [not found]           ` <mailman.2253.1469741176.26859.help-gnu-emacs@gnu.org>
2016-07-28 22:27             ` Rolf Ade
     [not found]         ` <mailman.2252.1469740513.26859.help-gnu-emacs@gnu.org>
2016-07-28 21:52           ` Rolf Ade [this message]
2016-07-29  1:42         ` Stefan Monnier
2016-07-28  5:12 ` Yuri Khan
     [not found] ` <mailman.2177.1469682795.26859.help-gnu-emacs@gnu.org>
2016-07-28 19:31   ` Rolf Ade

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d1lxv3af.fsf@linux-qg7d.fritz.box \
    --to=rolf@pointsman.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).