Skip to content

Commit

Permalink
feat: whatis recognizes section suffix (zdharma-continuum#45)
Browse files Browse the repository at this point in the history
[F-Sy-H](https://github.com/zdharma-continuum/fast-syntax-highlighting) can recognize and highlight manual subsection suffixes (i.e., `open.2`, `ls.1p`, `printf.3`).

- `man-db` is known to support subsection suffixes
- `mandoc` should not be affected by this commit
  • Loading branch information
memchr authored Mar 10, 2023
1 parent 7c390ee commit 5521b08
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions →chroma/-whatis.ch
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@

(( next_word = 2 | 8192 ))
local THEFD check __first_call="$1" __wrd="$2" __start_pos="$3" __end_pos="$4"
local __style
local __style __term __section __section_flag

# extact manual subsection
# NOTE: __term should be separated from __wrd to prevent incorrect cache hits
if command -v mandb > /dev/null; then
__term="${__wrd%.[0-8n](|p|type|const|head|perl)}"
__section="${${2#$__term}#.}"
else
__term=$__wrd
fi

[[ -n $__section ]] && __section_flag="-s $__section"

(( ! ${+FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]} )) && \
FAST_HIGHLIGHT[whatis_chroma_callback_was_ran]=0
Expand Down Expand Up @@ -97,7 +108,7 @@ else
print "$__wrd"
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER} ))
print "$__start/$__end"
LANG=C whatis "$__wrd" 2>/dev/null
LANG=C whatis "${(z)__section_flag}" "$__term" 2>/dev/null
)
command true # see above
zle -F ${${FAST_HIGHLIGHT[whatis_chroma_zle_-F_have_-w_opt]:#0}:+-w} "$THEFD" -fast-whatis-chroma-callback
Expand All @@ -107,7 +118,7 @@ else
print "$__wrd"
(( __start=__start_pos-${#PREBUFFER}, __end=__end_pos-${#PREBUFFER} ))
print "$__start/$__end"
LANG=C whatis "$__wrd" &> /dev/null
LANG=C whatis "${(z)__section_flag}" "$__term" &> /dev/null
print "$?"
)
command true
Expand Down

0 comments on commit 5521b08

Please sign in to comment.