unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* buffer-narrowed-p
@ 2010-08-14 12:33 Andreas Röhler
  2010-08-14 12:39 ` buffer-narrowed-p Lennart Borgman
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Röhler @ 2010-08-14 12:33 UTC (permalink / raw)
  To: help-gnu-emacs



Hi,

a couple of functions should behave different if buffer
is narrowed, i.e. taking narrowing already as
users decision to work on it, dismissing check for region
then.

As its used repeatedly, here an essay to solve it one
for all:

(defun buffer-narrowed-p ()
   (interactive)
   "Returns t, if buffer is narrowed. "
   (save-restriction
     (lexical-let ((beg (point-min))
                   (end (point-max))
                   erg)
       (widen)
       (setq erg (not (and (eq beg (point-min)) (eq end (point-max)))))
       (when (interactive-p)
         (if erg (message "Buffer is narrowed to: %d %d" beg end)
           (message "Buffer not narrowed: %s" "nil")))
       erg)))

Comments welcome :-)

Andreas

--
https://code.launchpad.net/~a-roehler/python-mode
https://code.launchpad.net/s-x-emacs-werkstatt/



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

* Re: buffer-narrowed-p
  2010-08-14 12:33 buffer-narrowed-p Andreas Röhler
@ 2010-08-14 12:39 ` Lennart Borgman
  2010-08-14 13:09   ` buffer-narrowed-p Andreas Röhler
  0 siblings, 1 reply; 3+ messages in thread
From: Lennart Borgman @ 2010-08-14 12:39 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: help-gnu-emacs

On Sat, Aug 14, 2010 at 2:33 PM, Andreas Röhler
<andreas.roehler@easy-emacs.de> wrote:
>
>
> Hi,
>
> a couple of functions should behave different if buffer
> is narrowed, i.e. taking narrowing already as
> users decision to work on it, dismissing check for region
> then.
>
> As its used repeatedly, here an essay to solve it one
> for all:
>
> (defun buffer-narrowed-p ()
>  (interactive)
>  "Returns t, if buffer is narrowed. "
>  (save-restriction
>    (lexical-let ((beg (point-min))
>                  (end (point-max))
>                  erg)
>      (widen)
>      (setq erg (not (and (eq beg (point-min)) (eq end (point-max)))))
>      (when (interactive-p)
>        (if erg (message "Buffer is narrowed to: %d %d" beg end)
>          (message "Buffer not narrowed: %s" "nil")))
>      erg)))
>
> Comments welcome :-)


I have this (which I think I stole from a comment by Stefan) in
ourcomments-util.el in nXhtml:

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



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

* Re: buffer-narrowed-p
  2010-08-14 12:39 ` buffer-narrowed-p Lennart Borgman
@ 2010-08-14 13:09   ` Andreas Röhler
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Röhler @ 2010-08-14 13:09 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: help-gnu-emacs

Am 14.08.2010 14:39, schrieb Lennart Borgman:
> On Sat, Aug 14, 2010 at 2:33 PM, Andreas Röhler
> <andreas.roehler@easy-emacs.de>  wrote:
>>
>>
>> Hi,
>>
>> a couple of functions should behave different if buffer
>> is narrowed, i.e. taking narrowing already as
>> users decision to work on it, dismissing check for region
>> then.
>>
>> As its used repeatedly, here an essay to solve it one
>> for all:
>>
>> (defun buffer-narrowed-p ()
>>   (interactive)
>>   "Returns t, if buffer is narrowed. "
>>   (save-restriction
>>     (lexical-let ((beg (point-min))
>>                   (end (point-max))
>>                   erg)
>>       (widen)
>>       (setq erg (not (and (eq beg (point-min)) (eq end (point-max)))))
>>       (when (interactive-p)
>>         (if erg (message "Buffer is narrowed to: %d %d" beg end)
>>           (message "Buffer not narrowed: %s" "nil")))
>>       erg)))
>>
>> Comments welcome :-)
>
>
> I have this (which I think I stole from a comment by Stefan) in
> ourcomments-util.el in nXhtml:
>
> ;;;###autoload
> (defun buffer-narrowed-p ()
>    "Return non-nil if the current buffer is narrowed."
>    (/= (buffer-size)
>        (- (point-max)
>           (point-min))))
>

Should be faster, thanks!




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

end of thread, other threads:[~2010-08-14 13:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-08-14 12:33 buffer-narrowed-p Andreas Röhler
2010-08-14 12:39 ` buffer-narrowed-p Lennart Borgman
2010-08-14 13:09   ` buffer-narrowed-p Andreas Röhler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).