meow-edit / meow

Yet another modal editing on Emacs / 猫态编辑
GNU General Public License v3.0
1.07k stars 128 forks source link

How to sync completion changes (Corfu) in Beacon mode? #530

Closed ahan98 closed 4 months ago

ahan98 commented 4 months ago

Hi, thanks for all your hard work on this excellent package.

I'm wondering how to apply autocompletions to all the fake cursors in Beacon mode.

For example:

(def)
(def)

From line 1: xxGbeiu<tab><esc> results in

(def)
(defun)

Is there any way to apply the completion to all cursors in Beacon? I'm using Corfu, but the type of completion probably doesn't matter. I'm using the default config suggested on the Corfu repo.

I am using only the default QWERTY (meow-setup).

DogLooksGood commented 4 months ago

The beacon mode is a wrapper for keyboard macro, which doesn't work well with operations without deterministic result. The outputs from completions are dynamic, the first option may change on different lines. For such use case, you probably want to do it with query-replace or query-replace-regexp.

ahan98 commented 4 months ago

Thanks for the fast reply. I see your point. But, I wonder if we can do something like this (I couldn't get this to work, and it is a little silly, but I think the idea is interesting):

(defun corfu-insert-advice (orig-fun &rest args)
  (let ((start (point)))
    (apply orig-fun args)
    (when-let* ((end (point))
        (suffix (buffer-substring-no-properties start end)))
      (message "completed suffix: %s" suffix)
      (delete-region start end)
      (insert suffix))))
(advice-add 'corfu-complete :around 'corfu-insert-advice)

I'm actually surprised that this doesn't work because I would think the macro should treat the insertion as literal keyboard presses right?

Anyway, I guess there's not much to do here, so I'll close the issue, but it's an interesting thought experiment at least...

DogLooksGood commented 4 months ago

A keyboard macro is a sequence of key inputs. So it only tracks your keyboard input as KEYS, not even commands.