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

Visual indicator not always correct #24

Open
098799 opened this issue Jan 31, 2019 · 13 comments
Open

Visual indicator not always correct #24

098799 opened this issue Jan 31, 2019 · 13 comments
Labels

Comments

@098799
Copy link

098799 commented Jan 31, 2019

Visual indicator (red cursor) is not working on startup of emacs. Also when switching/killing buffers I frequently mistakenly get white cursor for when I'm in fact in the ryo mode.

One clear example is:

  • I'm in ryo mode (cursor is red).
  • I enter magit popup, my cursor is white and I'm not in ryo mode (correct).
  • I press q to leave the magit popup and I'm back in ryo mode, but incorretly with white cursor.

My use-package config hooks regarding which modes have ryo enabled by default are as follows (and I don't want to add magit popup to that as it has it's own set of single letter shortcuts):

:config (add-hook 'text-mode-hook #'ryo-modal-mode) (add-hook 'prog-mode-hook #'ryo-modal-mode) (add-hook 'fundamental-mode-hook #'ryo-modal-mode) (add-hook 'conf-unix-mode-hook #'ryo-modal-mode)

Thank you for all the work you've put into developing this package. I'm using it for a few months now and my config grew up to 150 lines of shortcuts. I like it a lot and I really don't feel like switching, but not knowing if I'm in the ryo mode or not at a glance makes it sometimes cumbersome to use.

@Kungsgeten
Copy link
Owner

Hi! Sorry that I haven't replied here, must have forgotten about it.

To be honest I don't know why the visual indicator sometimes doesn't work. The check for it is used in post-command-hook which is run almost no matter what you do.

In the case of Magit I've done some research. The function magit-restore-window-configuration ends with the following code:

(when (and winconf (equal frame (window-configuration-frame winconf)))
      (set-window-configuration winconf)
      (when (buffer-live-p buffer)
        (with-current-buffer buffer
          (setq magit-previous-window-configuration nil))))

If I try and comment out this, it seems like the cursor color switching works. @tarsius Do you know why magit-restore-window-configuration doesn't seem to call post-command-hook when it is done?

@tarsius
Copy link

tarsius commented Aug 16, 2019

No lisp code should ever call post-command-hook. Emacs calls that hook somewhere in the command-loop, which is implemented in C.

@Kungsgeten
Copy link
Owner

@tarsius Yes ofcourse. I just find it strange that the quoted code somehow has the effect that post-command-hook isn't run after the function has been executed (and we've returned to the original buffer).

@tarsius
Copy link

tarsius commented Aug 16, 2019

I just find it strange that the quoted code somehow has the effect that post-command-hook isn't run after the function has been executed

I strongly doubt that it has that effect. In fact pressing q in a popup buffer does not even call this function. Also note that Magit no longer uses magit-popup it now uses transient. So if you suspect that this issue has something to do with the Magit's popups, then you should try to reproduce the issue with a recent snapshot of Magit, which uses transient.

@Kungsgeten
Copy link
Owner

@tarsius I'm using the latest version of Magit when testing, so transient is used. I know that q doesn't run magit-restore-window-configuration directly, but it does so via magit-mode-bury-buffer and magit-bury-buffer-function by default. I tried using magit-mode-quit-window instead, which seems to work.

I suspect that set-window-configuration perhaps runs post-command-hook before everything has actually been changed (or something like that). Anyway thanks for your replying and keep up the good work!

@098799
Copy link
Author

098799 commented Aug 16, 2019

It's not only magit's behavior that is affected. I can't provide additional examples until Monday unfortunately.

@Kungsgeten
Copy link
Owner

There's no rush :) But please see if you can give other examples and perhaps I can try to see if there's a common factor among them.

@098799
Copy link
Author

098799 commented Aug 19, 2019

Another case: I'm in ryo, I open a file (counsel-find-file) that doesn't have ryo hook enabled and the indicator is still red, but ryo-mode is off (until I press any key, then it's updated).

@Kungsgeten Kungsgeten added the bug label Aug 20, 2019
@Kungsgeten
Copy link
Owner

Kungsgeten commented Aug 20, 2019

I also get this bug. Unfortunately I don't know how to fix it. One "solution" could be to use a different cursor for RYO, for instance like this:

(setq ryo-modal-cursor-type 'hbar)
(setq ryo-modal-cursor-color nil)

@098799
Copy link
Author

098799 commented Aug 20, 2019

Perhaps that should be the out-of-the-box behavior, since it's the only correct one. Fixes magit issues as well, btw.

@eldyer
Copy link

eldyer commented Sep 16, 2019

I have the same issue, but the use of a different cursor indeed fixes it.

lmintmate added a commit to lmintmate/emacs.d that referenced this issue Apr 12, 2020
I really liked the result I had achieved. However I found out that
calling post-command-hook isn't a good
idea (github.com/Kungsgeten/ryo-modal/issues/24#issuecomment-521966076)
and since I don't know what else I could use to enforce the cursor
changes, I'm removing the entire code and will rely on just cursor
color instead (I don't want to change the cursor shape). At least
after some thought I managed to think of a good color that fits with
my theme.
@BlankSpruce
Copy link
Contributor

I'm not sure if it covers all the cases but here's something I've discovered:
For current ryo-modal I couldn't recreate the first example provided in this issue but I can observe wrong cursor color when I do the following sequence:

  • ryo-modal-mode on in the buffer
  • C-x C-f
  • call embark-act, press ! (to select shell-command)
  • call any shell command (like echo 123)
  • shell commands ends, ryo-modal-mode is still on, wrong cursor color until I do any movement command

Now if I add the following to my init.el:

(defun foobar ()
  (when ryo-modal-mode
    (ryo-modal--cursor-color-update)))

(add-hook 'buffer-list-update-hook 'foobar)

the color of the cursor is changed as expected as soon as shell command ends. I don't know any major disadvantages of this approach though.

@098799
Copy link
Author

098799 commented May 21, 2022

Thanks @BlankSpruce. It's been a few years and I've gotten used to only caring about the shape of the cursor, which I've customized to be vim-like (thin on insert mode, i.e. ryo-modal-off). This has been working fine.

All in all my Emacs setup has matured a little bit and i don't change packages and config too often anymore. Ryo-modal has retained it's spot as one of the most important packages in my configuration, kudos @Kungsgeten !

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

No branches or pull requests

5 participants