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

Add support for moody and doom-modeline. #7

Closed
4goodapp opened this issue Mar 17, 2019 · 19 comments
Closed

Add support for moody and doom-modeline. #7

4goodapp opened this issue Mar 17, 2019 · 19 comments

Comments

@4goodapp
Copy link

Using keycast with moody or doom-modeine give the following errors respectively:

Error (use-package): keycast/:config: Cannot turn on keycast-mode. mode-line-buffer-identification not found in mode-line-format

user-error: Cannot turn on keycast-mode. mode-line-buffer-identification not found in mode-line-format

Can it even work with those modelines?

@tarsius
Copy link
Owner

tarsius commented Mar 17, 2019

You have to customize keycast-insert-after.

@vincentbernat
Copy link

The problem with these modeline modifications is they are built with :eval. It could be inserted after the :eval, but there is usually no room left. What would be useful is to provide an on/off hook function to let user update the "theme" they are using.

@tarsius
Copy link
Owner

tarsius commented Dec 8, 2019

Sorry but I don't understand.

@vincentbernat
Copy link

I am using the following modeline:

(setq-default mode-line-format '("%e" (:eval (spaceline-ml-main))))

keycast-insert-after is not fit to modify such a modeline. Instead, if you can provide a way to call a hook function when the mode-line-format needs to be modified to include mode-line-keycast, this would let the user decide where they want to put mode-line-keycast.

@tarsius
Copy link
Owner

tarsius commented Dec 9, 2019

It seems unfortunate to me what spaceline is doing. Emacs provides a customization interface "list/tree of of elements stored in variable mode-line-format", which has the advantage that it is easy for packages to add additional elements.

Spaceline chooses to ignore that interface as much as it possibly can, which has the drawback that now every package that wants to add an element to the mode-line now has to reimplement that just for spaceline once a users of spaceline comes along. Or not--I don't think I am going to do that. Sorry.

However once you have implemented the below mode I might add that to keycast. I might also consider it too ugly and "its not my fault that spaceline makes such ugly hacks necessary" and you might then have to distribute it as a separate package.

(define-minor-mode spaceline-keycast-mode
  "Show current command and its key binding in the mode line.
This is a reimplementation of `keycast-mode' for use by users
of the `spaceline' package."
  :global t
  (if spaceline-keycast-mode
      (progn
        ;; ... your code here ...
        (add-hook 'pre-command-hook 'keycast-mode-line-update t))
    ;; ... your code here ...
    (remove-hook 'pre-command-hook 'keycast-mode-line-update)))

@d1egoaz
Copy link

d1egoaz commented May 12, 2020

FYI, I got it working with the the help of doom-emacs creator through the discord channel:

This was the the code that made it work for me:

(after! keycast
  (define-minor-mode keycast-mode
    "Show current command and its key binding in the mode line."
    :global t
    (if keycast-mode
        (add-hook 'pre-command-hook 'keycast--update t)
      (remove-hook 'pre-command-hook 'keycast--update))))
(add-to-list 'global-mode-string '("" mode-line-keycast))
(keycast-mode) ;; or run keycast-mode by demand

non doom-emacs users:

(with-eval-after-load 'keycast
  (define-minor-mode keycast-mode
    "Show current command and its key binding in the mode line."
    :global t
    (if keycast-mode
        (add-hook 'pre-command-hook 'keycast--update t)
      (remove-hook 'pre-command-hook 'keycast--update)))

  (add-to-list 'global-mode-string '("" mode-line-keycast)))

https://discord.com/channels/406534637242810369/603399769015975996/709874678520610946
https://discord.com/channels/406534637242810369/603399769015975996/709875976317829161

edit:

@tarsius
Copy link
Owner

tarsius commented May 12, 2020

These conversations are behind registration walls. Beyond the realization that the ... your code here ... aren't even necessary, what other insights did they come up with?

@d1egoaz
Copy link

d1egoaz commented May 12, 2020

ohh right, the conversations are not public available as in Github, sorry about that.

Honestly, I didn't dig into this too much, he was helping other people at the same time.
He started with this version:

(after! keycast ;; same as (with-eval-after-load 'keycast
  (add-to-list 'global-mode-string '("" mode-line-keycast)))

and ended with the one above.

@4goodapp
Copy link
Author

@d1egoaz Just tried your code, It appear to be working fine using doom-modeline. Thanks for sharing.

@anupam312nwd
Copy link

anupam312nwd commented Mar 4, 2021

If anyone visiting this page, the command keycast-mode-line-update is changed to keycast--update.
Please change the corresponding function in the code provided above to have it working.
source: 6d75f14

@d1egoaz
Copy link

d1egoaz commented May 14, 2021

If anyone visiting this page, the command keycast-mode-line-update is changed to keycast--update.
Please change the corresponding function in the code provided above to have it working.
source: 6d75f14

updated! thanks

azzamsa added a commit to azzamsa/emacs.d that referenced this issue Jun 10, 2021
azzamsa added a commit to azzamsa/emacs.d that referenced this issue Jun 16, 2021
@AtomicNess123
Copy link

So, to summarize, to be able to use doome-modeline with keycast-mode, how to proceed? Thanks!

@tarsius
Copy link
Owner

tarsius commented Jul 11, 2021

So, to summarize, to be able to use doome-modeline with keycast-mode, how to proceed?

#7 (comment)

@otech-nl
Copy link

otech-nl commented Jul 16, 2021

For those using doom-mode-line with use-package:

(use-package keycast
  :config
  (define-minor-mode keycast-mode
    "Show current command and its key binding in the mode line (fix for use with doom-mode-line)."
    :global t
    (if keycast-mode
        (add-hook 'pre-command-hook 'keycast--update t)
      (remove-hook 'pre-command-hook 'keycast--update)))
  (add-to-list 'global-mode-string '("" mode-line-keycast)))

@DivineDominion
Copy link

@otech-nl Found the same code on EmacsWiki -- when I shut off keycast-mode, the it doesn't remove the entry for keycast, though. It's forever displaying the confirmation command of M-x keycast-mode (in my case something w.r.t. selectrum selection). Did you not run into an issue like that?

@otech-nl
Copy link

No, sorry. That doesn't sound familiar.

@CIAvash
Copy link

CIAvash commented Jan 20, 2022

With the latest change 72d9add, mode-line-keycast needs to be changed to keycast-mode-line.

@AtomicNess123
Copy link

Thanks! Is there a way for it to be shown in a pop up?

@psionic-k
Copy link

psionic-k commented Jan 16, 2024

For my personal use, I created a "freestyle" mode that doesn't attempt to display anything and just leaves the result in a variable. The existing modeline integration was trying to do a lot. This was easier to integrate (example below).

https://github.com/psionic-k/keycast/tree/freestyle-mode

I agree with Tarsius that these modeline packages are not playing nice. It's fine to eliminate modeline spam, but advice is almost always a sure sign that something was too rigid.

(use-package keycast
  :config
  (setopt keycast-mode-line-format
          "%k%c%r ")
  (setopt keycast-substitute-alist
          '((keycast-log-erase-buffer nil nil)
            (transient-update         nil nil)
            (self-insert-command      nil nil)
            (mwheel-scroll nil nil)))

  ;; Unfortunately "for historical reasons" according to the manual, there is no
  ;; facility to read the actual `selected-window' when it has been temporarily
  ;; set.  Even if you know what you are doing.  Luckily Tarsius has us covered
  ;; with a workaround in the moody package.
  (defvar moody--active-window (selected-window))

  (defun moody-window-active-p ()
    "Return t if the selected window is the active window.
Or put differently, return t if the possibly only temporarily
selected window is still going to be selected when we return
to the command loop."
    (eq (selected-window) moody--active-window))

  (defun moody--set-active-window (_)
    (let ((win (selected-window)))
      (setq moody--active-window
            (if (minibuffer-window-active-p win)
                (minibuffer-selected-window)
              win))))
  (add-hook 'pre-redisplay-functions #'moody--set-active-window)

  ;; Decorating an existing item in the modeline
  (defun pmx-keycast-doom-modeline-update (return)
    (if (moody-window-active-p)
        (concat return " " keycast-last-formatted)
      return))

  ;; Mode line hooks get called on start and stop :-)
  (defun pmx-keycast-doom-modeline-integrate ()
    (if keycast-freestyle-mode
        (advice-add #'doom-modeline-segment--buffer-position :filter-return
                    #'pmx-keycast-doom-modeline-update)
      (advice-remove #'doom-modeline-segment--buffer-position
                     #'pmx-keycast-doom-modeline-update)))

  (add-hook 'keycast-freestyle-mode-hook #'pmx-keycast-doom-modeline-integrate))

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

10 participants