unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#35718: 26.2; Functions in yank-handled-properties ALWAYS get called
@ 2019-05-13 17:02 Xu Chunyang
  2019-06-07  9:27 ` Eli Zaretskii
  0 siblings, 1 reply; 4+ messages in thread
From: Xu Chunyang @ 2019-05-13 17:02 UTC (permalink / raw)
  To: 35718

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





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

* bug#35718: 26.2; Functions in yank-handled-properties ALWAYS get called
  2019-05-13 17:02 bug#35718: 26.2; Functions in yank-handled-properties ALWAYS get called Xu Chunyang
@ 2019-06-07  9:27 ` Eli Zaretskii
  2019-06-07 13:03   ` Noam Postavsky
  0 siblings, 1 reply; 4+ messages in thread
From: Eli Zaretskii @ 2019-06-07  9:27 UTC (permalink / raw)
  To: Xu Chunyang; +Cc: 35718

> From: Xu Chunyang <mail@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.





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

* bug#35718: 26.2; Functions in yank-handled-properties ALWAYS get called
  2019-06-07  9:27 ` Eli Zaretskii
@ 2019-06-07 13:03   ` Noam Postavsky
  2021-06-22 14:25     ` Lars Ingebrigtsen
  0 siblings, 1 reply; 4+ messages in thread
From: Noam Postavsky @ 2019-06-07 13:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Xu Chunyang, 35718


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






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

* bug#35718: 26.2; Functions in yank-handled-properties ALWAYS get called
  2019-06-07 13:03   ` Noam Postavsky
@ 2021-06-22 14:25     ` Lars Ingebrigtsen
  0 siblings, 0 replies; 4+ messages in thread
From: Lars Ingebrigtsen @ 2021-06-22 14:25 UTC (permalink / raw)
  To: Noam Postavsky; +Cc: Xu Chunyang, 35718

Noam Postavsky <npostavs@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





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

end of thread, other threads:[~2021-06-22 14:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-13 17:02 bug#35718: 26.2; Functions in yank-handled-properties ALWAYS get called Xu Chunyang
2019-06-07  9:27 ` Eli Zaretskii
2019-06-07 13:03   ` Noam Postavsky
2021-06-22 14:25     ` Lars Ingebrigtsen

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

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).