all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* narrowedp?
@ 2009-10-01 10:17 Alan Mackenzie
  2009-10-01 10:38 ` narrowedp? David Kastrup
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Mackenzie @ 2009-10-01 10:17 UTC (permalink / raw)
  To: emacs-devel

Hi, Emacs!

There doesn't seem to be a function `narrowedp'.  This is, perhaps, an
unfortunate lack.

It's easy enough to test the lower bound:

    (eq (point-min) 1)

, but the upper bound is a touch tedious:

    (save-restriction
      (let ((reg-end (point-max)))
        (widen)
	(eq reg-end (point-max))))

.  Actually, I really just want to test the lower bound (to know whether
to need to test for point-min being inside a literal).  But testing
point-min against "1" seems a bit unemacsy and unfutureproof.  When
Emacs gets good multi-major-mode facilities, the "beginning of buffer"
will not be 1, rather the beginning of the particular buffer part.  Or
something like that.

-- 
Alan Mackenzie (Nuremberg, Germany).




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

* Re: narrowedp?
  2009-10-01 10:17 narrowedp? Alan Mackenzie
@ 2009-10-01 10:38 ` David Kastrup
  2009-10-01 11:06   ` narrowedp? Lennart Borgman
  0 siblings, 1 reply; 3+ messages in thread
From: David Kastrup @ 2009-10-01 10:38 UTC (permalink / raw)
  To: emacs-devel

Alan Mackenzie <acm@muc.de> writes:

> Hi, Emacs!
>
> There doesn't seem to be a function `narrowedp'.  This is, perhaps, an
> unfortunate lack.
>
> It's easy enough to test the lower bound:
>
>     (eq (point-min) 1)
>
> , but the upper bound is a touch tedious:
>
>     (save-restriction
>       (let ((reg-end (point-max)))
>         (widen)
> 	(eq reg-end (point-max))))

Try (> (point-max) (buffer-size)) for that.

Checking both can be done with
(= (- (point-max) (point-min)) (buffer-size))

-- 
David Kastrup





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

* Re: narrowedp?
  2009-10-01 10:38 ` narrowedp? David Kastrup
@ 2009-10-01 11:06   ` Lennart Borgman
  0 siblings, 0 replies; 3+ messages in thread
From: Lennart Borgman @ 2009-10-01 11:06 UTC (permalink / raw)
  To: David Kastrup; +Cc: emacs-devel

On Thu, Oct 1, 2009 at 12:38 PM, David Kastrup <dak@gnu.org> wrote:
>
> Checking both can be done with
> (= (- (point-max) (point-min)) (buffer-size))

I use this function

(defun buffer-narrowed-p ()
  "Return non-nil if the current buffer is narrowed."
  (/= (buffer-size)
      (- (point-max)
         (point-min))))

Maybe it would be good if this was included in Emacs. However please
observe also that `save-restriction' and `widen' are fast operations.




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

end of thread, other threads:[~2009-10-01 11:06 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-01 10:17 narrowedp? Alan Mackenzie
2009-10-01 10:38 ` narrowedp? David Kastrup
2009-10-01 11:06   ` narrowedp? Lennart Borgman

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.