all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* What variable says that the buffer is in narrowed state?
@ 2007-10-13 13:30 Bastien
  0 siblings, 0 replies; 5+ messages in thread
From: Bastien @ 2007-10-13 13:30 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I expected to find some `buffer-narrowed-p' variable.  Is there
something like this?  The mode-line is able to display this bit 
of information, so I guess it might somehow be accessible.

Thanks,

-- 
Bastien

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

* Re: What variable says that the buffer is in narrowed state?
       [not found] <mailman.2016.1192278715.18990.help-gnu-emacs@gnu.org>
@ 2007-10-13 13:45 ` Sven Joachim
  2007-10-13 15:57   ` Bastien
  2007-10-14 19:57   ` Stefan Monnier
  0 siblings, 2 replies; 5+ messages in thread
From: Sven Joachim @ 2007-10-13 13:45 UTC (permalink / raw)
  To: help-gnu-emacs

Bastien <bzg@altern.org> writes:

> I expected to find some `buffer-narrowed-p' variable.  Is there
> something like this?  The mode-line is able to display this bit 
> of information, so I guess it might somehow be accessible.

If there were such a thing, it should probably be a function rather
than a variable.  Doesn't seem there is one, so I wrote it for you:

(defun buffer-narrowed-p ()
  "Return t if buffer is narrowed, nil otherwise."
  (or (> (point-min) 1)
      (< (point-max) (buffer-size))))

The mode-line display is coded in src/xdisp.c, look for "Narrow"
there.

Cheers,
       Sven

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

* Re: What variable says that the buffer is in narrowed state?
  2007-10-13 13:45 ` Sven Joachim
@ 2007-10-13 15:57   ` Bastien
  2007-10-14 19:57   ` Stefan Monnier
  1 sibling, 0 replies; 5+ messages in thread
From: Bastien @ 2007-10-13 15:57 UTC (permalink / raw)
  To: help-gnu-emacs

Sven Joachim <svenjoac@gmx.de> writes:

> (defun buffer-narrowed-p ()
>   "Return t if buffer is narrowed, nil otherwise."
>   (or (> (point-min) 1)
>       (< (point-max) (buffer-size))))

Great!  Thanks very much.

> The mode-line display is coded in src/xdisp.c, look for "Narrow"
> there.

Seen that -- that's why I expected some internal variable/function would
tell me about the buffer narrow-status.

-- 
Bastien

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

* Re: What variable says that the buffer is in narrowed state?
  2007-10-13 13:45 ` Sven Joachim
  2007-10-13 15:57   ` Bastien
@ 2007-10-14 19:57   ` Stefan Monnier
  2007-10-15 17:51     ` Sven Joachim
  1 sibling, 1 reply; 5+ messages in thread
From: Stefan Monnier @ 2007-10-14 19:57 UTC (permalink / raw)
  To: help-gnu-emacs

>> I expected to find some `buffer-narrowed-p' variable.  Is there
>> something like this?  The mode-line is able to display this bit 
>> of information, so I guess it might somehow be accessible.

> If there were such a thing, it should probably be a function rather
> than a variable.  Doesn't seem there is one, so I wrote it for you:

> (defun buffer-narrowed-p ()
>   "Return t if buffer is narrowed, nil otherwise."
>   (or (> (point-min) 1)
>       (< (point-max) (buffer-size))))

Sometimes you can't avoid assuming that buffer positions start at 1, but
that's rare.  Even in the above case, for example, you can simply check:

   (defun buffer-narrowed-p ()
     (> (buffer-size) (- (point-max) (point-min))))


-- Stefan

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

* Re: What variable says that the buffer is in narrowed state?
  2007-10-14 19:57   ` Stefan Monnier
@ 2007-10-15 17:51     ` Sven Joachim
  0 siblings, 0 replies; 5+ messages in thread
From: Sven Joachim @ 2007-10-15 17:51 UTC (permalink / raw)
  To: help-gnu-emacs

Stefan Monnier <monnier@iro.umontreal.ca> writes:

>> (defun buffer-narrowed-p ()
>>   "Return t if buffer is narrowed, nil otherwise."
>>   (or (> (point-min) 1)
>>       (< (point-max) (buffer-size))))
>
> Sometimes you can't avoid assuming that buffer positions start at 1, but
> that's rare.

What's worse is that I incorrectly assumed that buffer positions end
at (buffer-size), while they actually end at (1+ (buffer-size)). :-/

>  Even in the above case, for example, you can simply check:
>
>    (defun buffer-narrowed-p ()
>      (> (buffer-size) (- (point-max) (point-min))))

Thanks.  I'm still learning, maybe in a few years I'll be able to post
a snippet here that actually works. :-(

Slightly embarrassed,
Sven

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

end of thread, other threads:[~2007-10-15 17:51 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-13 13:30 What variable says that the buffer is in narrowed state? Bastien
     [not found] <mailman.2016.1192278715.18990.help-gnu-emacs@gnu.org>
2007-10-13 13:45 ` Sven Joachim
2007-10-13 15:57   ` Bastien
2007-10-14 19:57   ` Stefan Monnier
2007-10-15 17:51     ` Sven Joachim

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.