aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/simple.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/simple.el')
-rw-r--r--lisp/simple.el31
1 files changed, 20 insertions, 11 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 0877f396faa..f644044a430 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -966,16 +966,22 @@ rather than line counts."
966 (re-search-forward "[\n\C-m]" nil 'end (1- line)) 966 (re-search-forward "[\n\C-m]" nil 'end (1- line))
967 (forward-line (1- line))))) 967 (forward-line (1- line)))))
968 968
969(defun count-words-region (start end) 969(defun count-words-region (start end &optional arg)
970 "Count the number of words in the region. 970 "Count the number of words in the region.
971If called interactively, print a message reporting the number of 971If called interactively, print a message reporting the number of
972lines, words, and chars in the region. 972lines, words, and characters in the region (whether or not the
973region is active); with prefix ARG, report for the entire buffer
974rather than the region.
975
973If called from Lisp, return the number of words between positions 976If called from Lisp, return the number of words between positions
974START and END." 977START and END."
975 (interactive "r") 978 (interactive "r\nP")
976 (if (called-interactively-p 'any) 979 (cond ((not (called-interactively-p 'any))
977 (count-words--message "Region" start end) 980 (count-words start end))
978 (count-words start end))) 981 (arg
982 (count-words--buffer-message))
983 (t
984 (count-words--message "Region" start end))))
979 985
980(defun count-words (start end) 986(defun count-words (start end)
981 "Count words between START and END. 987 "Count words between START and END.
@@ -999,11 +1005,14 @@ END, without printing any message."
999 ((use-region-p) 1005 ((use-region-p)
1000 (call-interactively 'count-words-region)) 1006 (call-interactively 'count-words-region))
1001 (t 1007 (t
1002 (count-words--message 1008 (count-words--buffer-message))))
1003 (if (= (point-max) (1+ (buffer-size))) 1009
1004 "Buffer" 1010(defun count-words--buffer-message ()
1005 "Narrowed part of buffer") 1011 (count-words--message
1006 (point-min) (point-max))))) 1012 (if (= (point-max) (1+ (buffer-size)))
1013 "Buffer"
1014 "Narrowed part of buffer")
1015 (point-min) (point-max)))
1007 1016
1008(defun count-words--message (str start end) 1017(defun count-words--message (str start end)
1009 (let ((lines (count-lines start end)) 1018 (let ((lines (count-lines start end))