-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
main-highlighter can be run as command, with profiling equipped #371
base: master
Are you sure you want to change the base?
Conversation
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 good. Other than moving to tools/, the rest is a large number of trivial changes. Looking forward to the second iteration.
|
||
# Strive for -f | ||
# .. occuring problems (no q flag), but at least try to quote $0 and $@ | ||
[[ -z "$ZSH_VERSION" ]] && exec /usr/bin/env zsh -f -c "source \"$0\" \"$1\" \"$2\" \"$3\"" |
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.
sh scripts can't use [[
; change it to [
.
|
||
# Strive for -f | ||
# .. occuring problems (no q flag), but at least try to quote $0 and $@ | ||
[[ -z "$ZSH_VERSION" ]] && exec /usr/bin/env zsh -f -c "source \"$0\" \"$1\" \"$2\" \"$3\"" |
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.
About quoting: /usr/bin/env zsh -fc 'source "$@"' - "$0" "$@"
should do the trick.
[[ -z "$ZSH_VERSION" ]] && exec /usr/bin/env zsh -f -c "source \"$0\" \"$1\" \"$2\" \"$3\"" | ||
|
||
ZERO="${(%):-%N}" | ||
ZERO_RESOLVED="${ZERO:A:h}" |
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.
You don't actually need $ZERO_RESOLVED; it'd be fine to replace all uses with $ZERO.
Yes, I know I said ${0:A:h}
originally. I think I mislead you; sorry for that.
|
||
_zsh_highlight_highlighter_main_paint | ||
|
||
print -u2 "Main highlighter's running time: $SECONDS" |
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.
I'd rather send this to stdout, since it's not an error. Perhaps make it a # comment
to ease parsing?
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.
A quick reply: this allows to redirect region_highlight output to a file, and have running time on terminal
typeset -F SECONDS | ||
SECONDS=0 | ||
|
||
_zsh_highlight_highlighter_main_paint |
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.
The code is in no way specific to the main
highlighter; I think it would be better suited in tools/ and taking a highlighter name as an argument. WDYT?
Like the existing test scripts, I think this script would benefit from the stub _zsh_highlight_add_highlight
implementation used by various files in tests/. (It'd cause the output to print style names rather than color settings derived from them.)
print -u2 "Usage: ./mh-parse.zsh {to-parse file}" | ||
exit 1 | ||
else | ||
print -u2 "Unreadable to-parse file \`$1', aborting" |
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.
Two minor issues:
- Prefix $0 to the error message.
- Use ${(qq)1} to escape the filename.
print -rl -- "${region_highlight[@]}" | ||
else | ||
if [[ -z "$1" ]]; then | ||
print -u2 "Usage: ./mh-parse.zsh {to-parse file}" |
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.
I'd rather the argument read {file to parse}
; I think that scans better in English.
typeset -F SECONDS | ||
SECONDS=0 | ||
|
||
_zsh_highlight_highlighter_main_paint |
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.
Don't you need to setopt interactivecomments
here, so that any comments in the file would be highlighted correctly?
(Closing/reopening to trigger continuous integration) |
Following up to #314 (I've once pruned Z-SY-H fork when cleaning up my repositories, so have to start a new PR).
$0
and also%N
[[ -r "$1" ]]
mh-parse.zsh
as it can serve for possible problem-investigation instructions at user's machine.