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

Feature request: simpler api for customizing transient states #5405

Open
sooheon opened this issue Mar 8, 2016 · 20 comments
Open

Feature request: simpler api for customizing transient states #5405

sooheon opened this issue Mar 8, 2016 · 20 comments
Labels
Feature request stale marked as a stale issue/pr (usually by a bot) Transient-state

Comments

@sooheon
Copy link

sooheon commented Mar 8, 2016

For example, paste transient state is defined:

(spacemacs|define-transient-state paste
        :title "Pasting Transient State"
        :doc "\n[%s(length kill-ring-yank-pointer)/%s(length kill-ring)] \
[_C-j_/_C-k_] cycles through yanked text, [_p_/_P_] pastes the same text above or \
below. Anything else exits."
        :bindings
        ("C-j" evil-paste-pop)
        ("C-k" evil-paste-pop-next)
        ("p" evil-paste-after)
        ("P" evil-paste-before)
        ("0" spacemacs//transient-state-0))

Is there a way for me to have in my config:

(spacemacs|customize-transient-state paste 
  :bindings ("C-j" nil) 
            ("C-k" nil) 
            ("M-n" evil-paste-pop) 
            ("M-p" evil-paste-pop-next))

I suppose I could duplicate the code and redefine it at the end of config load, but I'm hoping for a better approach.

@nixmaniack
Copy link
Contributor

I think you're looking for this if it's just related to customizing bindings.

(defun spacemacs-ivy/post-init-auto-highlight-symbol ()
(setq spacemacs-symbol-highlight-transient-state-remove-bindings
'("/" "b" "f"))
(setq spacemacs-symbol-highlight-transient-state-add-bindings
'(("/" spacemacs/search-project-auto-region-or-symbol :exit t)
("b" spacemacs/swiper-all-region-or-symbol :exit t)
("f" spacemacs/search-auto-region-or-symbol :exit t))))

@sooheon
Copy link
Author

sooheon commented Mar 8, 2016

@nixmaniack great, that looks like exactly what I was looking for. Do you know if there's anything to also fix the docstring, then?

@nixmaniack
Copy link
Contributor

As per my understanding, I don't think there's a way at this moment to customize docstring. You might want to create a feature request for it.

@sooheon
Copy link
Author

sooheon commented Mar 8, 2016

Ideally, if the customization macro could be in the form I suggested above, one could arbitrarily adjust any part of the transient state transparently, rather than having to create separate functions to touch each piece. Can @justbur comment on the feasibility of this?

@TheBB
Copy link
Collaborator

TheBB commented Mar 8, 2016

You change the docstring by tweaking the variable (in this case) spacemacs/paste-transient-state/hint.

It's a form that is evaled.

@justbur
Copy link
Contributor

justbur commented Mar 8, 2016

@TheBB is right. Be aware that if you want the coloring you either need to do it manually or use hydra--format

@syl20bnr
Copy link
Owner

syl20bnr commented Mar 8, 2016

There is a macro now to apply hydra formatting to a string, I'm on mobile and cannot paste the name here for now.

@sooheon
Copy link
Author

sooheon commented Mar 8, 2016

So to switch C-k/C-j bindings to C-n/C-p, I need:

(defun sooheon/post-init-evil ()
  (setq spacemacs-paste-transient-state-remove-bindings
        '("C-j" "C-k"))
  (setq spacemacs-paste-transient-state-add-bindings
        '(("C-n" evil-paste-pop)
          ("C-p" evil-paste-pop-next)))
  (setq spacemacs/paste-transient-state/hint
        '(concat
          #("Pasting Transient State\n"
            0 23 (face
                  spacemacs-transient-state-title-face))
          (concat
           (format
            "[%s/%s] [%s/%s] cycles through yanked text, [%s/%s] pastes the same text above or below. Anything else exits."
            (length kill-ring-yank-pointer)
            (length kill-ring)
            #("C-n"
              0 3 (face hydra-face-red))
            #("C-p"
              0 3 (face hydra-face-red))
            #("p" 0 1 (face hydra-face-red))
            #("P" 0 1 (face hydra-face-red)))
           "")
          nil
          nil)))

I can confirm that this does work, but isn't it a bit much? Or am I missing a more elegant way to do it?

@justbur
Copy link
Contributor

justbur commented Mar 8, 2016

You're adjusting the docstring and most of the bindings, so why not just redefine the transient state?

@sooheon
Copy link
Author

sooheon commented Mar 8, 2016

That seems like the cleaner way. It's not really clear how to do that, though (as in where to add the redefinition). So far, I've tried it in dotspacemacs-user-config, inside a post-config-evil function in private layer, and inside pre-init-evil, dotspacemacs|use-package-add-hook evil :post-config as well. None have worked so far. Where should it go to take effect?

@justbur
Copy link
Contributor

justbur commented Mar 8, 2016

try this which should work anywhere in user-config (no hooks)

