GNU bug report logs - #35718
26.2; Functions in yank-handled-properties ALWAYS get called

Previous Next

Package: emacs;

Reported by: Xu Chunyang <mail <at> xuchunyang.me>

Date: Mon, 13 May 2019 17:18:02 UTC

Severity: normal

Found in version 26.2

Done: Lars Ingebrigtsen <larsi <at> gnus.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 35718 in the body.
You can then email your comments to 35718 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 bug-gnu-emacs <at> gnu.org:
bug#35718; Package emacs. (Mon, 13 May 2019 17:18:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Xu Chunyang <mail <at> xuchunyang.me>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 13 May 2019 17:18:02 GMT) Full text and rfc822 format available.

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

From: Xu Chunyang <mail <at> xuchunyang.me>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.2; Functions in yank-handled-properties ALWAYS get called
Date: Tue, 14 May 2019 01:02:11 +0800
Hi,

I want to change how image is pasted (e.g., save the image to disk and
insert a markdown image link). When I play with yank-handled-properties:

    (add-to-list 'yank-handled-properties '(image . foo))
    
    (defun foo (image beg end)
      (message "=> %S %S %S" image beg end))

However, the function foo is always called even there is no image at
all. This is unexpected since the function should only be called when
the property 'image is found according to the documentation:

    When the `yank' command inserts text into the buffer, it scans the
    inserted text for stretches of text that have `eq' values of the text
    property PROP; for each such stretch of text, FUN is called with three
    arguments...

The function is called inside remove-yank-excluded-properties, however
FUN is always called no matter what PROP is:

    (while (< run-start end)
      (let ((value (get-text-property run-start prop))
            (run-end (next-single-property-change
                      run-start prop nil end)))
        (funcall fun value run-start run-end)
        (setq run-start run-end)))


--
In GNU Emacs 26.2 (build 1, x86_64-apple-darwin18.5.0, Carbon Version 158 AppKit 1671.4)
 of 2019-04-20 built on Chunyangs-MacBook-Air.local
Repository revision: d21490f428a6baf568ad0669425b4a7b39a6bd73
Windowing system distributor 'Apple Inc.', version 10.14.4




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

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

From: Eli Zaretskii <eliz <at> gnu.org>
To: Xu Chunyang <mail <at> xuchunyang.me>
Cc: 35718 <at> debbugs.gnu.org
Subject: Re: bug#35718: 26.2;
 Functions in yank-handled-properties ALWAYS get called
Date: Fri, 07 Jun 2019 12:27:06 +0300
> From: Xu Chunyang <mail <at> xuchunyang.me>
> Date: Tue, 14 May 2019 01:02:11 +0800
> 
> I want to change how image is pasted (e.g., save the image to disk and
> insert a markdown image link). When I play with yank-handled-properties:
> 
>     (add-to-list 'yank-handled-properties '(image . foo))
>     
>     (defun foo (image beg end)
>       (message "=> %S %S %S" image beg end))
> 
> However, the function foo is always called even there is no image at
> all. This is unexpected since the function should only be called when
> the property 'image is found according to the documentation:
> 
>     When the `yank' command inserts text into the buffer, it scans the
>     inserted text for stretches of text that have `eq' values of the text
>     property PROP; for each such stretch of text, FUN is called with three
>     arguments...
> 
> The function is called inside remove-yank-excluded-properties, however
> FUN is always called no matter what PROP is:
> 
>     (while (< run-start end)
>       (let ((value (get-text-property run-start prop))
>             (run-end (next-single-property-change
>                       run-start prop nil end)))
>         (funcall fun value run-start run-end)
>         (setq run-start run-end)))

The above code actually calls the handler function whenever PROP's
value _changes_, not just where PROP is non-nil.  Not sure if this is
a bug or a feature; opinions welcome.




Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35718; Package emacs. (Fri, 07 Jun 2019 13:05:02 GMT) Full text and rfc822 format available.

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

From: Noam Postavsky <npostavs <at> gmail.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Xu Chunyang <mail <at> xuchunyang.me>, 35718 <at> debbugs.gnu.org
Subject: Re: bug#35718: 26.2;
 Functions in yank-handled-properties ALWAYS get called
Date: Fri, 07 Jun 2019 09:03:59 -0400
>> However, the function foo is always called even there is no image at
>> all. This is unexpected since the function should only be called when
>> the property 'image is found according to the documentation:
>>
>>     When the `yank' command inserts text into the buffer, it scans the
>>     inserted text for stretches of text that have `eq' values of the text
>>     property PROP; for each such stretch of text, FUN is called with three
>>     arguments...
>> 
>> The function is called inside remove-yank-excluded-properties, however
>> FUN is always called no matter what PROP is:
>> 
>>     (while (< run-start end)
>>       (let ((value (get-text-property run-start prop))
>>             (run-end (next-single-property-change
>>                       run-start prop nil end)))
>>         (funcall fun value run-start run-end)
>>         (setq run-start run-end)))
>
> The above code actually calls the handler function whenever PROP's
> value _changes_, not just where PROP is non-nil.  Not sure if this is
> a bug or a feature; opinions welcome.

I think the question is more about whether we distinguish between an
absent property, and a property whose value is nil
(remove-yank-excluded-properties currently does not, which is what I
think this bug report is complaining about).  The manual doesn't say
either way, but text-property-any (and other property checking
functions) seem to treat them the same as well:

(text-property-any 0 2 'xxx nil (propertize "foo" 'xxx nil)) ;=> 0
(text-property-any 0 2 'xxx nil (propertize "foo" 'xxx t)) ;=> nil
(text-property-any 0 2 'xxx nil "foo") ;=> 0





Information forwarded to bug-gnu-emacs <at> gnu.org:
bug#35718; Package emacs. (Tue, 22 Jun 2021 14:26:01 GMT) Full text and rfc822 format available.

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

From: Lars Ingebrigtsen <larsi <at> gnus.org>
To: Noam Postavsky <npostavs <at> gmail.com>
Cc: Eli Zaretskii <eliz <at> gnu.org>, Xu Chunyang <mail <at> xuchunyang.me>,
 35718 <at> debbugs.gnu.org
Subject: Re: bug#35718: 26.2; Functions in yank-handled-properties ALWAYS
 get called
Date: Tue, 22 Jun 2021 16:25:03 +0200
Noam Postavsky <npostavs <at> gmail.com> writes:

> I think the question is more about whether we distinguish between an
> absent property, and a property whose value is nil
> (remove-yank-excluded-properties currently does not, which is what I
> think this bug report is complaining about).  The manual doesn't say
> either way, but text-property-any (and other property checking
> functions) seem to treat them the same as well:
>
> (text-property-any 0 2 'xxx nil (propertize "foo" 'xxx nil)) ;=> 0
> (text-property-any 0 2 'xxx nil (propertize "foo" 'xxx t)) ;=> nil
> (text-property-any 0 2 'xxx nil "foo") ;=> 0

I think that we don't (in general) care about the difference of a nil
property and a missing property, so if I understand the snippet
correctly, this is basically working as intended, so I'm closing this
bug report.

If I misunderstood, please respond to the debbugs address and we'll
reopen.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no




bug closed, send any further explanations to 35718 <at> debbugs.gnu.org and Xu Chunyang <mail <at> xuchunyang.me> Request was from Lars Ingebrigtsen <larsi <at> gnus.org> to control <at> debbugs.gnu.org. (Tue, 22 Jun 2021 14:26: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. (Wed, 21 Jul 2021 11:24:06 GMT) Full text and rfc822 format available.

This bug report was last modified 2 years and 279 days ago.

Previous Next


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