Closed olets closed 4 months ago
As a workaround solution, I use this code snippet at the end of .zshrc
file to highlight for single word abbreviations.
chroma_single_word() {
(( next_word = 2 | 8192 ))
local __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
(( __first_call )) && { __style=${FAST_THEME_NAME}command }
[[ -n "$__style" ]] && (( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER}, __start >= 0 )) && reply+=("$__start $__end ${FAST_HIGHLIGHT_STYLES[$__style]}")
(( this_word = next_word ))
_start_pos=$_end_pos
return 0
}
# register single word command execpt for the followings:
# - already in PATH
# - already in fast-syntax-highlighting chroma map
register_single_word_chroma() {
local word=$1
if [[ -x $(command -v $word) ]] || [[ -n $FAST_HIGHLIGHT["chroma-$word"] ]]; then
return 1
fi
FAST_HIGHLIGHT+=( "chroma-$word" chroma_single_word )
return 0
}
if [[ -n $FAST_HIGHLIGHT ]]; then
for abbr in ${(f)"$(abbr list-abbreviations)"}; do
if [[ $abbr != *' '* ]]; then
register_single_word_chroma ${(Q)abbr}
fi
done
fi
@tomoesaturn what an exciting notification to receive! Thanks for sharing. Looks like it works.
My intuition would be to use ${FAST_THEME_NAME}alias
not ${FAST_THEME_NAME}command
. If you considered that, what made you choose ${FAST_THEME_NAME}command
?
How hard do you think it would be to support multi-word abbreviations? Is that possible with F-Sy-H?
@olets
My intuition would be to use
${FAST_THEME_NAME}alias
not${FAST_THEME_NAME}command
. If you considered that, what made you choose${FAST_THEME_NAME}command
?
Oops, I didn't care about highlight color. I agree with you to use ${FAST_THEME_NAME}alias
!
How hard do you think it would be to support multi-word abbreviations? Is that possible with F-Sy-H?
In my opinion, it would be slightly difficult because F-Sy-H chroma function seems to be triggered by a single word. To support multi-word abbreviations, we need to create a chroma function for the first word only, and then the second and subsequent words should be treated like arguments of the first word.
I think therefore that it can be implemented roughly in the following flow.
eval
or somethingSounds tricky enough that it's not worth letting multi-word highlighting be a blocker for documenting single-word highlighting. For now, let's put single-word out into the world.
If you're interested in contributing to the documentation, please open a PR for https://zsh-abbr.olets.dev/advanced.html#syntax-highlighting. To speed up any PR back-and-forth, I'm picturing something like
#### fast-syntax-highlighting
[fast-syntax-highlighting](https://github.com/zdharma/fast-syntax-highlighting) users…
…
Want highlighting for multi-word aliases? See [zsh-abbr#24](https://github.com/olets/zsh-abbr/issues/24).
#### zsh-syntax-highlighting
<existing zsh-syntax-highlighting docs>
If you're not interested in making the change, lmk and I'll make an update!
@olets Thanks! I'll try to contribute to the documentation!
@shimajiteppei would you like to be added as a contributor in the GitHub readme and https://zsh-abbr.olets.dev/community/ * ?
* the docs site's GitHub-hosted images don't always load on the first try
@olets Thank you for your offer. I would be happy to be added.
@all-contributors please add @shimajiteppei for code and doc
@olets
I've put up a pull request to add @shimajiteppei! :tada:
I've opened #120 to track multi-word abbreviations. Closing
Would be nice to support fast-syntax-highlighting.
Its chroma docs are here.