-
-
Notifications
You must be signed in to change notification settings - Fork 113
Inherit hydra faces from hydra-default-face #136
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
base: master
Are you sure you want to change the base?
Conversation
I guess the latter point would complicate the tests somewhat, unless there’s some way of doing the propertization before the actual format at run-time. |
Thanks a lot. But your change is quite large: I can accept only changes <=15 lines in total from a person without a on Emacs Copyright Assignment. I have an assignment, so that I'm allowed to have hydra in GNU ELPA. So you need to get one too if you want to contribute a large change to hydra (or any Emacs-related project, like org-mode or CEDET or Emacs itself). It's not hard, see description. In case you already have an assignment, I can fix up the tests which are failing and merge. |
Hi! Ah, I didn’t know ELPA had the copyright assignment thing. If the changes seem useful to you I can fill out the assignment no problem; my only concern was that they would make the tests too ugly for your tastes. It might take me a bit to get the forms posted, since I’m currently on travels; but if they snail mail it I suppose it takes a while anyway. Thanks for making hydra! |
The changes are useful, and the tests can be updated to be less ugly, and no one except me looks at them anyway. Besides, it would be great to get more PR from you in the future, also for other ELPA projects.
You're welcome. |
I recently realized I completely lost track of the copyright assigment process I had started back then. So, with only 2 years of latency, I now went through with the remaining step and have my assignment. Not surprisingly, the patch doesn’t apply anymore, but if you’re still interested, I can look into that. |
Thanks. Please rebase on top of master and update. I'll have a look. |
I simplified things somewhat. For now, all this does is add As for the tests, do you have some sort of setup to diff expanded hydra definitions with the earlier ones? I reckon one could replace the target strings by up-to-date macroexpanded hydras, but without inspecting the diffs one could miss potential regressions. |
Thanks. Could you also look into the failing tests? |
Hello Oleh. I did glance over the test suite, hence my question. A lot of the tests hard-code the exact propertized string they expect. So, when anything about the UI is changed, those tests will break. One would need to regenerate the target strings completely. However, this runs the risk of bypassing the whole idea of testing. Hence I was wondering how you handled that in the past. |
That's the idea. The current UI is what most users expect now. So if any commit changes the UI, it's for a good reason, and is tracked by updated UI tests. Unfortunately, there's manual work involved in rewriting the tests (easy), and checking that that they still make sense (harder). The hard part isn't that hard though, just When I rewrite the test, I point my cursor like this:
and call |
Okay, thanks! My guess is the best way to validate new targets is to diff them with the old ones. I will look into this. |
So I updated the failing tests. I couldn’t exactly reproduce your previous indentation though, even when tweaking |
31 32 (face hydra-face-red) | ||
42 45 (face hydra-face-red))))) | ||
(let ((result (eval format-statement))) | ||
(cl-loop |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks wrong here. The doc part of the result should be data, not code. So this cl-loop
should be evaluated in defhydra
, not at top-level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is what I initially referred to as «corner that had to be cut». Hydras may contain something like %20`foo
. Now consider this:
(with-current-buffer-window
"baz"
nil
nil
(insert
(format
(propertize "Magic number: %20s"
'face
'(:background "red"))
42)))
Because of the padding added, 42
will not be propertized. This is why I came to believe that faces must be set at run-time, not when compiling the format string. Do you see another way to handle these cases?
The whole string can be propertized with some base face, excepting the keys. Example: (defhydra hydra-toggle (:color pink :hint nil)
"
_a_ abbrev-mode: %`abbrev-mode
_d_ debug-on-error: %`debug-on-error
_f_ auto-fill-mode: %`auto-fill-function
_h_ highlight %`highlight-nonselected-windows
_t_ truncate-lines: %`truncate-lines
_w_ whitespace-mode: %`whitespace-mode
_l_ org link display: %`org-descriptive-links
"
("a" abbrev-mode)
("d" toggle-debug-on-error)
("f" auto-fill-mode)
("h" (setq highlight-nonselected-windows (not highlight-nonselected-windows)))
("t" toggle-truncate-lines)
("w" whitespace-mode)
("l" org-toggle-link-display)
("q" nil "quit")) Generates: (set
(defvar hydra-toggle/hint nil
"Dynamic hint for hydra-toggle.")
'(concat
(format
"%s abbrev-mode: %S
%s debug-on-error: %S
%s auto-fill-mode: %S
%s highlight %S
%s truncate-lines: %S
%s whitespace-mode: %S
%s org link display: %S
"
#("a"
0 1 (face hydra-face-pink))
abbrev-mode
#("d"
0 1 (face hydra-face-pink))
debug-on-error
#("f"
0 1 (face hydra-face-pink))
auto-fill-function
#("h"
0 1 (face hydra-face-pink))
highlight-nonselected-windows
#("t"
0 1 (face hydra-face-pink))
truncate-lines
#("w"
0 1 (face hydra-face-pink))
whitespace-mode
#("l"
0 1 (face hydra-face-pink))
org-descriptive-links)
#("[q]: quit."
1 2 (face hydra-face-blue)))) Two things can be done to
I think the second approach should be preferred, the advantage being more flexibility later, and no need to update the tests. |
I will look into |
Actually, I’m not sure if that would be enough… Hm. If the |
Note that
…generates:
With no face applied between indices 15 and 31. |
Just add logic that takes a string, and replaces the
This logic can be added to the function that eventually prints |
The stumbling block here is that this cannot be done at compile-time, at least not if the Hydra docstring contains something like
This is what I went for b
8000
y generating the
I don’t follow. Consider:
The issue is that this will always generate |
I meant do it at runtime. See how it's done in example: (defun hydra-toggle/body nil
"Create a hydra with no body and the heads:
\"a\": `abbrev-mode',
\"d\": `toggle-debug-on-error',
\"f\": `auto-fill-mode',
\"h\": `(setq highlight-nonselected-windows (not highlight-nonselected-windows))',
\"t\": `toggle-truncate-lines',
\"w\": `whitespace-mode',
\"l\": `org-toggle-link-display',
\"q\": `nil'
The body can be accessed via `hydra-toggle/body'."
(interactive)
(hydra-default-pre)
(let ((hydra--ignore nil))
(hydra-keyboard-quit)
(setq hydra-curr-body-fn
'hydra-toggle/body))
(hydra-show-hint
hydra-toggle/hint
'hydra-toggle)
(hydra-set-transient-map
hydra-toggle/keymap
(lambda nil
(hydra-keyboard-quit)
nil)
'run)
(setq prefix-arg
current-prefix-arg)) The relevant part is: (hydra-show-hint hydra-toggle/hint 'hydra-toggle) So |
I don’t really know what I’m doing with my elisp, but maybe this is useful to you anyway, with some brushing up. I was a bit bummed out because my hydras were always using the same font as the buffer contents, whereas I like to use a different font for mode-line and echo area; so this adds proper faces for all the other parts of the hydra, not just the heads.
One corner that had to be cut is that the offsets of face-properties are not adjusted when padding is added in a string format. This works around the problem by setting the default-face only after the format is done. To not clobber any face-assignments done earlier (for the heads), it goes over the string and only propertizes the parts that are not already propertized.