emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Paul Sexton <psexton@xnet.co.nz>
To: emacs-orgmode@gnu.org
Subject: Re: Context-sensitive word count in org mode (elisp)
Date: Wed, 16 Feb 2011 20:34:15 +0000 (UTC)	[thread overview]
Message-ID: <loom.20110216T212901-393@post.gmane.org> (raw)
In-Reply-To: 4D5B9CA8.5070100@christianmoe.com

Christian Moe <mail <at> christianmoe.com> writes:

> 
> Forgot to add the code.
> 
> #+begin_src emacs-lisp
>    ;; Adapted from code posted by Paul Sexton <2011-02-16 Wed 4:51am>
>    ;; - Everything now contained in one function
>    ;; - Will count correct number of words inside Latex macro
> 
>    (defun org-word-count (beg end)
>    (interactive "r")
>    (unless mark-active
>      (setf beg (point-min)
> 	  end (point-max)))
>    (let ((wc 0)
> 	(latex-macro-regexp "\\\\[A-Za-z]+\\(\\[[^]]*\\]\\| 
> \\){\\([^}]*\\)}"))   ; CHANGED
>      (save-excursion
>        (goto-char beg)
>        (while (< (point) end)
>          (re-search-forward "\\w+\\W*")
>          (cond
>           ((or (org-in-commented-line) (org-at-table-p)) ; CHANGED
>            nil)
>           ((looking-at org-any-link-re)
>            (goto-char (match-end 0)))
>           ((save-excursion
>              (backward-char)
>              (looking-at latex-macro-regexp))
>            (goto-char (match-beginning 2))  ; CHANGED
>            (setf wc (+ 2 wc)))
>           (t
>            (incf wc)))))
>      (message (format "%d words in %s." wc
>                       (if mark-active "region" "buffer")))))
> #+end_src
> 

Thanks, I wasn't aware of those pre-existing functions.

I don't agree with changing '(match-end 0)' to '(match-beginning 2)'
however. For most latex macros, I don't want to count the words inside
the macro's arguments. For example, I don't want the next of footnotes
to be included in the word count. However others differ, and there will
always be cases where one DOES want to count the macro arguments - so maybe
org-word-count should do this optionally.

Paul

  reply	other threads:[~2011-02-16 20:34 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-16  3:51 Context-sensitive word count in org mode (elisp) Paul Sexton
2011-02-16  9:12 ` Christian Moe
2011-02-16  9:47   ` Dan Davison
2011-02-16  9:45 ` Christian Moe
2011-02-16 20:34   ` Paul Sexton [this message]
2011-02-17 10:02     ` Christian Moe
2011-02-17 18:57       ` Eric Schulte
2011-02-16 10:14 ` Bastien
2011-02-16 18:15   ` Samuel Wales
2011-02-16 13:03 ` Joost Kremers
2011-02-16 23:28 ` Paul Sexton
2011-02-17 16:50   ` Samuel Wales
2011-02-17 18:55     ` Paul Sexton
2011-03-27 19:40       ` [Orgmode] " Samuel Wales
2011-02-18 14:34   ` Bastien
2011-02-20 21:49     ` Paul Sexton
2011-02-21 23:30       ` Samuel Wales
     [not found]     ` <4D601314.8000701@xnet.co.nz>
2011-02-22 11:28       ` Bastien
  -- strict thread matches above, loose matches on Subject: below --
2011-02-16 16:22 Benjamin Beckwith
2011-02-16 23:31 ` Paul Sexton

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=loom.20110216T212901-393@post.gmane.org \
    --to=psexton@xnet.co.nz \
    --cc=emacs-orgmode@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).