all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Xah Lee <xah@xahlee.org>
To: help-gnu-emacs@gnu.org
Subject: Re: Beginner's Lisp Question
Date: Thu, 17 Jan 2008 17:24:26 -0800 (PST)	[thread overview]
Message-ID: <a59347f4-4e7f-459a-8752-bd2c1f953d5a@i72g2000hsd.googlegroups.com> (raw)
In-Reply-To: mailman.6235.1200593955.18990.help-gnu-emacs@gnu.org

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

       reply	other threads:[~2008-01-18  1:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.6235.1200593955.18990.help-gnu-emacs@gnu.org>
2008-01-18  1:24 ` Xah Lee [this message]
2008-01-17 18:18 Beginner's Lisp Question Rasmus Pank Roulund

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a59347f4-4e7f-459a-8752-bd2c1f953d5a@i72g2000hsd.googlegroups.com \
    --to=xah@xahlee.org \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.