zsh-users
 help / color / mirror / code / Atom feed
* Extend/Modify/Reuse/Augment existing completion functions
@ 2015-04-06 19:14 Jochen Keil
  2015-04-06 23:56 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Jochen Keil @ 2015-04-06 19:14 UTC (permalink / raw)
  To: zsh-users

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

Hello,

I tried to partially override the current git completion for `git commit
--fixup`. My simplistic approach was to create a `_git-commit` file in
my $fpath (before the system path) and then copy the `_git-commit`
function from `Completion/Unix/Command/_git`.

After that I added my own function to generate the completions to `--fixup`:

> __git_commit_tags () {
>   commits=("${(@f)$(git log --pretty=format:'%h:%s')}")
>   _describe 'commits' commits
> }
>
> ..
>     '--fixup=[construct a commit message for use with rebase
--autosquash]:fixup commit:__git_commit_tags' \
> ..

What I don't like is the code duplication. Can I somehow just add my own
completion function for `git commit --fixup` without copying over the
whole thing?

In addition, I've seen that the dev branch already has completion
support for `--fixup`. In case I don't like it when it hits the next
release, is there a way to override just this specific completion?

Thank you very much,

  Jochen


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

* Re: Extend/Modify/Reuse/Augment existing completion functions
  2015-04-06 19:14 Extend/Modify/Reuse/Augment existing completion functions Jochen Keil
@ 2015-04-06 23:56 ` Bart Schaefer
  2015-04-09 11:31   ` Jochen Keil
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2015-04-06 23:56 UTC (permalink / raw)
  To: zsh-users

On Apr 6,  9:14pm, Jochen Keil wrote:
}
} Can I somehow just add my own completion function for
} `git commit --fixup` without copying over the whole thing?

Something like the following should work:

Create a file named _git and place it in a directory that appears early
enough in your $fpath that your _git will be autoloaded before the one
supplied with zsh.  That file contains

#--- 8< ---
local -a gitpaths
gitpaths=( $^fpath/_git(N) )
source $gitpaths[2] || return

# Now we've loaded _git, override a function therein
__git_commit_tags () {
  commits=("${(@f)$(git log --pretty=format:'%h:%s')}")
  _describe 'commits' commits
}

_git "$@"
#--- 8< ---

If you need to add/replace an argument in one of the embedded _arguments
calls, you'll likely have to duplicate and override the whole function
that makes that particular call; you can do some source-editing tricks
using the $functions parameter from the zsh/parameter module, but it'd
be a bit ugly.


} In addition, I've seen that the dev branch already has completion
} support for `--fixup`. In case I don't like it when it hits the next
} release, is there a way to override just this specific completion?

You can substitute in pretty much anything by using the "completer"
zstyle; just put your completer first in the list, and make sure it
returns nonzero any time it wants the "regular" completers such as
_complete to take over.


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

* Re: Re: Extend/Modify/Reuse/Augment existing completion functions
  2015-04-06 23:56 ` Bart Schaefer
@ 2015-04-09 11:31   ` Jochen Keil
  0 siblings, 0 replies; 3+ messages in thread
From: Jochen Keil @ 2015-04-09 11:31 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

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

Hello Bart,

On 07.04.2015 01:56, Bart Schaefer wrote:
> On Apr 6,  9:14pm, Jochen Keil wrote:
> }
> } Can I somehow just add my own completion function for
> } `git commit --fixup` without copying over the whole thing?
> 
> Something like the following should work:
> 
> Create a file named _git and place it in a directory that appears early
> enough in your $fpath that your _git will be autoloaded before the one
> supplied with zsh.  That file contains
> 
> #--- 8< ---
> local -a gitpaths
> gitpaths=( $^fpath/_git(N) )
> source $gitpaths[2] || return
> 
> # Now we've loaded _git, override a function therein
> __git_commit_tags () {
>   commits=("${(@f)$(git log --pretty=format:'%h:%s')}")
>   _describe 'commits' commits
> }
> 
> _git "$@"
> #--- 8< ---

Unfortunately this doesn't work for me, it leaves me with no git
completion at all. Sorry if it wasn't clear enough, but
`__git_commit_tags` is my own function, the default `_argument` call has
no function at all. Additionally, I had the impression that `source`-ing
completion scripts is not a best practice?

> If you need to add/replace an argument in one of the embedded _arguments
> calls, you'll likely have to duplicate and override the whole function
> that makes that particular call; you can do some source-editing tricks
> using the $functions parameter from the zsh/parameter module, but it'd
> be a bit ugly.

That's what I'm doing right now, I've duplicated the function and
replaced/extending the `_argument` call. Works fine, apart from the code
duplication, so I'm probably going to stick to it.

> } In addition, I've seen that the dev branch already has completion
> } support for `--fixup`. In case I don't like it when it hits the next
> } release, is there a way to override just this specific completion?
> 
> You can substitute in pretty much anything by using the "completer"
> zstyle; just put your completer first in the list, and make sure it
> returns nonzero any time it wants the "regular" completers such as
> _complete to take over.

Thanks, I will try that out as soon as the default completer comes with
a function for completing `git commit --fixup`.

Thank you very much and all the best,

  Jochen



[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 181 bytes --]

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

end of thread, other threads:[~2015-04-09 11:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-06 19:14 Extend/Modify/Reuse/Augment existing completion functions Jochen Keil
2015-04-06 23:56 ` Bart Schaefer
2015-04-09 11:31   ` Jochen Keil

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).