zsh-users
 help / color / mirror / code / Atom feed
* gen-hg-bookmark-string hook in vcs_info is not very helpful
@ 2017-09-22 18:33 yegle
  2017-09-24 11:34 ` Daniel Shahaf
  0 siblings, 1 reply; 2+ messages in thread
From: yegle @ 2017-09-22 18:33 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1876 bytes --]

Hi list,

I'm trying to highlight the current bookmark in a hg repo with some color.
It looks like gen-hg-bookmark-string is the way to go, but I find it
impossible to do what I plan to do.

Specifically, the issue with these lines:
https://github.com/zsh-users/zsh/blob/master/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg#L140-L142

    if VCS_INFO_hook 'gen-hg-bookmark-string' "${hgbmarks[@]}"; then
        # If there is an active bookmark, annotate it and put it first.
        if [[ -n $curbm ]] ; then
            hgbmarks[(i)$curbm]=()
            hgbmarks[1,0]="${curbm}*"
        fi
        hgbmstring=${(j:, :)hgbmarks}
        # Deannotate the array, in case later code expects it to be valid.
        # (The order is not restored.)
        [[ -n $curbm ]] && hgbmarks[1]=${${hgbmarks[1]}[1,-2]}
    else
        hgbmstring=${hook_com[hg-bookmark-string]}
    fi

Because the existing code append $curbm with *, it seems like I can just
modify curbm in my hook to add color escape string. But note the line
`hgbmarks[(i)$curbm]=()`: if you modify $curbm in any way, the result
string will have duplicate bookmarks: one that I modified with color escape
string, one that was failed to remove from the array.

Another option, of course, is to make the change and then unset $curbm at
the end, but this is really a hack:

function +vi-hg-highlight-curbm {

    if [[ -n $curbm ]] ; then

        hgbmarks[(i)$curbm]=()

        hgbmarks[1,0]="%{$fg_bold[red]%}${curbm}%{$reset_color%}*"

        curbm=""

    fi

}

I think a very simple fix for this issue is to modify the line to:

hgbmarks[1,0]="${hook_com[hg-active-bookmark]}*"

Can anyone propose a patch to fix this issue and make
gen-hg-bookmark-string more useful? I would be happy to send a PR if the
repo is hosted on Github or something more user friendly :-(

-- 
Yuchen Ying
https://about.me/yegle

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: gen-hg-bookmark-string hook in vcs_info is not very helpful
  2017-09-22 18:33 gen-hg-bookmark-string hook in vcs_info is not very helpful yegle
@ 2017-09-24 11:34 ` Daniel Shahaf
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Shahaf @ 2017-09-24 11:34 UTC (permalink / raw)
  To: yegle, zsh-users

yegle wrote on Fri, 22 Sep 2017 11:33 -0700:
> Specifically, the issue with these lines:
> https://github.com/zsh-users/zsh/blob/master/Functions/VCS_Info/Backends/VCS_INFO_get_data_hg#L140-L142
> 

(Tangential: <http://www.zsh.org/cgi-bin/mla/redirect?WORKERNUMBER=37966>)

>     if VCS_INFO_hook 'gen-hg-bookmark-string' "${hgbmarks[@]}"; then
>         # If there is an active bookmark, annotate it and put it first.
>         if [[ -n $curbm ]] ; then
>             hgbmarks[(i)$curbm]=()
>             hgbmarks[1,0]="${curbm}*"
>         fi
>         hgbmstring=${(j:, :)hgbmarks}
>         # Deannotate the array, in case later code expects it to be valid.
>         # (The order is not restored.)
>         [[ -n $curbm ]] && hgbmarks[1]=${${hgbmarks[1]}[1,-2]}
>     else
>         hgbmstring=${hook_com[hg-bookmark-string]}
>     fi
> 
> Because the existing code append $curbm with *, it seems like I can just
> modify curbm in my hook to add color escape string.

You can't, for two reasons:

1. $curbm is private to VCS_INFO_get_data_hg; it is not part of the API.
The API includes only what's in the manual, e.g., $hook_com and $ret.

2. The codepath you're quoting is the codepath for when there is no
hook.  You have a hook so you _should_ be taking the 'else' branch.  The
reason you don't is that your hook function neglects to set ret=1
before it returns (again, that's documented).

tl;dr: Add "ret=1" in your hook function.

> Can anyone propose a patch to fix this issue and make
> gen-hg-bookmark-string more useful? I would be happy to send a PR if
> the repo is hosted on Github or something more user friendly :-(

For future reference, "save the output of 'git diff' to a *.txt file and
attach it to an email".


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-09-24 11:43 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-22 18:33 gen-hg-bookmark-string hook in vcs_info is not very helpful yegle
2017-09-24 11:34 ` Daniel Shahaf

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).