emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Simple isearch concerns


From: Juri Linkov
Subject: Re: Simple isearch concerns
Date: Mon, 12 Apr 2021 01:17:04 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (x86_64-pc-linux-gnu)

>> (Note that you should wait to push it until my paperwork has been
>> processed by the FSF, I wasn't aware of that subtlety.)

While you are waiting for your paperwork to be processed,
I'd like to point out that when I tried to debug a problem
of the failed lazy-highlighting for non-nil lazy-highlight-buffer,
I noticed that the current implementation is not the best one:

> +(put 'beginning-of-buffer 'isearch-motion
> +     '((lambda () (goto-char (point-min))) . forward))
>
> +      (let* ((property (get this-command 'isearch-motion))
> +             (function (car property))
> +        (funcall function)
> +        (setq this-command 'ignore)))

The problem is that it executes a function as a command,
and resets the current command to 'ignore'.  This causes
more problems.

Instead of emulating the command execution, it would be more natural
to let the command to be completed as usual, then call 'isearch-repeat'
in 'isearch-post-command-hook' after the command moved point.

This is how other existing features work: isearch-allow-prefix,
isearch-allow-scroll, isearch-yank-on-move.  They prepare internal
variables in isearch-pre-command-hook, let the command to move point,
then do post-processing in isearch-post-command-hook to update
the search string, etc.

Then instead of such definition:

  (put 'beginning-of-buffer 'isearch-motion
       '((lambda () (goto-char (point-min))) . forward))

you can use a shorter definition

  (put 'beginning-of-buffer 'isearch-motion 'forward)

that means: let the command 'beginning-of-buffer' move point
to the beginning of the buffer, then call 'isearch-repeat'
with the argument 'forward' in isearch-pre-command-hook.

When there is no existing command with required functionality,
then the command body could be defined in the property, e.g.

  (put 'scroll-up-command 'isearch-motion
       '((lambda () (interactive) (goto-char (window-end))) . forward))

Then in isearch-pre-command-hook you can setq 'this-command' to
the command definition:

  (let* ((property (get this-command 'isearch-motion))
         (function (car property))
    (setq this-command function)))

then the definition will be executed as a command.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]