From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Xah Lee Newsgroups: gmane.emacs.help Subject: Re: Beginner's Lisp Question Date: Thu, 17 Jan 2008 17:24:26 -0800 (PST) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-2022-JP Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1200620451 5565 80.91.229.12 (18 Jan 2008 01:40:51 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 18 Jan 2008 01:40:51 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Fri Jan 18 02:41:07 2008 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1JFgEE-0004Ii-M4 for geh-help-gnu-emacs@m.gmane.org; Fri, 18 Jan 2008 02:41:06 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1JFgDp-00011v-HV for geh-help-gnu-emacs@m.gmane.org; Thu, 17 Jan 2008 20:40:41 -0500 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!postnews.google.com!i72g2000hsd.googlegroups.com!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 93 Original-NNTP-Posting-Host: 69.236.102.115 Original-X-Trace: posting.google.com 1200619467 28952 127.0.0.1 (18 Jan 2008 01:24:27 GMT) Original-X-Complaints-To: groups-abuse@google.com Original-NNTP-Posting-Date: Fri, 18 Jan 2008 01:24:27 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: i72g2000hsd.googlegroups.com; posting-host=69.236.102.115; posting-account=qPxGtQkAAADb6PWdLGiWVucht1ZDR6fn User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/523.12.2 (KHTML, like Gecko) Version/3.0.4 Safari/523.12.2, gzip(gfe), gzip(gfe) Original-Xref: shelby.stanford.edu gnu.emacs.help:155387 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:50791 Archived-At: 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 $B!V(BThird, 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.$B!W(B 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 $B-t(B http://xahlee.org/ On Jan 17, 10:18 am, Rasmus Pank Roulund 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