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

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

Re: Counting SLOC in Emacs


From: Marcin Borkowski
Subject: Re: Counting SLOC in Emacs
Date: Fri, 28 Nov 2014 15:31:09 +0100

On 2014-11-28, at 15:04, Stefan Monnier wrote:

>>   (save-excursion
>>     (save-restriction
>>       (narrow-to-region beg end)
>>       (goto-char (point-min))
>>       (let ((count 0))
>>         (while (not (eobp))
>
> I'd use
>
>      (save-excursion
>        (goto-char beg
>        (let ((count 0))
>          (while (< (point) end)
> since narrowing can have all kinds of weird effects.

OK.

>>      (message "SLOC in %s: %s."
>>               (if (use-region-p) "region" "buffer")
>>               count)))))
>
> And don't re-call use-region-p here, in the off-chance that it returns
> something else than in the first call.  E.g. you can use (if (and (=
> beg (point-min)) (= end (point-max))) "buffer" "region") instead.

I don't think it's probable (or even possible), but definitely my
solution was not very elegant.  I wonder whether (let)ting
(use-region-p) to a temporary variable wouldn't be better.

Anyway, thanks for your review!  I will write a blog post about this
function (googling for "emacs count sloc" doesn't yield anything
useful, let's change it! ;-) ).

>         Stefan


-- 
Marcin Borkowski
http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
Faculty of Mathematics and Computer Science
Adam Mickiewicz University



reply via email to

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