(spacemacs|define-transient-state my-paste
        :title "Pasting Transient State"
        :doc "\n[%s(length kill-ring-yank-pointer)/%s(length kill-ring)] \
[_M-n_/_M-p_] cycles through yanked text, [_p_/_P_] pastes the same text above or \
below. Anything else exits."
        :bindings
        ("M-n" evil-paste-pop)
        ("M-p" evil-paste-pop-next)
        ("p" evil-paste-after)
        ("P" evil-paste-before)
        ("0" spacemacs//transient-state-0))
(define-key evil-normal-state-map "p" 'spacemacs/my-paste-transient-state/evil-paste-after)
(define-key evil-normal-state-map "P" 'spacemacs/my-paste-transient-state/evil-paste-before)

@justbur
Copy link
Contributor

justbur commented Mar 8, 2016

The issue is that the transient-states are all loaded at once at the end of the initialization, so that your definition is probably getting overwritten. This was to allow people to change the key bindings ironically.

@sooheon
Copy link
Author

sooheon commented Mar 8, 2016

@justbur thanks, my mistake was defining the same paste transient state, which I thought would be fine if "I am the one who overrides".

While my question is essentially answered, I do wonder what kind of impact all of these patches on patches on patches of elisp has for startup time...

@sooheon
Copy link
Author

sooheon commented Mar 10, 2016

With the unspoken consensus that for now these two methods answer the issue, I'll close.

I do think that as we deal with editing styles molding to user preferences, having transient states be so rigid is a problem in the long term. It'd be amazing if transient state bindings could be as easily editable as evil-define-key for a given state.

@sooheon sooheon closed this as completed Mar 10, 2016
@sooheon sooheon changed the title How to adjust spacemacs defined transient-state bindings? Feature request: simpler api for customizing transient states Mar 10, 2016
@sooheon sooheon reopened this Mar 10, 2016
@sooheon
Copy link
Author

sooheon commented Mar 10, 2016

On second thought, no harm in keeping this around as context, and an open ended call for those with the elisp-foo to mull over this api. If we think of transient states as really first class states or "modes", it makes sense that customizing them should be as accessible as something like evil-define-key.

@braham-snyder
Copy link
Contributor

braham-snyder commented Mar 18, 2017

here's an open PR taking a step in the right direction, from @madand – it adds a function that automatically sets or appends to spacemacs-%s-transient-state-add-bindings variables, depending on whether the variable already exists: #8155

EDIT: I think this may be another good example of a transient state customization that would benefit greatly from something like spacemacs|customize-transient-state (as suggested in the OP): I'd simply like to remove the :on-exit property of the time-machine transient state (so that I can exit the hydra without quitting git-timemachine and its buffer).

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Feb 29, 2020
@madand
Copy link
Contributor

madand commented Mar 1, 2020

This issue is still valid and transient state machinery would certainly
benefit from improved macrology around it.

Regarding @braham-snyder's issue with not being able to override :on-exit hook
of time-machine transient state . I believe I figured out a simple way to
solve it. We just need to convert every lisp form, that is used with :on-entry
and :on-exit hook, into a defun. This way users will be able to redefine or
advice them at will, no changes to define-transient-state required.

I will make PR with the mentioned change later this week.

--

Another issue I can think of is abuse of :dynamic-hint for implementing
switching between (static) minimal and full hints. Note the same boilerplate
code again and again:

(defun spacemacs//web-ts-toggle-hint ()
"Toggle the full hint docstring for the web transient state."
(interactive)
(setq spacemacs--web-ts-full-hint-toggle
(not spacemacs--web-ts-full-hint-toggle)))
(defun spacemacs//web-ts-hint ()
"Return a condensed/full hint for the web transient state"
(concat
" "
(if spacemacs--web-ts-full-hint-toggle
spacemacs--web-ts-full-hint
(concat "[" (propertize "?" 'face 'hydra-face-red) "] help"
spacemacs--web-ts-minified-hint))))

(defun spacemacs//vue-ts-toggle-hint ()
"Toggle the full hint docstring for the vue transient state."
(interactive)
(setq spacemacs--vue-ts-full-hint-toggle
(not spacemacs--vue-ts-full-hint-toggle)))
(defun spacemacs//vue-ts-hint ()
"Return a condensed/full hint for the vue transient state"
(concat
" "
(if spacemacs--vue-ts-full-hint-toggle
spacemacs--vue-ts-full-hint
(concat "[" (propertize "?" 'face 'hydra-face-red) "] help"
spacemacs--vue-ts-minified-hint))))

(defun spacemacs//scroll-ts-toggle-hint ()
"Toggle the full hint docstring for the scroll transient state."
(interactive)
(setq spacemacs--scroll-ts-full-hint-toggle
(not spacemacs--scroll-ts-full-hint-toggle)))
(defun spacemacs//scroll-ts-hint ()
"Return a condensed/full hint for the scroll transient state"
(concat
" "
(if spacemacs--scroll-ts-full-hint-toggle
spacemacs--scroll-ts-full-hint
(concat "[" (propertize "?" 'face 'hydra-face-red) "] toggle help"))))

@duianto duianto removed the stale marked as a stale issue/pr (usually by a bot) label Mar 15, 2020
@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Mar 15, 2021
@lebensterben lebensterben removed stale marked as a stale issue/pr (usually by a bot) - Mailling list - labels Mar 14, 2022
Copy link

github-actions bot commented May 1, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request stale marked as a stale issue/pr (usually by a bot) Transient-state
Projects
None yet
Development

No branches or pull requests

10 participants