Skip to content

Commit

Permalink
rc tools ctags/man: rationalize sorting of completion candidates
Browse files Browse the repository at this point in the history
As of recently, shell script candidate completions are computed in
the background, and displayed incrementally.
Sorting completions means we can't show partial results.

We do this for "ctags-search"; but if there is only one ctags file
there is already a sensible order (which is slightly different than
what GNU sort does). So let's preserve the order in that case.
The number of completions is probably too high for an order to be useful.

Similarly, for "man", sorting is probably not very helpful because
there are so many results.

See mawww#5035 (comment)
  • Loading branch information
krobelus authored and Evan Johnson committed Jan 25, 2024
1 parent 9b35c88 commit 7690a7c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
14 changes: 10 additions & 4 deletions rc/tools/ctags.kak
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,22 @@ define-command -params ..1 \
-shell-script-candidates %{
realpath() { ( cd "$(dirname "$1")"; printf "%s/%s\n" "$(pwd -P)" "$(basename "$1")" ) }
eval "set -- $kak_quoted_opt_ctagsfiles"
for candidate in "$@"; do
[ -f "$candidate" ] && realpath "$candidate"
done | awk '!x[$0]++' | # remove duplicates
files=$(
for candidate in "$@"; do
[ -f "$candidate" ] && realpath "$candidate"
done |
awk '!x[$0]++; # remove duplicates
END { if (length(x) == 1) { exit 1; } }'
)
[ $? -eq 1 ] && sort=cat || sort=sort
printf %s\\n "$files" |
while read -r tags; do
namecache="${tags%/*}/.kak.${tags##*/}.namecache"
if [ -z "$(find "$namecache" -prune -newer "$tags")" ]; then
cut -f 1 "$tags" | grep -v '^!' | uniq > "$namecache"
fi
cat "$namecache"
done | sort } \
done | "$sort" } \
-docstring %{
ctags-search [<symbol>]: jump to a symbol's definition
If no symbol is passed then the current selection is used as symbol name
Expand Down
3 changes: 1 addition & 2 deletions rc/tools/man.kak
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ define-command -params ..1 \
-shell-script-candidates %{
find /usr/share/man/ $(printf %s "${MANPATH}" |
sed 's/:/ /') -name '*.[1-8]*' |
sed 's,^.*/\(.*\)\.\([1-8][a-zA-Z]*\).*$,\1(\2),' |
sort
sed 's,^.*/\(.*\)\.\([1-8][a-zA-Z]*\).*$,\1(\2),'
} \
-docstring %{
man [<page>]: manpage viewer wrapper
Expand Down

0 comments on commit 7690a7c

Please sign in to comment.