Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

psprint
Copy link
Contributor

@psprint psprint commented Sep 25, 2016

Following up to #314 (I've once pruned Z-SY-H fork when cleaning up my repositories, so have to start a new PR).

  1. Addressed this, #!/bin/sh is the shebang, zsh -f is being run
  2. Using $0 and also %N
  3. Doing [[ -r "$1" ]]
  4. I opt for shipping mh-parse.zsh as it can serve for possible problem-investigation instructions at user's machine.

Copy link
Member

@danielshahaf danielshahaf left a 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\""
Copy link
Member

@danielshahaf danielshahaf Sep 25, 2016

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\""
Copy link
Member

@danielshahaf danielshahaf Sep 25, 2016

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}"
Copy link
Member

@danielshahaf danielshahaf Sep 25, 2016

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"
Copy link
Member

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?

Copy link
Contributor Author

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
Copy link
Member

@danielshahaf danielshahaf Sep 25, 2016

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"
Copy link
Member

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}"
Copy link
Member

@danielshahaf danielshahaf Sep 25, 2016

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
Copy link
Member

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?

@nicoulaj
Copy link
Member

(Closing/reopening to trigger continuous integration)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants