Next: Readying a Graph, Previous: Counting Words, Up: Top [Contents][Index]
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-words-example
.
See Counting via 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-words-example
.
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 | ||
• Words and Symbols | What to count? | |
• Syntax | What constitutes a word or symbol? | |
• count-words-in-defun | Very like count-words-example .
| |
• Several defuns | Counting several defuns in a file. | |
• Find a File | Do you want to look at a file? | |
• lengths-list-file | A list of the lengths of many definitions. | |
• Several files | Counting in definitions in different files. | |
• Several files recursively | Recursively counting in different files. | |
• Prepare the data | Prepare the data for display in a graph. |
Next: Readying a Graph, Previous: Counting Words, Up: Top [Contents][Index]