all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Beginner's Lisp Question
@ 2008-01-17 18:18 Rasmus Pank Roulund
  0 siblings, 0 replies; 2+ messages in thread
From: Rasmus Pank Roulund @ 2008-01-17 18:18 UTC (permalink / raw)
  To: help-gnu-emacs

Hey,
This is probably a rather stupid question.
Either way, I use the texcount.pl 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" "texcount.pl %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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Beginner's Lisp Question
       [not found] <mailman.6235.1200593955.18990.help-gnu-emacs@gnu.org>
@ 2008-01-18  1:24 ` Xah Lee
  0 siblings, 0 replies; 2+ messages in thread
From: Xah Lee @ 2008-01-18  1:24 UTC (permalink / raw)
  To: help-gnu-emacs

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
http://xahlee.org/emacs/elisp_image_tag.html

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
variable.

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
(save-current-buffer
  (set-buffer (get-buffer-create " myTemp"))
  (insert-file-contents filePath nil nil nil t)
  ; process it ...
)

detail:
Elisp Lesson: Process A Thousand Files
http://xahlee.org/emacs/elisp_link_report.html

「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.」

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.

  Xah
  xah@xahlee.org
\xAD\xF4 http://xahlee.org/


On Jan 17, 10:18 am, Rasmus Pank Roulund <rasmus.p...@gmail.com>
wrote:
> Hey,
> This is probably a rather stupid question.
> Either way, I use the texcount.pl 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" "texcount.pl %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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-01-18  1:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.6235.1200593955.18990.help-gnu-emacs@gnu.org>
2008-01-18  1:24 ` Beginner's Lisp Question Xah Lee
2008-01-17 18:18 Rasmus Pank Roulund

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.