hydra icon indicating copy to clipboard operation
hydra copied to clipboard

display currently active hydra even when hints are toggled off

Open jonlee836 opened this issue 7 years ago • 2 comments

It would be nice to see the currently active hydra at all times unless the hints are active or the hydra exits.

For now I'm just using progn to output "nav-buff-wind-ctrl" to the mini-buffer, otherwise a blank mini-buffer is displayed until I toggle hints on and off. I got it to work when toggling hints, entering, and exiting the hydra but not during it's use.

window moving example

(defhydra nav-buff-wind-ctrl (:body-pre (hydra-hint-wrapper "nav-buff-wind-ctrl") :color amaranth :hint nil)

("w" (progn (windmove-up) (message hydra-currently-active)))
  ("a" (progn (windmove-left) (message hydra-currently-active)))
  ("s" (progn (windmove-down) (message hydra-currently-active)))
  ("d" (progn (windmove-right) (message hydra-currently-active)))

 ("`" (toggle-hydra-hint-status) :color red)
  ("q" (message "hydra exited safetly") :exit t))

Display current hydra

(defvar hydra-currently-active "")

;; show current hydra
(defun hydra-hint-wrapper (current-hydra)
  (setq hydra-currently-active current-hydra)
  (if (equal hydra-is-helpful 'nil)
      (progn
        ;; lisp that hooks into current hydra?
        (message hydra-currently-active)
        )
    )
  )

;; turn on hints inside hydra 
(defun toggle-hydra-hint-status ()
  (interactive)
  (if (equal hydra-is-helpful 't)
      (progn
        (message hydra-currently-active)
        (setq hydra-is-helpful nil)
        )
    (setq hydra-is-helpful t)
    )
  )

jonlee836 avatar Jan 23 '18 11:01 jonlee836

It would be nice to see the currently active hydra at all times unless the hints are active or the hydra exits.

For now I'm just using progn to output "nav-buff-wind-ctrl" to the mini-buffer, otherwise a blank mini-buffer is displayed until I toggle hints on and off. I got it to work when toggling hints, entering, and exiting the hydra but not during it's use.

I don't really understand what you're trying to achieve here. You want to see the hydra name, but not the key hints?

Try this code:

(defun toggle-hydra-hint-status ()
  (interactive)
  (let ((cv (hydra-get-property 'hydra-windmove :verbosity)))
    (if (eq cv 2)
        (hydra-set-property 'hydra-windmove :verbosity 0)
      (hydra-set-property 'hydra-windmove :verbosity 2))
    (hydra-windmove/body)))

(defhydra hydra-windmove ()
  "hydra-windmove"
  ("w" windmove-up nil)
  ("a" windmove-left nil)
  ("s" windmove-down nil)
  ("d" windmove-right nil)
  ("`" toggle-hydra-hint-status nil)
  ("q" (message "hydra exited safetly") nil :exit t))

abo-abo avatar Jan 23 '18 19:01 abo-abo

Try this code:

The name of the hydra still disappears upon hitting the movement keys.

Here's a hacky solution that uses :after-exit to output hydra-currently-active in the minibuffer and :before-exit to change the value of hydra-currently-active to "quit".

EDIT : I didn't notice messages from commands while inside hydra were being overwritten. Fixed it now.

hydra

(defhydra nav-buff-wind-ctrl (:body-pre (hydra-hint-wrapper "nav-buff-wind-ctrl")
                                        :before-exit (hydra-exit-and-cleanup)
                                        :after-exit (message hydra-currently-active)
                                        :color amaranth :hint nil)
  ("w" windmove-up)
  ("a" windmove-left) 
  ("s" windmove-down) 
  ("d" windmove-right)
  ("`" toggle-hydra-hint-status nil)
  ("~" (find-file hydra-active-file) :exit t)
  ("q" nil :exit t)
  ("C-c" nil :exit t)
  ("C-g" nil :exit t))

function

(defvar hydra-currently-active "")
(defvar hydra-active-file "")

(defun hydra-exit-and-cleanup ()
  (setq hydra-currently-active 'nil)
  (hydra-display-string)
  )

;; prevent overwriting of messages from other commands
(defun hydra-display-string ()
  (if (not (current-message))
      (if (not (equal hydra-currently-active 'nil))
          (if (equal hydra-is-helpful nil)
              (message hydra-currently-active)
            )
        (message "quiting")
        )
    )
  )

;; display current hydra
(defun hydra-hint-wrapper (current-hydra)
  ;; (mode-line ((t (:background "blue" :foreground "brightwhite"))))
  (setq hydra-currently-active current-hydra)
  (setq hydra-active-file (concat emacs-key-directory "/" hydra-currently-active ".el"))
  (if (equal hydra-is-helpful 'nil)
      (message hydra-currently-active)
    )
  )

;; toggle hints while inside hydra 
(defun toggle-hydra-hint-status ()
  (interactive)
  (if (equal hydra-is-helpful 't)
      (progn
        (message hydra-currently-active)
        (setq hydra-is-helpful nil)
        )
    (progn (setq hydra-is-helpful t)
           )
    )
  )

;; use origami inside code otherwise use org-mode
(defun toggle-org-origami ()
  (interactive)
  (if (not (equal major-mode 'org-mode))
      (origami-ctrl/body)
    (org-custom/body)
    )
  )

jonlee836 avatar Jan 25 '18 02:01 jonlee836