🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: fr.comp.text.tex
Article #51

Re: Estimer la taille d'un buffer (source LaTeX)

#51
From: Stefan Monnier foo
Date: Mon, 17 Sep 2001 16:03
54 lines
3505 bytes
>>>>> "Maxime" == Maxime MORGE <morge@simade.emse.fr> writes:
> je r�dige un article en LaTeX via Emacs. Cet article doit contenir moins
> de 2000 mots. j'aimerais donc disposer d'un outil me permettant d'estimer
> la taille de cet article. Id�alement, une fonction Lisp prennant en
> compte le formatage LaTeX pourrait convenir. Toutefois tout autre
> type de solution m'int�resse. Quelque chose me dit que je ne suis pas le
> seul � avoir �t� confront� � ce probl�me.

Je suis s�r que qqun � mieux � proposer, mais j'utilise le code simpliste
ci-dessous (il sera d'ailleurs inclu dans Emacs-21).  Il compte tous les
mots de 2 lettres et plus, sauf les commandes TeX (et il ne compte pas les
mots pass�s comme arguments � certaines commandes).  �a signifie
malheureusement qu'il compte aussi les mots qui sont dans les commentaires.


	Stefan


(defconst tex-discount-args-cmds
  '("begin" "end" "input" "special" "cite" "ref" "include" "includeonly"
    "documentclass" "usepackage" "label")
  "TeX commands whose arguments should not be counted as text.")

(defun tex-count-words (begin end)
  "Count the number of words in the buffer."
  (interactive
   (if (and transient-mark-mode mark-active)
       (list (region-beginning) (region-end))
     (list (point-min) (point-max))))
  ;; TODO: skip comments and math and maybe some environments.
  (save-excursion
    (goto-char begin)
    (let ((count 0))
      (while (and (< (point) end) (re-search-forward "\\<" end t))
	(if (not (eq (char-syntax (preceding-char)) ?/))
	    (progn
	      ;; Don't count single-char words.
	      (unless (looking-at ".\\>") (incf count))
	      (forward-char 1))
	  (let ((cmd
		 (buffer-substring-no-properties
		  (point) (progn (when (zerop (skip-chars-forward "a-zA-Z@"))
				   (forward-char 1))
				 (point)))))
	    (when (member cmd tex-discount-args-cmds)
	      (skip-chars-forward "*")
	      (forward-comment (point-max))
	      (when (looking-at "\\[")
		(forward-sexp 1)
		(forward-comment (point-max)))
	      (if (not (looking-at "{"))
		  (forward-char 1)
		(forward-sexp 1))))))
      (message "%s words" count))))
Technical Details
Message-ID: <5lsndl954p.fsf@rum.cs.yale.edu>
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!news-ge.switch.ch!news-zh.switch.ch!epflnews.epfl.ch!dinews.epfl.ch!rum.cs.yale.edu!rum.cs.yale.edu
References: <20010914.104752.654887343.3157@localhost.localdomain>

Show Full Headers
Complete Article Headers
X-Google-Language: FRENCH,ASCII
X-Google-Thread: f5a1a,7ba7e10ea1a2c0c
X-Google-Attributes: gidf5a1a,public
X-Google-Thread: 10ee61,7ba7e10ea1a2c0c
X-Google-Attributes: gid10ee61,public
X-Google-ArrivalTime: 2001-09-17 19:40:33 PST
Sender: monnier@rum.cs.yale.edu
From: "Stefan Monnier <foo@acm.com>" <monnier+fr.comp.applications.emacs/news/@flint.cs.yale.edu>
Newsgroups: fr.comp.text.tex,fr.comp.applications.emacs
Subject: Re: Estimer la taille d'un buffer (source LaTeX)
References: <20010914.104752.654887343.3157@localhost.localdomain>
Date: 17 Sep 2001 12:03:18 -0400
Message-ID: <5lsndl954p.fsf@rum.cs.yale.edu>
Lines: 54
User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.106
MIME-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
X-Original-NNTP-Posting-Host: rum.cs.yale.edu
X-Original-Trace: 17 Sep 2001 12:03:19 -0400, rum.cs.yale.edu
X-Original-NNTP-Posting-Host: liasg2.epfl.ch
NNTP-Posting-Host: disunds1.epfl.ch
X-Trace: epflnews.epfl.ch 1000780423 disunds1.epfl.ch (18 Sep 2001 04:33:43 +0200)
Organization: EPFL
Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!newsfeeds.belnet.be!news.belnet.be!news-ge.switch.ch!news-zh.switch.ch!epflnews.epfl.ch!dinews.epfl.ch!rum.cs.yale.edu!rum.cs.yale.edu