all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Counting SLOC in Emacs
@ 2014-11-28 11:23 Marcin Borkowski
  2014-11-28 13:41 ` Marcin Borkowski
  2014-11-28 16:46 ` Phillip Lord
  0 siblings, 2 replies; 17+ messages in thread
From: Marcin Borkowski @ 2014-11-28 11:23 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

Hello,

there is count-lines-region, but I'd like to exclude empty lines and
lines with only comments.  Is there anything like that?  (If not, I'll
try to hack it myself and share.)

TIA,

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



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-11-28 11:23 Counting SLOC in Emacs Marcin Borkowski
@ 2014-11-28 13:41 ` Marcin Borkowski
  2014-11-28 14:04   ` Stefan Monnier
  2014-11-28 16:46 ` Phillip Lord
  1 sibling, 1 reply; 17+ messages in thread
From: Marcin Borkowski @ 2014-11-28 13:41 UTC (permalink / raw)
  To: Help Gnu Emacs mailing list

On 2014-11-28, at 12:23, Marcin Borkowski wrote:

> Hello,
>
> there is count-lines-region, but I'd like to exclude empty lines and
> lines with only comments.  Is there anything like that?  (If not, I'll
> try to hack it myself and share.)

OK, so replyaing to myself: what do you think of this?

(defun count-sloc-region (beg end)
  "Count source lines of code in region (or (narrowed part of)
the buffer when no region is active).  SLOC means that empty
lines and comment-only lines are not taken into consideration."
  (interactive
   (if (use-region-p)
       (list (region-beginning) (region-end))
     (list (point-min) (point-max))))
  (save-excursion
    (save-restriction
      (narrow-to-region beg end)
      (goto-char (point-min))
      (let ((count 0))
	(while (not (eobp))
	  (if (not (comment-only-p (line-beginning-position) (line-end-position)))
	      (setq count (1+ count)))
	  (forward-line))
	(message "SLOC in %s: %s."
		 (if (use-region-p) "region" "buffer")
		 count)))))

Regards,

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



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-11-28 13:41 ` Marcin Borkowski
@ 2014-11-28 14:04   ` Stefan Monnier
  2014-11-28 14:31     ` Marcin Borkowski
  0 siblings, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2014-11-28 14:04 UTC (permalink / raw)
  To: help-gnu-emacs

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




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-11-28 14:04   ` Stefan Monnier
@ 2014-11-28 14:31     ` Marcin Borkowski
  2014-11-28 14:49       ` Stefan Monnier
       [not found]       ` <mailman.14877.1417186246.1147.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 17+ messages in thread
From: Marcin Borkowski @ 2014-11-28 14:31 UTC (permalink / raw)
  To: help-gnu-emacs


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



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-11-28 14:31     ` Marcin Borkowski
@ 2014-11-28 14:49       ` Stefan Monnier
  2014-11-28 16:00         ` Marcin Borkowski
       [not found]       ` <mailman.14877.1417186246.1147.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 17+ messages in thread
From: Stefan Monnier @ 2014-11-28 14:49 UTC (permalink / raw)
  To: help-gnu-emacs

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

Yes, it should be passed as an additional argument (you could pass
`region' or `buffer' as argument, with nil meaning "not interactive,
just return the count without displaying a message").

> 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! ;-) ).

Of course, you'll bump into further problems:

     (* foo bar
      * baz *)

will count as 1 lines, IIUC.  And similarly

     printf ("toto\n"); (* foo bar
                         * baz *)

