all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#7151: `set-marker' narrowing and proposed feature `buffer-narrowed-p'
@ 2010-10-02 18:12 MON KEY
  2012-09-07  9:00 ` Chong Yidong
  0 siblings, 1 reply; 2+ messages in thread
From: MON KEY @ 2010-10-02 18:12 UTC (permalink / raw)
  To: 7151

`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\





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

* bug#7151: `set-marker' narrowing and proposed feature `buffer-narrowed-p'
  2010-10-02 18:12 bug#7151: `set-marker' narrowing and proposed feature `buffer-narrowed-p' MON KEY
@ 2012-09-07  9:00 ` Chong Yidong
  0 siblings, 0 replies; 2+ messages in thread
From: Chong Yidong @ 2012-09-07  9:00 UTC (permalink / raw)
  To: MON KEY; +Cc: 7151

MON KEY <monkey@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.





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

end of thread, other threads:[~2012-09-07  9:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-10-02 18:12 bug#7151: `set-marker' narrowing and proposed feature `buffer-narrowed-p' MON KEY
2012-09-07  9:00 ` Chong Yidong

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.