Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some comments on minibuffer setup and exit hook logic #174

Open
akashpal-21 opened this issue Jun 16, 2024 · 1 comment
Open

Some comments on minibuffer setup and exit hook logic #174

akashpal-21 opened this issue Jun 16, 2024 · 1 comment

Comments

@akashpal-21
Copy link

akashpal-21 commented Jun 16, 2024

Currently the following logic is implemented in xah-fly-keys mode

;; Construction:
(add-hook 'minibuffer-setup-hook 'xah-fly-insert-mode-activate)
(add-hook 'minibuffer-exit-hook 'xah-fly-command-mode-activate)

;; ;; Teardown:
(remove-hook 'minibuffer-setup-hook 'xah-fly-insert-mode-activate)
(remove-hook 'minibuffer-exit-hook 'xah-fly-command-mode-activate)

Problem description:

  1. If minibuffer is called when insert-mode is active - it must not revert to command mode when minibuffer exits

  2. Some workflow such as when using consult-completions-in-region as the completion-in-region-function requires calling another minibuffer session to handle when completions is called. This causes the command-mode to be activated prematurely after the completions has completed -- instead when the minibuffer has actually exited.

Possible solution

Define a logic to determine when minibuffer session has actually exited using a post-command-hook when switchover from command to insert is required -- this adds some extra overheads.

(defun xah-fly--minibuffer-setup ()
  "Activate `xah-fly-insert-mode` in the minibuffer."
  (unless xah-fly-insert-state-p
    (xah-fly-insert-mode-activate)
    (add-hook 'post-command-hook #'xah-fly--check-minibuffer-exit)))

(defun xah-fly--check-minibuffer-exit ()
  "Check if the minibuffer has been exited and activate command mode."
  (unless (active-minibuffer-window)
    (xah-fly-command-mode-activate)
    (remove-hook 'post-command-hook #'xah-fly--check-minibuffer-exit)))
;; Construction:
(add-hook 'minibuffer-setup-hook #'xah-fly--minibuffer-setup)

;; Teardown:
(remove-hook 'minibuffer-setup-hook #'xah-fly--minibuffer-setup)
(remove-hook 'post-command-hook #'xah-fly--check-minibuffer-exit)

Please let me know if some other trivial solution exists.

Best,

@akashpal-21
Copy link
Author

akashpal-21 commented Jun 16, 2024

I wish to clarify one point,

Some workflow such as when using consult-completions-in-region as the completion-in-region-function requires calling another minibuffer session to handle when completions is called. This causes the command-mode to be activated prematurely after the completions has completed -- instead when the minibuffer has actually exited.

This is relevant only when using eval-expression M-: (default overwritten by xah-fly-keys as <space> , r) - we can use autocompletions (minibuffer on top of another minibuffer) in consult-completions-in-region here.

But also as implied - this type of autocompletions constantly reverts xah-fly-keys to command-mode due to the minibuffer-exit-hook even when called when insert-mode is currently active (during normal data entry operations).

Sorry if I were not too clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant