Add a utility function buffer-narrowed-p, and use it.
authorChong Yidong <cyd@gnu.org>
Fri, 7 Sep 2012 08:58:31 +0000 (16:58 +0800)
committerChong Yidong <cyd@gnu.org>
Fri, 7 Sep 2012 08:58:31 +0000 (16:58 +0800)
* lisp/subr.el (buffer-narrowed-p): New function.

* lisp/ses.el (ses-widen):
* lisp/simple.el (count-words--buffer-message):
* lisp/net/browse-url.el (browse-url-of-buffer): Use it

* lisp/simple.el (count-words-region): Don't signal an error if there
is a non-nil prefix arg and the mark is not set.

* doc/lispref/positions.texi (Narrowing): Document buffer-narrowed-p.

doc/lispref/ChangeLog
doc/lispref/positions.texi
etc/NEWS
lisp/ChangeLog
lisp/emacs-lisp/cl-loaddefs.el
lisp/net/browse-url.el
lisp/ses.el
lisp/simple.el
lisp/subr.el

index bd21100..179f819 100644 (file)
@@ -1,5 +1,7 @@
 2012-09-07  Chong Yidong  <cyd@gnu.org>
 
+       * positions.texi (Narrowing): Document buffer-narrowed-p.
+
        * markers.texi (Moving Markers): Add xref to Point (Bug#7151).
 
        * syntax.texi (Low-Level Parsing): Add xref to Parser State
index a0c6531..c4576e6 100644 (file)
@@ -874,18 +874,18 @@ commands to a limited range of characters in a buffer.  The text that
 remains addressable is called the @dfn{accessible portion} of the
 buffer.
 
-  Narrowing is specified with two buffer positions which become the
-beginning and end of the accessible portion.  For most editing commands
-and most Emacs primitives, these positions replace the values of the
-beginning and end of the buffer.  While narrowing is in effect, no text
-outside the accessible portion is displayed, and point cannot move
-outside the accessible portion.
-
-  Values such as positions or line numbers, which usually count from the
-beginning of the buffer, do so despite narrowing, but the functions
-which use them refuse to operate on text that is inaccessible.
-
-  The commands for saving buffers are unaffected by narrowing; they save
+  Narrowing is specified with two buffer positions, which become the
+beginning and end of the accessible portion.  For most editing
+commands and primitives, these positions replace the values of the
+beginning and end of the buffer.  While narrowing is in effect, no
+text outside the accessible portion is displayed, and point cannot
+move outside the accessible portion.  Note that narrowing does not
+alter actual buffer positions (@pxref{Point}); it only determines
+which positions are considered the accessible portion of the buffer.
+Most functions refuse to operate on text that is outside the
+accessible portion.
+
+  Commands for saving buffers are unaffected by narrowing; they save
 the entire buffer regardless of any narrowing.
 
   If you need to display in a single buffer several very different
@@ -924,6 +924,11 @@ It is equivalent to the following expression:
 @end example
 @end deffn
 
+@defun buffer-narrowed-p
+This function returns non-@code{nil} if the buffer is narrowed, and
+@code{nil} otherwise.
+@end defun
+
 @defspec save-restriction body@dots{}
 This special form saves the current bounds of the accessible portion,
 evaluates the @var{body} forms, and finally restores the saved bounds,
index bc1c49f..b85d64f 100644 (file)
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -645,6 +645,9 @@ The interpretation of the DECLS is determined by `defun-declarations-alist'.
 
 ** New error type and new function `user-error'.  Doesn't trigger the debugger.
 
++++
+** New utility function `buffer-narrowed-p'.
+
 ** Window changes
 
 *** The functions get-lru-window, get-mru-window and get-largest-window
index 33e641b..7aae8fd 100644 (file)
@@ -1,6 +1,13 @@
 2012-09-07  Chong Yidong  <cyd@gnu.org>
 
-       * simple.el (count-words--buffer-message): Fix narrowing check.
+       * subr.el (buffer-narrowed-p): New function.
+
+       * ses.el (ses-widen):
+       * simple.el (count-words--buffer-message):
+       * net/browse-url.el (browse-url-of-buffer): Use it
+
+       * simple.el (count-words-region): Don't signal an error if there
+       is a non-nil prefix arg and the mark is not set.
 
        * help.el (describe-key-briefly): Allow the message to be seen
        when invoked from the minibuffer (Bug#7014).
index 7d70d22..a59beae 100644 (file)
@@ -260,7 +260,7 @@ Remove from SYMBOL's plist the property PROPNAME and its value.
 ;;;;;;  cl-typecase cl-ecase cl-case cl-load-time-value cl-eval-when
 ;;;;;;  cl-destructuring-bind cl-function cl-defmacro cl-defun cl-gentemp
 ;;;;;;  cl-gensym cl--compiler-macro-cXXr cl--compiler-macro-list*)
-;;;;;;  "cl-macs" "cl-macs.el" "e09b4be5072a8b52d40af6e073876e76")
+;;;;;;  "cl-macs" "cl-macs.el" "9f9bae5b8ccaf325bd59ba9be2b27c44")
 ;;; Generated autoloads from cl-macs.el
 
 (autoload 'cl--compiler-macro-list* "cl-macs" "\
index 20d7121..d1d33bf 100644 (file)
@@ -743,7 +743,7 @@ narrowed."
     (and buffer (set-buffer buffer))
     (let ((file-name
           ;; Ignore real name if restricted
-          (and (= (- (point-max) (point-min)) (buffer-size))
+          (and (not (buffer-narrowed-p))
                (or buffer-file-name
                    (and (boundp 'dired-directory) dired-directory)))))
       (or file-name
index 8add16a..7cdac74 100644 (file)
@@ -1270,11 +1270,9 @@ when the width of cell (ROW,COL) has changed."
 ;; The data area
 ;;----------------------------------------------------------------------------
 
-(defun ses-narrowed-p () (/= (- (point-max) (point-min)) (buffer-size)))
-
 (defun ses-widen ()
   "Turn off narrowing, to be reenabled at end of command loop."
-  (if (ses-narrowed-p)
+  (if (buffer-narrowed-p)
       (setq ses--deferred-narrow t))
   (widen))
 
index ca73ba1..d87ae3c 100644 (file)
@@ -974,7 +974,9 @@ rather than the region.
 
 If called from Lisp, return the number of words between positions
 START and END."
-  (interactive "r\nP")
+  (interactive (if current-prefix-arg
+                  (list nil nil current-prefix-arg)
+                (list (region-beginning) (region-end) nil)))
   (cond ((not (called-interactively-p 'any))
         (count-words start end))
        (arg
@@ -1008,9 +1010,7 @@ END, without printing any message."
 
 (defun count-words--buffer-message ()
   (count-words--message
-   (if (= (- (point-max) (point-min)) (buffer-size))
-       "Buffer"
-     "Narrowed part of buffer")
+   (if (buffer-narrowed-p) "Narrowed part of buffer" "Buffer")
    (point-min) (point-max)))
 
 (defun count-words--message (str start end)
index 74afd59..621622e 100644 (file)
@@ -2647,6 +2647,10 @@ directory if it does not exist."
 \f
 ;;;; Misc. useful functions.
 
+(defsubst buffer-narrowed-p ()
+  "Return non-nil if the current buffer is narrowed."
+  (/= (- (point-max) (point-min)) (buffer-size)))
+
 (defun find-tag-default ()
   "Determine default tag to search for, based on text at point.
 If there is no plausible default, return nil."