-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/sh | ||
|
||
# | ||
# This file runs main highlighter on a specified file | ||
# i.e. parses the file with the highlighter. Outputs | ||
# running time (stderr) and resulting region_highlight | ||
# (stdout). | ||
# | ||
|
||
# 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 commentThe reason will be displayed to describe this comment to others. Learn more. About quoting: |
||
|
||
ZERO="${(%):-%N}" | ||
ZERO_RESOLVED="${ZERO:A:h}" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
# | ||
# Load Z-SY-H | ||
# | ||
|
||
if [[ -e "${ZERO_RESOLVED}/main-highlighter.zsh" ]]; then | ||
source "${ZERO_RESOLVED}/../../zsh-syntax-highlighting.zsh" | ||
elif [[ -e "${0:A:h}/main-highlighter.zsh" ]]; then | ||
source "${0:A:h}/../../zsh-syntax-highlighting.zsh" | ||
elif [[ -e "../../main-highlighter.zsh" ]]; then | ||
source "../../zsh-syntax-highlighting.zsh" | ||
else | ||
print "Could not find zsh-syntax-highlighting.zsh, aborting" | ||
exit 1 | ||
fi | ||
|
||
# | ||
# Call _zsh_highlight_highlighter_main_paint | ||
# | ||
|
||
if [[ -r "$1" ]]; then | ||
# Load from given file | ||
PREBUFFER="" | ||
BUFFER="$(<$1)" | ||
|
||
typeset -F SECONDS | ||
SECONDS=0 | ||
|
||
_zsh_highlight_highlighter_main_paint | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code is in no way specific to the Like the existing test scripts, I think this script would benefit from the stub There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't you need to |
||
|
||
print -u2 "Main highlighter's running time: $SECONDS" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
# This output can be diffed to detect changes in operation | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I'd rather the argument read |
||
exit 1 | ||
else | ||
print -u2 "Unreadable to-parse file \`$1', aborting" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two minor issues:
|
||
exit 2 | ||
fi | ||
fi | ||
|
||
exit 0 | ||
|
||
# vim:ft=zsh |
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[
.