From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ted Zlatanov Newsgroups: gmane.emacs.help Subject: Re: Counting SLOC in Emacs Date: Tue, 02 Dec 2014 09:35:59 -0500 Organization: =?utf-8?B?0KLQtdC+0LTQvtGAINCX0LvQsNGC0LDQvdC+0LI=?= @ Cienfuegos Message-ID: <874mterueo.fsf@lifelogs.com> References: <877fyfk1qn.fsf@wmi.amu.edu.pl> <8761dzjvcl.fsf@wmi.amu.edu.pl> <874mtjjt31.fsf@wmi.amu.edu.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1417531232 5026 80.91.229.3 (2 Dec 2014 14:40:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Dec 2014 14:40:32 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Dec 02 15:40:23 2014 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Xvoco-0008GF-DE for geh-help-gnu-emacs@m.gmane.org; Tue, 02 Dec 2014 15:40:22 +0100 Original-Received: from localhost ([::1]:37145 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xvoco-0000lz-23 for geh-help-gnu-emacs@m.gmane.org; Tue, 02 Dec 2014 09:40:22 -0500 Original-Path: usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!news-2.dfn.de!news.dfn.de!storethat.news.telefonica.de!telefonica.de!weretis.net!feeder1.news.weretis.net!news.albasani.net!.POSTED!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 33 Original-X-Trace: news.albasani.net TDr5IP2BD5Fk56KstY+5TuYLcl89BQReralO37qbiCJ9bqUnqBv+yKwqWi2GHt1zkzFMd5lNM5N63PYuEywM+w== Original-NNTP-Posting-Date: Tue, 2 Dec 2014 14:35:13 +0000 (UTC) Injection-Info: news.albasani.net; logging-data="ZeXV2e0zMTAjRxyLZfY5dDnyMMxi5VVFk4kWaK9LMZ0eMVdoMWYzmS+yqUpsogYcdASq5iteYfcXMSEMAKmFwh8lviv8KMPJKyhLluqCBdZrcyMEHNglx/KCXxCBEADv"; mail-complaints-to="abuse@albasani.net" User-Agent: Gnus/5.130012 (Ma Gnus v0.12) Emacs/25.0.50 (gnu/linux) X-Face: bd.DQ~'29fIs`T_%O%C\g%6jW)yi[zuz6; d4V0`@y-~$#3P_Ng{@m+e4o<4P'#(_GJQ%TT= D}[Ep*b!\e,fBZ'j_+#"Ps?s2!4H2-Y"sx" Cancel-Lock: sha1:SYny4hw0M0yZgZ68VafvSAinGdo= sha1:pS5V3wCybtI6MzoYWE57SESGMHM= Original-Xref: usenet.stanford.edu gnu.emacs.help:209088 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:101367 Archived-At: On Fri, 28 Nov 2014 09:49:27 -0500 Stefan Monnier 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