From e5c2edf79ba2b75a3572839fcb9de612f93ab630 Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Fri, 7 Sep 2012 16:58:31 +0800 Subject: [PATCH] Add a utility function buffer-narrowed-p, and use it. * 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 | 2 ++ doc/lispref/positions.texi | 29 +++++++++++++++++------------ etc/NEWS | 3 +++ lisp/ChangeLog | 9 ++++++++- lisp/emacs-lisp/cl-loaddefs.el | 2 +- lisp/net/browse-url.el | 2 +- lisp/ses.el | 4 +--- lisp/simple.el | 8 ++++---- lisp/subr.el | 4 ++++ 9 files changed, 41 insertions(+), 22 deletions(-) diff --git a/doc/lispref/ChangeLog b/doc/lispref/ChangeLog index bd21100dd4..179f81990a 100644 --- a/doc/lispref/ChangeLog +++ b/doc/lispref/ChangeLog @@ -1,5 +1,7 @@ 2012-09-07 Chong Yidong + * 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 diff --git a/doc/lispref/positions.texi b/doc/lispref/positions.texi index a0c6531985..c4576e6456 100644 --- a/doc/lispref/positions.texi +++ b/doc/lispref/positions.texi @@ -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, diff --git a/etc/NEWS b/etc/NEWS index bc1c49fe94..b85d64f83a 100644 --- 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 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 33e641b5fc..7aae8fd785 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,6 +1,13 @@ 2012-09-07 Chong Yidong - * 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). diff --git a/lisp/emacs-lisp/cl-loaddefs.el b/lisp/emacs-lisp/cl-loaddefs.el index 7d70d22c9c..a59beaeb7a 100644 --- a/lisp/emacs-lisp/cl-loaddefs.el +++ b/lisp/emacs-lisp/cl-loaddefs.el @@ -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" "\ diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el index 20d7121592..d1d33bfe56 100644 --- a/lisp/net/browse-url.el +++ b/lisp/net/browse-url.el @@ -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 diff --git a/lisp/ses.el b/lisp/ses.el index 8add16a699..7cdac74e31 100644 --- a/lisp/ses.el +++ b/lisp/ses.el @@ -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)) diff --git a/lisp/simple.el b/lisp/simple.el index ca73ba1b03..d87ae3c5c1 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -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) diff --git a/lisp/subr.el b/lisp/subr.el index 74afd59f8d..621622e70e 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -2647,6 +2647,10 @@ directory if it does not exist." ;;;; 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." -- 2.20.1