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: Stefan Monnier
Subject: Re: Counting SLOC in Emacs
Date: Fri, 28 Nov 2014 09:04:25 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (gnu/linux)

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

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


        Stefan




reply via email to

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