Function: vhdl-statistics-buffer

vhdl-statistics-buffer is an interactive and byte-compiled function defined in vhdl-mode.el.gz.

Signature

(vhdl-statistics-buffer)

Documentation

Get some file statistics.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/vhdl-mode.el.gz
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Statistics

(defun vhdl-statistics-buffer ()
  "Get some file statistics."
  (interactive)
  (let ((no-stats 0)
	(no-code-lines 0)
	(no-empty-lines 0)
	(no-comm-lines 0)
	(no-comments 0)
	(no-lines (count-lines (point-min) (point-max))))
    (save-excursion
      ;; count statements
      (goto-char (point-min))
      (while (re-search-forward "\\(--.*\n\\|\"[^\"\n]*[\"\n]\\)\\|;" nil t)
	(if (match-string 1)
	    (goto-char (match-end 1))
	  (setq no-stats (1+ no-stats))))
      ;; count code lines
      (goto-char (point-min))
      (while (not (eobp))
	(unless (looking-at "^\\s-*\\(--.*\\)?$")
	  (setq no-code-lines (1+ no-code-lines)))
	(beginning-of-line 2))
      ;; count empty lines
      (goto-char (point-min))
      (while (and (re-search-forward "^\\s-*$" nil t)
		  (not (eq (point) (point-max))))
	(if (match-string 1)
	    (goto-char (match-end 1))
	  (setq no-empty-lines (1+ no-empty-lines))
	  (unless (eq (point) (point-max))
	    (forward-char))))
      ;; count comment-only lines
      (goto-char (point-min))
      (while (re-search-forward "^\\s-*--.*" nil t)
	(if (match-string 1)
	    (goto-char (match-end 1))
	  (setq no-comm-lines (1+ no-comm-lines))))
      ;; count comments
      (goto-char (point-min))
      (while (re-search-forward "--.*" nil t)
	(if (match-string 1)
	    (goto-char (match-end 1))
	  (setq no-comments (1+ no-comments)))))
    ;; print results
    (message "\n\
File statistics: \"%s\"\n\
-----------------------\n\
# statements    : %5d\n\
# code lines    : %5d\n\
# empty lines   : %5d\n\
# comment lines : %5d\n\
# comments      : %5d\n\
# total lines   : %5d\n"
	     (buffer-file-name) no-stats no-code-lines no-empty-lines
	     no-comm-lines no-comments no-lines)
    (when (featurep 'xemacs) (vhdl-show-messages))))