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

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

[h-e-w] Line count?


From: Wojciech Komornicki
Subject: [h-e-w] Line count?
Date: Wed, 11 Dec 2002 19:44:55 -0600

>>>>> "Geoff" == Geoff Shilling <address@hidden> writes:

  Geoff:> Anyone know of a function that will do a line count in source code 
for all
  Geoff:> the non-commented, non-blank lines?

Here is a piece of elisp code which count lines in C/C++ code.  It is
not perfect since it will not count lines such as
     /*  comment 1 */ some code; /* comment 2 */
but I do not write code like this

;; Count the number of code lines in C++ code
(defun countlines()
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (let ((count 0) (in-comment nil))
      (while (< (point) (point-max))
        (cond
         ((looking-at "^\\s *$")                ; blank line
          t)
         ((looking-at "^\\s *//")               ; C++ comment on a line by 
itself
          t)
         ((looking-at "^\\s */\\*.*\\*/\\s *$") ; c comment on a line by itself
          t)
         ((looking-at "^\\s */\\*")             ; start of comment line
          (setq in-comment t))
         ((and in-comment (looking-at ".*\\*/")); end of c comment
          (setq in-comment nil))
         ((not in-comment)                      ; code line
          (setq count (1+ count))))
        (next-line 1))
      (message (format "Number lines: %d" count)))))

--
Wojciech Komornicki                                      Dept of Mathematics
address@hidden                                     Hamline University
http://www.hamline.edu/~wnk/                               St Paul, MN 55104
                                                                         USA

It's not enough to know the world is absurd and restrict yourself merely to
pointing out that fact.... It is wrong to expect a reward for your struggles.
The reward is the act of struggle itself, not what you win.  Even though you
can't expect to defeat the absurdity of the world, you must make the attempt.
That's morality, that's religion, that's art, that's life.

                                                                    Phil Ochs



reply via email to

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