[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 14:41:30 +0100 |
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
- Counting SLOC in Emacs, Marcin Borkowski, 2014/11/28
- Re: Counting SLOC in Emacs,
Marcin Borkowski <=
- Re: Counting SLOC in Emacs, Stefan Monnier, 2014/11/28
- Re: Counting SLOC in Emacs, Marcin Borkowski, 2014/11/28
- Re: Counting SLOC in Emacs, Stefan Monnier, 2014/11/28
- Re: Counting SLOC in Emacs, Marcin Borkowski, 2014/11/28
- Re: Counting SLOC in Emacs, Thien-Thi Nguyen, 2014/11/29
- Re: Counting SLOC in Emacs, Marcin Borkowski, 2014/11/29
- Re: Counting SLOC in Emacs, Grant Rettke, 2014/11/29
Re: Counting SLOC in Emacs, Phillip Lord, 2014/11/28