GNU bug report logs - #7151
`set-marker' narrowing and proposed feature `buffer-narrowed-p'

Previous Next

Package: emacs;

Reported by: MON KEY <monkey <at> sandpframing.com>

Date: Sat, 2 Oct 2010 18:10:03 UTC

Severity: wishlist

Done: Chong Yidong <cyd <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 7151 in the body.
You can then email your comments to 7151 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to owner <at> debbugs.gnu.org, bug-gnu-emacs <at> gnu.org:
bug#7151; Package emacs. (Sat, 02 Oct 2010 18:10:03 GMT) Full text and rfc822 format available.

Acknowledgement sent to MON KEY <monkey <at> sandpframing.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Sat, 02 Oct 2010 18:10:03 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: MON KEY <monkey <at> sandpframing.com>
To: bug-gnu-emacs <at> gnu.org
Subject: `set-marker' narrowing and proposed feature `buffer-narrowed-p'
Date: Sat, 2 Oct 2010 14:12:03 -0400
`set-marker' can not be set beyond value of `point-max'
This is documented here:

,---- (info "(elisp)Moving Marker Positions")
|
| If POSITION is less than 1, `set-marker' moves MARKER to the
| beginning of the buffer.  If POSITION is greater than the size of
| the buffer, `set-marker' moves marker to the end of the buffer.
| If POSITION is `nil' or a marker that points nowhere, then MARKER
| is set to point nowhere.
|
`----

Some mention in the above section should be made of `buffer-size' so users can
now how to check if the buffer is narrowed.

Likewise, docstrings of `>', `<', `<=', `>=', all indicate their arguments:

,----
|
| Both must be numbers or markers.
|
`----

There is a discrepancy here in that the following signals an error:

(let ((mk-mrk (make-marker)))
  (set-marker mk-mrk nil)
  (> mk-mrk (point-max)))
;=> (error "Marker does not point anywhere")

Moreover, as the docstring of `set-marker' doesn't indicate that its range is
bounded by the current values of `point-max' and `point-min' simple arithmetic
checks for a markers value against some arbitrary buffer position can lead to
confusing return values:

(let ((mk-mrk (make-marker)))
  (progn (narrow-to-region (+ (point-min) 10) (- (point-max) 10))
         (set-marker mk-mrk (1+ (point-max)))
         (widen))
  `(,(= mk-mrk (point-max))
    ,(>= mk-mrk (point-max))
    ,(< mk-mrk (point-max))
    ,(marker-position mk-mrk)
    ,(point-max)))
;=> (nil nil t <PSN> <PSN>)


(let ((mk-mrk (make-marker)))
  (set-marker mk-mrk (1+ (point-max)))
  (> mk-mrk (point-max)))
;=> nil

(let ((mk-mrk (make-marker)))
  (set-marker mk-mrk 12000)
  (> mk-mrk (point-max)))
;=> nil

(let ((mk-mrk (make-marker)))
  (set-marker mk-mrk 12000)
  (= (marker-position mk-mrk) 12000))
;=> nil

(let ((mk-mrk (make-marker)))
  (set-marker mk-mrk (1+ (point-max)))
  (> mk-mrk (1- (point-max))))
;=> t

I think some mention of these anomalies should be made in the respective docs in
addition to the scattered lisp service provided by the manual.

I would also like to propose addition of a new function `buffer-narrowed-p'.
rgrep'ing buffer-narrowed-p  in "lisp/" did not return any results...

(defun buffer-narrowed-p (&optional buffer-or-name)
  "Test if buffer narrowing is in effect.
When optional arg BUFFER-OR-NAME is non-nil check for narrowing in that buffer
instead. Default is `current-buffer'.\n
:EXAMPLE\n\n\(prog2
    \(narrow-to-region \(line-beginning-position\) \(line-end-position\)\)
    \(buffer-narrowed-p \"*Help*\"\)
  \(widen\)\)\n"
  (let ((chk-bffr (if buffer-or-name
                      (or (get-buffer buffer-or-name)
                          (error  "Optional arg BUFFER-OR-NAME does
not find buffer: `%S'"))
                    (current-buffer))))
    (with-current-buffer chk-bffr
      (or (> (point-min) 1)
          (/= (buffer-size) (1- (point-max)))
          (/= (- (point-max) (point-min)) (buffer-size))))))

--
/s_P\




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#7151; Package emacs. (Fri, 07 Sep 2012 09:01:01 GMT) Full text and rfc822 format available.

Message #8 received at 7151 <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> gnu.org>
To: MON KEY <monkey <at> sandpframing.com>
Cc: 7151 <at> debbugs.gnu.org
Subject: Re: bug#7151: `set-marker' narrowing and proposed feature
	`buffer-narrowed-p'
Date: Fri, 07 Sep 2012 17:00:20 +0800
MON KEY <monkey <at> sandpframing.com> writes:

> Some mention in the above section should be made of `buffer-size' so users can
> now how to check if the buffer is narrowed.

Done.  Thanks for the suggestion.

> Likewise, docstrings of `>', `<', `<=', `>=', all indicate their
> arguments:
> | Both must be numbers or markers.
> There is a discrepancy here in that the following signals an error:
>
> (let ((mk-mrk (make-marker)))
>   (set-marker mk-mrk nil)
>   (> mk-mrk (point-max)))
> ;=> (error "Marker does not point anywhere")
>
> I think some mention of these anomalies should be made in the
> respective docs in addition to the scattered lisp service provided by
> the manual.

I don't think this is worth documenting; we don't document every single
error condition, and this one is easy to figure out.

> I would also like to propose addition of a new function
> `buffer-narrowed-p'.

Thanks for the suggestion.  I committed a much simpler version.




bug closed, send any further explanations to 7151 <at> debbugs.gnu.org and MON KEY <monkey <at> sandpframing.com> Request was from Chong Yidong <cyd <at> gnu.org> to control <at> debbugs.gnu.org. (Fri, 07 Sep 2012 09:02:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 05 Oct 2012 11:24:04 GMT) Full text and rfc822 format available.

This bug report was last modified 12 years and 317 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.