will count as 2 lines.  You might want to try something like:

   (defun count-sloc-region (beg end kind)
     "Count source lines of code in region (or (narrowed part of)
   the buffer when no region is active).  SLOC means that empty
   lines and comment-only lines are not taken into consideration."
     (interactive
      (if (use-region-p)
          (list (region-beginning) (region-end) 'region)
        (list (point-min) (point-max) 'buffer)))
     (save-excursion
       (goto-char beg
       (let ((count 0))
         (while (< (point) end)
	  (cond
           ((nth 4 (syntax-ppss)) ;; BOL is already inside a comment.
            (let ((pos (point)))
              (goto-char (nth 8 (syntax-ppss)))
              (forward-comment (point-max))
              (if (< (point) pos) (goto-char pos)))) ;; Just paranoia.
           (t (forward-comment (point-max))))
	  (setq count (1+ count))
	  (forward-line))
        (when kind
	  (message "SLOC in %s: %s." kind count))))))


-- Stefan




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-11-28 14:49       ` Stefan Monnier
@ 2014-11-28 16:00         ` Marcin Borkowski
  2014-11-29  9:46           ` Thien-Thi Nguyen
  2014-12-02 20:43           ` Robert Thorpe
  0 siblings, 2 replies; 17+ messages in thread
From: Marcin Borkowski @ 2014-11-28 16:00 UTC (permalink / raw)
  To: help-gnu-emacs


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

>>> 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.
>
> Yes, it should be passed as an additional argument (you could pass
> `region' or `buffer' as argument, with nil meaning "not interactive,
> just return the count without displaying a message").
>
>> 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! ;-) ).
>
> Of course, you'll bump into further problems:
>
>      (* foo bar
>       * baz *)
>
> will count as 1 lines, IIUC.  And similarly
>
>      printf ("toto\n"); (* foo bar
>                          * baz *)
>
> will count as 2 lines.  You might want to try something like:

Hm.  Didn't think of this.  (I'm not really accustomed to multi-line
comments, I guess.)

>    (defun count-sloc-region (beg end kind)
>      "Count source lines of code in region (or (narrowed part of)
>    the buffer when no region is active).  SLOC means that empty
>    lines and comment-only lines are not taken into consideration."
>      (interactive
>       (if (use-region-p)
>           (list (region-beginning) (region-end) 'region)
>         (list (point-min) (point-max) 'buffer)))
>      (save-excursion
>        (goto-char beg
>        (let ((count 0))
>          (while (< (point) end)
> 	  (cond
>            ((nth 4 (syntax-ppss)) ;; BOL is already inside a comment.
>             (let ((pos (point)))
>               (goto-char (nth 8 (syntax-ppss)))
>               (forward-comment (point-max))
>               (if (< (point) pos) (goto-char pos)))) ;; Just paranoia.
>            (t (forward-comment (point-max))))
> 	  (setq count (1+ count))
> 	  (forward-line))
>         (when kind
> 	  (message "SLOC in %s: %s." kind count))))))

Wow, thanks!

I'm planning to run a code reading seminar for some ambitious students
at my faculty.  I'm wondering whether it could be a good idea to study
this;).

(In fact, not really - at least not in the beginning - let them learn
some more typical stuff before exposing young minds to Emacs Lisp with
its peculiarities, like `interactive'.  We'll start with Python and JS,
though some Common Lisp is also planned.)

> -- Stefan

Best,

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



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-11-28 11:23 Counting SLOC in Emacs Marcin Borkowski
  2014-11-28 13:41 ` Marcin Borkowski
@ 2014-11-28 16:46 ` Phillip Lord
  1 sibling, 0 replies; 17+ messages in thread
From: Phillip Lord @ 2014-11-28 16:46 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: Help Gnu Emacs mailing list


My own m-buffer.el was designed (partly) for this form of 
manipulation. So, it would be something like...

(- 
 (length (m-buffer-match-line (current-buffer)))
 (length (m-buffer-match-empty-line (current-buffer))))

I haven't written a "match-comment" function yet, but will probably add
it now that you mention it. It's easy enough to do.

Phil


Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:

> Hello,
>
> there is count-lines-region, but I'd like to exclude empty lines and
> lines with only comments.  Is there anything like that?  (If not, I'll
> try to hack it myself and share.)
>
> TIA,

-- 
Phillip Lord,                           Phone: +44 (0) 191 208 7827
Lecturer in Bioinformatics,             Email: phillip.lord@newcastle.ac.uk
School of Computing Science,            http://homepages.cs.ncl.ac.uk/phillip.lord
Room 914 Claremont Tower,               skype: russet_apples
Newcastle University,                   twitter: phillord
NE1 7RU                                 



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-11-28 16:00         ` Marcin Borkowski
@ 2014-11-29  9:46           ` Thien-Thi Nguyen
  2014-11-29 11:49             ` Marcin Borkowski
  2014-12-02 20:43           ` Robert Thorpe
  1 sibling, 1 reply; 17+ messages in thread
From: Thien-Thi Nguyen @ 2014-11-29  9:46 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 1106 bytes --]

() Marcin Borkowski <mbork@wmi.amu.edu.pl>
() Fri, 28 Nov 2014 17:00:42 +0100

   I'm planning to run a code reading seminar for some
   ambitious students at my faculty.  I'm wondering whether
   it could be a good idea to study this;).

   (In fact, not really - at least not in the beginning -
   let them learn some more typical stuff before exposing
   young minds to Emacs Lisp with its peculiarities, like
   `interactive'.  We'll start with Python and JS, though
   some Common Lisp is also planned.)

That's like "teaching" a child to walk one leg, the first
week, the other, the second, and together, only afterwards.

Ugh; Not Recommended.

Everything is peculiar in some respect.  If you choose those
of Emacs Lisp, your students may grind their teeth but they
will eventually learn some self-respect (and maybe some love
for parentheses :-D).

-- 
Thien-Thi Nguyen
   GPG key: 4C807502
   (if you're human and you know it)
      read my lisp: (responsep (questions 'technical)
                               (not (via 'mailing-list)))
                     => nil

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-11-29  9:46           ` Thien-Thi Nguyen
@ 2014-11-29 11:49             ` Marcin Borkowski
  2014-11-29 14:36               ` Grant Rettke
  0 siblings, 1 reply; 17+ messages in thread
From: Marcin Borkowski @ 2014-11-29 11:49 UTC (permalink / raw)
  To: help-gnu-emacs


On 2014-11-29, at 10:46, Thien-Thi Nguyen wrote:

> () Marcin Borkowski <mbork@wmi.amu.edu.pl>
> () Fri, 28 Nov 2014 17:00:42 +0100
>
>    I'm planning to run a code reading seminar for some
>    ambitious students at my faculty.  I'm wondering whether
>    it could be a good idea to study this;).
>
>    (In fact, not really - at least not in the beginning -
>    let them learn some more typical stuff before exposing
>    young minds to Emacs Lisp with its peculiarities, like
>    `interactive'.  We'll start with Python and JS, though
>    some Common Lisp is also planned.)
>
> That's like "teaching" a child to walk one leg, the first
> week, the other, the second, and together, only afterwards.
>
> Ugh; Not Recommended.
>
> Everything is peculiar in some respect.  If you choose those
> of Emacs Lisp, your students may grind their teeth but they
> will eventually learn some self-respect (and maybe some love
> for parentheses :-D).

I'm not sure if I get you.

What I meant was: in this Elisp code, you have some really atypical
things (from general programming point if view), like the tight coupling
between the language and buffer (as a data structure).  Given that my
students are beginners, some of them only exposed to really basics of
programming, I don't want them to deal with too many new concepts at
once.  I view it rather as teaching to walk the first few weeks, and
only then teaching to run;-).

Best,

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



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-11-29 11:49             ` Marcin Borkowski
@ 2014-11-29 14:36               ` Grant Rettke
  0 siblings, 0 replies; 17+ messages in thread
From: Grant Rettke @ 2014-11-29 14:36 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: Emacs Help

DrRacket is a great place to run at whatever speed you want, training
wheels or not, in a safe and pleasant manner, too.

http://racket-lang.org/

On Sat, Nov 29, 2014 at 5:49 AM, Marcin Borkowski <mbork@wmi.amu.edu.pl> wrote:
>
> On 2014-11-29, at 10:46, Thien-Thi Nguyen wrote:
>
>> () Marcin Borkowski <mbork@wmi.amu.edu.pl>
>> () Fri, 28 Nov 2014 17:00:42 +0100
>>
>>    I'm planning to run a code reading seminar for some
>>    ambitious students at my faculty.  I'm wondering whether
>>    it could be a good idea to study this;).
>>
>>    (In fact, not really - at least not in the beginning -
>>    let them learn some more typical stuff before exposing
>>    young minds to Emacs Lisp with its peculiarities, like
>>    `interactive'.  We'll start with Python and JS, though
>>    some Common Lisp is also planned.)
>>
>> That's like "teaching" a child to walk one leg, the first
>> week, the other, the second, and together, only afterwards.
>>
>> Ugh; Not Recommended.
>>
>> Everything is peculiar in some respect.  If you choose those
>> of Emacs Lisp, your students may grind their teeth but they
>> will eventually learn some self-respect (and maybe some love
>> for parentheses :-D).
>
> I'm not sure if I get you.
>
> What I meant was: in this Elisp code, you have some really atypical
> things (from general programming point if view), like the tight coupling
> between the language and buffer (as a data structure).  Given that my
> students are beginners, some of them only exposed to really basics of
> programming, I don't want them to deal with too many new concepts at
> once.  I view it rather as teaching to walk the first few weeks, and
> only then teaching to run;-).
>
> Best,
>
> --
> Marcin Borkowski
> http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski
> Faculty of Mathematics and Computer Science
> Adam Mickiewicz University
>



-- 
Grant Rettke
gcr@wisdomandwonder.com | http://www.wisdomandwonder.com/
“Wisdom begins in wonder.” --Socrates
((λ (x) (x x)) (λ (x) (x x)))
“Life has become immeasurably better since I have been forced to stop
taking it seriously.” --Thompson



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
       [not found]       ` <mailman.14877.1417186246.1147.help-gnu-emacs@gnu.org>
@ 2014-12-02 14:35         ` Ted Zlatanov
  2014-12-03  1:14           ` Leo Liu
  0 siblings, 1 reply; 17+ messages in thread
From: Ted Zlatanov @ 2014-12-02 14:35 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, 28 Nov 2014 09:49:27 -0500 Stefan Monnier <monnier@iro.umontreal.ca> wrote: 

SM>    (defun count-sloc-region (beg end kind)
SM>      "Count source lines of code in region (or (narrowed part of)
SM>    the buffer when no region is active).  SLOC means that empty
SM>    lines and comment-only lines are not taken into consideration."
SM>      (interactive
SM>       (if (use-region-p)
SM>           (list (region-beginning) (region-end) 'region)
SM>         (list (point-min) (point-max) 'buffer)))
SM>      (save-excursion
SM>        (goto-char beg
SM>        (let ((count 0))
SM>          (while (< (point) end)
SM> 	  (cond
SM>            ((nth 4 (syntax-ppss)) ;; BOL is already inside a comment.
SM>             (let ((pos (point)))
SM>               (goto-char (nth 8 (syntax-ppss)))
SM>               (forward-comment (point-max))
SM>               (if (< (point) pos) (goto-char pos)))) ;; Just paranoia.
SM>            (t (forward-comment (point-max))))
SM> 	  (setq count (1+ count))
SM> 	  (forward-line))
SM>         (when kind
SM> 	  (message "SLOC in %s: %s." kind count))))))

This is useful.

Could we have this added to `count-lines-region' with an optional
parameter, or provided by `prog-mode' specifically? It even merits a
modeline indicator that users can enable, I think.

Ted


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-11-28 16:00         ` Marcin Borkowski
  2014-11-29  9:46           ` Thien-Thi Nguyen
@ 2014-12-02 20:43           ` Robert Thorpe
  2014-12-02 22:10             ` Marcin Borkowski
  1 sibling, 1 reply; 17+ messages in thread
From: Robert Thorpe @ 2014-12-02 20:43 UTC (permalink / raw)
  To: Marcin Borkowski; +Cc: help-gnu-emacs

Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:

>>      (* foo bar
>>       * baz *)
>>
>> will count as 1 lines, IIUC.  And similarly
>>
>>      printf ("toto\n"); (* foo bar
>>                          * baz *)
>>
>> will count as 2 lines.  You might want to try something like:
>
> Hm.  Didn't think of this.  (I'm not really accustomed to multi-line
> comments, I guess.)

I think for practical purposes it's best to use script like David
Wheeler's SLOCount called from Emacs.

Re-writing it in Elisp is an interesting exercise though.

BR,
Robert Thorpe



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-12-02 20:43           ` Robert Thorpe
@ 2014-12-02 22:10             ` Marcin Borkowski
  0 siblings, 0 replies; 17+ messages in thread
From: Marcin Borkowski @ 2014-12-02 22:10 UTC (permalink / raw)
  To: help-gnu-emacs


On 2014-12-02, at 21:43, Robert Thorpe wrote:

> Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
>
>>>      (* foo bar
>>>       * baz *)
>>>
>>> will count as 1 lines, IIUC.  And similarly
>>>
>>>      printf ("toto\n"); (* foo bar
>>>                          * baz *)
>>>
>>> will count as 2 lines.  You might want to try something like:
>>
>> Hm.  Didn't think of this.  (I'm not really accustomed to multi-line
>> comments, I guess.)
>
> I think for practical purposes it's best to use script like David
> Wheeler's SLOCount called from Emacs.

Not really: Elisp-only solution has a few benefits:

1. portability
2. it adapts itself automatically to langauges which can be parsed by
Emacs modes.
3. maybe speed (C might be faster, but with Elisp you don't have to
start a process - this might require some measurement, though).

> Re-writing it in Elisp is an interesting exercise though.

4. Exactly, a good way to learn/teach something about how Emacs (and its
language modes) work.

> BR,
> Robert Thorpe

Best,

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



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-12-02 14:35         ` Ted Zlatanov
@ 2014-12-03  1:14           ` Leo Liu
  2014-12-30 14:05             ` Marcin Borkowski
  0 siblings, 1 reply; 17+ messages in thread
From: Leo Liu @ 2014-12-03  1:14 UTC (permalink / raw)
  To: help-gnu-emacs

On 2014-12-02 09:35 -0500, Ted Zlatanov wrote:
> This is useful.
>
> Could we have this added to `count-lines-region' with an optional
> parameter, or provided by `prog-mode' specifically? It even merits a
> modeline indicator that users can enable, I think.
>
> Ted

I had such need last year but only used it a few days and then totally
forgotten (never needed again). The code is still here
https://github.com/leoliu/sloc.el/blob/master/sloc.el

Leo




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-12-03  1:14           ` Leo Liu
@ 2014-12-30 14:05             ` Marcin Borkowski
  2014-12-31 11:50               ` Leo Liu
  0 siblings, 1 reply; 17+ messages in thread
From: Marcin Borkowski @ 2014-12-30 14:05 UTC (permalink / raw)
  To: Leo Liu; +Cc: help-gnu-emacs


On 2014-12-03, at 02:14, Leo Liu <sdl.web@gmail.com> wrote:

> On 2014-12-02 09:35 -0500, Ted Zlatanov wrote:
>> This is useful.
>>
>> Could we have this added to `count-lines-region' with an optional
>> parameter, or provided by `prog-mode' specifically? It even merits a
>> modeline indicator that users can enable, I think.
>>
>> Ted
>
> I had such need last year but only used it a few days and then totally
> forgotten (never needed again). The code is still here
> https://github.com/leoliu/sloc.el/blob/master/sloc.el

Hi,

I finally had some time to look into the code.  Could you tell me why
this?

      (unless (looking-at-p "^\\s-*$")

(line 46 in sloc.el)?  If I get it correctly, it ignores blank lines
/ending in any number of hyphens/ (possibly zero).  Why?

Also, this

    (let ((beg (min beg end))
          (end (max beg end))

is probably not necessary, or do I miss something?

> Leo

Best,

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



^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-12-30 14:05             ` Marcin Borkowski
@ 2014-12-31 11:50               ` Leo Liu
  2014-12-31 13:25                 ` Marcin Borkowski
  0 siblings, 1 reply; 17+ messages in thread
From: Leo Liu @ 2014-12-31 11:50 UTC (permalink / raw)
  To: help-gnu-emacs

On 2014-12-31 01:05 +1100, Marcin Borkowski wrote:
> I finally had some time to look into the code.  Could you tell me why
> this?
>
>       (unless (looking-at-p "^\\s-*$")

It ignores blank lines as the doc-string says.

> (line 46 in sloc.el)? If I get it correctly, it ignores blank lines
> /ending in any number of hyphens/ (possibly zero).  Why?
>
> Also, this
>
>     (let ((beg (min beg end))
>           (end (max beg end))
>
> is probably not necessary, or do I miss something?

Either I was being defensive or there were some cases that could have
end < beg.

HTH,
Leo




^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: Counting SLOC in Emacs
  2014-12-31 11:50               ` Leo Liu
@ 2014-12-31 13:25                 ` Marcin Borkowski
  0 siblings, 0 replies; 17+ messages in thread
From: Marcin Borkowski @ 2014-12-31 13:25 UTC (permalink / raw)
  To: help-gnu-emacs


On 2014-12-31, at 12:50, Leo Liu <sdl.web@gmail.com> wrote:

> On 2014-12-31 01:05 +1100, Marcin Borkowski wrote:
>> I finally had some time to look into the code.  Could you tell me why
>> this?
>>
>>       (unless (looking-at-p "^\\s-*$")
>
> It ignores blank lines as the doc-string says.

Ah, my bad: it's \s- that matches whitespace, not \s.

>> (line 46 in sloc.el)? If I get it correctly, it ignores blank lines
>> /ending in any number of hyphens/ (possibly zero).  Why?
>>
>> Also, this
>>
>>     (let ((beg (min beg end))
>>           (end (max beg end))
>>
>> is probably not necessary, or do I miss something?
>
> Either I was being defensive or there were some cases that could have
> end < beg.

I guess that would not be possible, but I might be mistaken.

> HTH,
> Leo

Yes, thanks!

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



^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2014-12-31 13:25 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-28 11:23 Counting SLOC in Emacs Marcin Borkowski
2014-11-28 13:41 ` Marcin Borkowski
2014-11-28 14:04   ` Stefan Monnier
2014-11-28 14:31     ` Marcin Borkowski
2014-11-28 14:49       ` Stefan Monnier
2014-11-28 16:00         ` Marcin Borkowski
2014-11-29  9:46           ` Thien-Thi Nguyen
2014-11-29 11:49             ` Marcin Borkowski
2014-11-29 14:36               ` Grant Rettke
2014-12-02 20:43           ` Robert Thorpe
2014-12-02 22:10             ` Marcin Borkowski
     [not found]       ` <mailman.14877.1417186246.1147.help-gnu-emacs@gnu.org>
2014-12-02 14:35         ` Ted Zlatanov
2014-12-03  1:14           ` Leo Liu
2014-12-30 14:05             ` Marcin Borkowski
2014-12-31 11:50               ` Leo Liu
2014-12-31 13:25                 ` Marcin Borkowski
2014-11-28 16:46 ` Phillip Lord

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.