unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#9429: 24.0.50; Extended count-words
@ 2011-09-03 16:41 Reuben Thomas
  2011-09-07  1:51 ` Stefan Monnier
  0 siblings, 1 reply; 13+ messages in thread
From: Reuben Thomas @ 2011-09-03 16:41 UTC (permalink / raw)
  To: 9429

I noticed the function count-words-region recently, which is similar to
a function ‘wc’ which I’ve been using for some time.

I noticed that it was possible to combine the two functions without
disturbing either. I offer the following superset function, which has
the convenient name “wc”, for use as an unbound command, i.e. M-x wc
RET.

The implementation below is intended to replace count-words-region for
users, since it behaves like count-words-region, but with some
additional features: it counts the whole buffer if there is no region,
and allows the word count to be inserted in the buffer when called
interactively, by use of a prefix argument. However, for the moment it
does this by calling count-words-region, rather than reimplementing it.

It seems to me that it could, however, replace count-words-region
(ideally, from my point of view, with a “wc” convenience alias), and I’d
be happy to supply such a definition.

I have an Emacs copyright assignment on file, and I’d be delighted if
this function were adopted in Emacs.

(defun wc (start end)
  "Print the number of words in the region or buffer.
When called interactively, the word count is printed in echo area,
unless a prefix argument is given."
  (interactive "r")
  (if (called-interactively-p 'interactive)
      (if (use-region-p) (setq start (region-beginning) end (region-end))
        (setq start (point-min) end (point-max))))
  (let ((matches (count-words-region start end)))
    (if (or (not (called-interactively-p 'interactive)) current-prefix-arg)
        (insert-string (number-to-string matches))
      (message "%s has %d words"
               (if (use-region-p) "Region" "Buffer")
               matches))))


In GNU Emacs 24.0.50.2 (x86_64-unknown-linux-gnu, GTK+ Version 2.24.4)
 of 2011-09-03 on skwd
Windowing system distributor `The X.Org Foundation', version 11.0.11001000
Important settings:
  value of $LC_ALL: nil
  value of $LC_COLLATE: nil
  value of $LC_CTYPE: nil
  value of $LC_MESSAGES: nil
  value of $LC_MONETARY: nil
  value of $LC_NUMERIC: nil
  value of $LC_TIME: nil
  value of $LANG: en_GB.UTF-8
  value of $XMODIFIERS: nil
  locale-coding-system: utf-8-unix
  default enable-multibyte-characters: t

Major mode: Emacs-Lisp

Minor modes in effect:
  recentf-mode: t
  show-paren-mode: t
  server-mode: t
  savehist-mode: t
  minibuffer-electric-default-mode: t
  iswitchb-mode: t
  icomplete-mode: t
  global-whitespace-mode: t
  global-auto-revert-mode: t
  desktop-save-mode: t
  tooltip-mode: t
  mouse-wheel-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  column-number-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
M-> M-< M-x M-x r e p o r t - e m a c s - b u g <r
eturn>

Recent messages:
Loading vc-git...done
Wrote /home/rrt/.emacs.desktop.lock
Desktop: 4 buffers restored, 40 to restore lazily.
For information about GNU Emacs and the GNU system, type C-h C-a.
Mark set [2 times]
Loading cperl-mode...done
Loading make-mode...done
Loading /home/rrt/local/share/emacs/site-lisp/lua-mode.el (source)...
prefix key set to "C-c"
Loading /home/rrt/local/share/emacs/site-lisp/lua-mode.el (source)...done

