all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Karl Fogel <kfogel@red-bean.com>
Cc: emacs-devel@gnu.org
Subject: Re: Question about intended behavior of 'insert-for-yank-1'.
Date: Mon, 12 Sep 2016 19:59:31 +0300	[thread overview]
Message-ID: <83eg4p9hqk.fsf@gnu.org> (raw)
In-Reply-To: <874m5lr92d.fsf@red-bean.com> (message from Karl Fogel on Mon, 12 Sep 2016 00:17:14 -0500)

> From: Karl Fogel <kfogel@red-bean.com>
> Date: Mon, 12 Sep 2016 00:17:14 -0500
> 
> The doc string for 'insert-for-yank-1' says:
> 
>   [...]
>   If STRING has a non-nil ‘yank-handler’ property on its first
>   character, the normal insert behavior is altered.  The value of
>   the ‘yank-handler’ property must be a list of one to four
>   elements, of the form (FUNCTION PARAM NOEXCLUDE UNDO).
>   FUNCTION, if non-nil, should be a function of one argument, an
>    object to insert; it is called instead of ‘insert’.
>   PARAM, if present and non-nil, replaces STRING as the argument to
>    FUNCTION or ‘insert’; e.g. if FUNCTION is ‘yank-rectangle’, PARAM
>    may be a list of strings to insert as a rectangle.
>   [...]
> 
> This implies that when the `yank-handler' property is present, then when PARAM is nil, the string passed to FUNCTION should be STRING.  That is, the entire length of STRING, even if the `yank-handler' property is set only on STRING's first character.
> 
> However, the way it actually behaves is that if you set the property on (say) exactly the first character of STRING, then, assuming you rely on the implicit parameter passing, what gets passed to FUNCTION is a string consisting of just the first character of STRING :-).  Later, when you yank with C-y, that's all you'll get.

But for insert-for-yank-1, STRING is its argument, and it's that
argument that gets passed to FUNCTION.  So I don't see how the doc
string of this subroutine is inaccurate or misleading.  The part that
tricked you is in insert-for-yank:

  (defun insert-for-yank (string)
    "Call `insert-for-yank-1' repetitively for each `yank-handler' segment.

  See `insert-for-yank-1' for more details."
    (let (to)
      (while (setq to (next-single-property-change 0 'yank-handler string))
	(insert-for-yank-1 (substring string 0 to)) <<<<<<<<<<<
	(setq string (substring string to))))
    (insert-for-yank-1 string))

It passes to insert-for-yank-1 the substring of its argument STRING
that was actually "covered" by the text property.  See also the while
loop.

> Should I update the documentation to clarify?  Or should the behavior change instead?

I see no problem with how the functions behave.  As for documentation,
can you show the change you had in mind?

> (By the way, I have not tested what happens if you set that property on multiple disjoint extents of STRING.  Does FUNCTION get passed a newly-created concatenation of all the stretches of string that had the property?  I have no idea.  If the recommendation here is just to fix the documentation, though, then I'll do that testing.)

Isn't that clear from the loop in insert-for-yank?  Or am I missing
something?

Thanks.



  reply	other threads:[~2016-09-12 16:59 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-12  5:17 Question about intended behavior of 'insert-for-yank-1' Karl Fogel
2016-09-12 16:59 ` Eli Zaretskii [this message]
2016-09-12 17:15   ` Karl Fogel
2016-09-12 18:32     ` Eli Zaretskii
2016-09-12 22:36       ` Karl Fogel
2016-09-12 22:54         ` Drew Adams
2016-09-12 23:08           ` Karl Fogel
2016-10-03  0:53           ` Karl Fogel
2016-10-03  3:17             ` Noam Postavsky
2016-10-03  6:53               ` Eli Zaretskii
2016-10-03 19:21               ` Karl Fogel
2016-10-03  6:44             ` Eli Zaretskii
2016-10-03 19:17               ` Karl Fogel
2016-10-04  6:03                 ` Eli Zaretskii
2016-10-04 17:40                   ` Karl Fogel
2016-10-04 18:19                     ` Eli Zaretskii
2016-10-04 20:16                       ` Davis Herring
2016-10-04 21:04                       ` Karl Fogel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83eg4p9hqk.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=kfogel@red-bean.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.