www.delorie.com/gnu/docs/emacs-lisp-intro/emacs-lisp-intro_211.html   search  
Buy the book!

Programming in Emacs Lisp

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

14. Counting Words in a defun

Our next project is to count the number of words in a function definition. Clearly, this can be done using some variant of count-word-region. See section Counting Words: Repetition and Regexps. If we are just going to count the words in one definition, it is easy enough to mark the definition with the C-M-h (mark-defun) command, and then call count-word-region.

However, I am more ambitious: I want to count the words and symbols in every definition in the Emacs sources and then print a graph that shows how many functions there are of each length: how many contain 40 to 49 words or symbols, how many contain 50 to 59 words or symbols, and so on. I have often been curious how long a typical function is, and this will tell.

Divide and Conquer  
14.1 What to Count?  What to count?
14.2 What Constitutes a Word or Symbol?  What constitutes a word or symbol?
14.3 The count-words-in-defun Function  Very like count-words.
14.4 Count Several defuns Within a File  Counting several defuns in a file.
14.5 Find a File  Do you want to look at a file?
14.6 lengths-list-file in Detail  A list of the lengths of many definitions.
14.7 Count Words in defuns in Different Files  Counting in definitions in different files.
14.8 Recursively Count Words in Different Files  Recursively counting in different files.
14.9 Prepare the Data for Display in a Graph  Prepare the data for display in a graph.

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003