[Top][All Lists]

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

Re: Beginner's Lisp Question

From: Xah Lee
Subject: Re: Beginner's Lisp Question
Date: Thu, 17 Jan 2008 17:24:26 -0800 (PST)
User-agent: G2/1.0

emacs lisp has a function to call a unix command line and receive its
output. For a example, see: the xGetDimention at

Elisp Lesson: Writing image-linkify Function

So, you can call your perl and gets its output. Then, it's easy to
extract word count from there. To extract, you'll need to:

1. create a temp buffer.

2. insert the output there. (so that you have a buffer to work with,
much more easier than processing a big string)

3. use search-forward-regex or get the word count, put it to a

4. kill the temp buffer.

5. Now you can print your count, or do more computation.

Heres a sample of opening a temp buffer

; a elisp idiom for processing a file without user interaction
  (set-buffer (get-buffer-create " myTemp"))
  (insert-file-contents filePath nil nil nil t)
  ; process it ...

Elisp Lesson: Process A Thousand Files

「Third, I would be nice if I could define a alias for the "Count
Words" command. I.e. "Wordcount" and "Count Words" would run the same

emacs's symbols normally don't spaces. You might try with "\ " or
quote the whole thing. Possibly there's a workaround so you can have
command names with spaces, but best just not to do it.


On Jan 17, 10:18 am, Rasmus Pank Roulund <address@hidden>
> Hey,
> This is probably a rather stupid question.
> Either way, I use the script to count words in LaTeX document.
> The output is something like this:
>       FILE: hist_pol_oko.tex
>       Words in text: 3811
>       Words in headers: 43
>       Words in float captions: 0
>       Number of headers: 7
>       Number of floats: 0
>       Number of math inlines: 0
>       Number of math displayed: 0
> I have added the following to my .emacs file
>       (add-to-list 'TeX-command-list
>        (list "Count Words" " %s.tex"
>        'TeX-run-command nil t)
>       )
> First, when I have Count Words from within AUCTeX the status line displays
> "Count Words: Done". Instead, I would like it to display the number of
> words. In the example above it would be "3811 words".
> Second, would also be nice, if Emacs would be able to do a calculation.
> I.e. "3811 words and 10.88 normal page(s)". The second figure would be
> calculated by dividing 3811 with 350.
> Third, I would be nice if I could define a alias for the "Count Words"
> command. I.e. "Wordcount" and "Count Words" would run the same script. I
> was only able to find
>     (defalias 'perl-mode 'cperl-mode)
> in the "Learning GNU Emacs", and as far as I can tell it would not work
> with this kind of command.
> I am sorry for asking so many questions, but I am really unfamiliar with
> Lisp.
> Thanks a bunch,
> Rasmus

reply via email to

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