xahlee / xah-fly-keys

the most efficient keybinding for emacs
http://xahlee.info/emacs/misc/xah-fly-keys.html
469 stars 80 forks source link

Backtrace - Debugger execution causes xah-fly-command-mode to fail - requring manual intervention. #176

Open akashpal-21 opened 2 weeks ago

akashpal-21 commented 2 weeks ago

If command-mode is active - and the user evaluates an expression that results in the backtrace being called - the debugger-mode will silently clear the transient map - meaning although the command mode is active -- none of the keybindings is currently active - this failure is not resolved when the debugger mode is exited.

This will require from the user to call the command mode to reestablish parity of keybinding with the xah-fly-mode currently active.

 (defun xah-fly--backtrace-setup (debug &rest args)
  "Advice around `debug` to restart `xah-fly-command-mode` after backtrace,
if the preceding mode before entering backtrace is command-mode,
During the backtrace command-mode is disabled temporarily.

ORIG-FUNC is the original `debug` function. ARGS are its arguments."
  (unless xah-fly-insert-state-p
    (xah-fly-insert-mode-activate)
    (add-hook 'post-command-hook #'xah-fly--backtrace-activate-command-mode))
  ;; Call the original `debug` function
  (apply debug args))
(advice-add 'debug :around #'xah-fly--backtrace-setup)

(defun xah-fly--backtrace-activate-command-mode ()
  "Activate `xah-fly-command-mode` after exiting the debugger."
  (unless (let ((buffer (get-buffer "*Backtrace*")))
        (and buffer (buffer-live-p buffer) (get-buffer-window buffer)))
    (xah-fly-command-mode-activate)
    (remove-hook 'post-command-hook #'xah-fly--backtrace-activate-command-mode)))

The procedure shown above is an example of how to work around it. Since the command mode binding is disregarded by debug mode, there is no reason to keep it - during backtrace the switch is made from command-mode to insert-mode and when the backtrace window has been killed using q or c (quit or continue), the command mode is restarted if required.

How to reproduce:

  1. while in command mode evaluate (xyz) this will cause a failure and call the backtrace.
  2. the user will find the command mode keybindings no longer work although the mode is clearly active
  3. when debugger exits the problem is still not resolved
  4. evaluate xah-fly-command-mode-active to re-establish parity.
xahlee commented 2 weeks ago

i have this problem too sorry for delay. haven't looked into yet. will do next couple of days. this is a bit complex so will take some time to look into.

akashpal-21 commented 1 week ago

No problem Xah, please take your time -- the temporary advice hack works good enough for me in the meantime --

I do the advice within the xah-fly-mode -- but we should avoid using advice whenever possible, but as a temporary solution it is good enough for now to work around the problem for me.