Load-path shadows:
/home/rrt/.emacs.d/elpa/dictionary-1.8.7/dictionary-init hides /usr/local/share/emacs/24.0.50/site-lisp/dictionary-el/dictionary-init
/home/rrt/.emacs.d/elpa/dictionary-1.8.7/dictionary hides /usr/local/share/emacs/24.0.50/site-lisp/dictionary-el/dictionary
/home/rrt/.emacs.d/elpa/dictionary-1.8.7/link hides /usr/local/share/emacs/24.0.50/site-lisp/dictionary-el/link
/home/rrt/.emacs.d/elpa/dictionary-1.8.7/connection hides /usr/local/share/emacs/24.0.50/site-lisp/dictionary-el/connection
/home/rrt/local/share/emacs/site-lisp/dict hides /usr/local/share/emacs/24.0.50/site-lisp/emacs-goodies-el/dict
/usr/share/emacs-snapshot/site-lisp/ruby1.8-elisp/ruby-mode hides /usr/local/share/emacs/24.0.50/lisp/progmodes/ruby-mode
/usr/local/share/emacs/24.0.50/site-lisp/auctex/tex-style hides /usr/share/emacs/site-lisp/auctex/tex-style
/usr/local/share/emacs/24.0.50/site-lisp/auctex/tex-mik hides /usr/share/emacs/site-lisp/auctex/tex-mik
/usr/local/share/emacs/24.0.50/site-lisp/auctex/multi-prompt hides /usr/share/emacs/site-lisp/auctex/multi-prompt
/usr/local/share/emacs/24.0.50/site-lisp/auctex/tex-jp hides /usr/share/emacs/site-lisp/auctex/tex-jp
/usr/local/share/emacs/24.0.50/site-lisp/auctex/tex-info hides /usr/share/emacs/site-lisp/auctex/tex-info
/usr/local/share/emacs/24.0.50/site-lisp/auctex/latex hides /usr/share/emacs/site-lisp/auctex/latex
/usr/local/share/emacs/24.0.50/site-lisp/auctex/tex hides /usr/share/emacs/site-lisp/auctex/tex
/usr/local/share/emacs/24.0.50/site-lisp/auctex/texmathp hides /usr/share/emacs/site-lisp/auctex/texmathp
/usr/local/share/emacs/24.0.50/site-lisp/auctex/context-nl hides /usr/share/emacs/site-lisp/auctex/context-nl
/usr/local/share/emacs/24.0.50/site-lisp/auctex/tex-font hides /usr/share/emacs/site-lisp/auctex/tex-font
/usr/local/share/emacs/24.0.50/site-lisp/auctex/toolbar-x hides /usr/share/emacs/site-lisp/auctex/toolbar-x
/usr/local/share/emacs/24.0.50/site-lisp/auctex/tex-buf hides /usr/share/emacs/site-lisp/auctex/tex-buf
/usr/local/share/emacs/24.0.50/site-lisp/auctex/tex-fptex hides /usr/share/emacs/site-lisp/auctex/tex-fptex
/usr/local/share/emacs/24.0.50/site-lisp/auctex/bib-cite hides /usr/share/emacs/site-lisp/auctex/bib-cite
/usr/local/share/emacs/24.0.50/site-lisp/auctex/context-en hides /usr/share/emacs/site-lisp/auctex/context-en
/usr/local/share/emacs/24.0.50/site-lisp/auctex/tex-fold hides /usr/share/emacs/site-lisp/auctex/tex-fold
/usr/local/share/emacs/24.0.50/site-lisp/auctex/tex-bar hides /usr/share/emacs/site-lisp/auctex/tex-bar
/usr/local/share/emacs/24.0.50/site-lisp/auctex/context hides /usr/share/emacs/site-lisp/auctex/context
/usr/local/share/emacs/24.0.50/site-lisp/auctex/font-latex hides /usr/share/emacs/site-lisp/auctex/font-latex
/usr/local/share/emacs/24.0.50/site-lisp/psgml/psgml-sysdep hides /usr/share/emacs/site-lisp/psgml/psgml-sysdep
/usr/local/share/emacs/24.0.50/site-lisp/psgml/psgml-init hides /usr/share/emacs/site-lisp/psgml/psgml-init
/usr/local/share/emacs/24.0.50/site-lisp/psgml/psgml-other hides /usr/share/emacs/site-lisp/psgml/psgml-other
/usr/local/share/emacs/24.0.50/site-lisp/psgml/psgml-html hides /usr/share/emacs/site-lisp/psgml/psgml-html
/usr/local/share/emacs/24.0.50/site-lisp/psgml/psgml hides /usr/share/emacs/site-lisp/psgml/psgml

Features:
(shadow sort gnus-util mail-extr message format-spec rfc822 mml mml-sec
mm-decode mm-bodies mm-encode mail-parse rfc2231 rfc2047 rfc2045
ietf-drums mm-util mail-prsvr mailabbrev mail-utils gmm-utils mailheader
emacsbug inform-mode lua-mode make-mode cperl-mode vc-git cc-mode
cc-fonts cc-guess cc-menus cc-cmds cc-styles cc-align cc-engine cc-vars
cc-defs flymake compile comint ring face-remap regexp-opt flyspell
smart-quotes auto-dictionary-autoloads c-eldoc-autoloads
dictionary-autoloads diff-git-autoloads dired-isearch-autoloads
full-ack-autoloads guess-style-autoloads kill-ring-search-autoloads
magit-autoloads mv-shell-autoloads tumble-autoloads
http-post-simple-autoloads package tabulated-list completing-help
recentf tree-widget wid-edit uniquify paren server savehist
minibuf-eldef iswitchb icomplete whitespace autorevert desktop cus-start
cus-load ropemacs pymacs go-mode-load ffap ispell advice advice-preload
yasnippet help-fns derived edmacro kmacro easymenu assoc cl psgml-init
muse-autoloads emacs-goodies-el emacs-goodies-custom
emacs-goodies-loaddefs easy-mmode preview-latex tex-site auto-loads
user-site-loaddefs time-date tooltip ediff-hook vc-hooks lisp-float-type
mwheel x-win x-dnd tool-bar dnd fontset image fringe lisp-mode register
page menu-bar rfn-eshadow timer select scroll-bar mouse jit-lock
font-lock syntax facemenu font-core frame cham georgian utf-8-lang
misc-lang vietnamese tibetan thai tai-viet lao korean japanese hebrew
greek romanian slovak czech european ethiopic indian cyrillic chinese
case-table epa-hook jka-cmpr-hook help simple abbrev minibuffer loaddefs
button faces cus-face files text-properties overlay sha1 md5 base64
format env code-pages mule custom widget hashtable-print-readable
backquote make-network-process dbusbind dynamic-setting
system-font-setting font-render-setting move-toolbar gtk x-toolkit x
multi-tty emacs)

-- 
http://rrt.sc3d.org/





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

end of thread, other threads:[~2012-04-12 19:48 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-03 16:41 bug#9429: 24.0.50; Extended count-words Reuben Thomas
2011-09-07  1:51 ` Stefan Monnier
2011-09-07 11:20   ` Reuben Thomas
2011-09-10  3:03     ` Stefan Monnier
2011-09-10  3:18       ` Lars Magne Ingebrigtsen
2011-09-10  4:01         ` Stefan Monnier
2011-09-10  7:59       ` Reuben Thomas
2011-09-11 22:55       ` Reuben Thomas
2011-09-12  2:40         ` Stefan Monnier
2011-09-14 18:55       ` Juri Linkov
2011-10-07 20:20         ` Glenn Morris
2011-10-08 19:29           ` Juri Linkov
2012-04-12 19:48       ` Lars Magne Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.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).