zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: (maybe) negative ranges
@ 2015-09-30 16:51 Peter Stephenson
  2015-09-30 17:26 ` Mikael Magnusson
  0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2015-09-30 16:51 UTC (permalink / raw)
  To: Zsh Hackers' List

I'd like to be able to ignore ^ at the start of a git range
specification to support things like

  git log r1 ^r2

(which is useful as it saves me having to remember what .. and
... mean and getting infuriated because they mean the opposite for git
diff).

This being zsh, it's not as easy as it should be.  With extendedglob I
need to quote the ^ on the command line, which I'm doing with a
backslash:

  git log r1 \^r<TAB>

In the completion function that gets executed as a result it looks like
$PREFIX still contains the backslash, so I have to deal with quoting
myself and still leave a valid revision to complete in further procesing.

This seems to do what I want, but I may have missed up to N! tricks...

I have no idea how to tweak this to turn

  '^stuff

into the equivalent of having

  'stuff

in the bowels and

  '^stuff

still on the command line, which looks like the only way of
consistently keeping the quotes and still have the completion work.

pws

diff --git a/Completion/Unix/Command/_git b/Completion/Unix/Command/_git
index 40a9fb6..1fcde90 100644
--- a/Completion/Unix/Command/_git
+++ b/Completion/Unix/Command/_git
@@ -5753,7 +5753,14 @@ __git_commit_ranges () {
   if compset -P '*..(.|)'; then
     expl=( $* )
   else
-    compset -S '..*' || suf=( -S .. -r '.@~ ^:\t\n\-' )
+    if ! compset -S '..*'; then
+      local match mbegin mend
+      if [[ ${PREFIX} = (#b)((\\|)\^)* ]]; then
+	compset -p ${#match[1]}
+      else
+	suf=( -S .. -r '.@~ ^:\t\n\-' )
+      fi
+    fi
     expl=( $* $suf )
   fi
 


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

* Re: PATCH: (maybe) negative ranges
  2015-09-30 16:51 PATCH: (maybe) negative ranges Peter Stephenson
@ 2015-09-30 17:26 ` Mikael Magnusson
  0 siblings, 0 replies; 2+ messages in thread
From: Mikael Magnusson @ 2015-09-30 17:26 UTC (permalink / raw)
  To: Peter Stephenson; +Cc: Zsh Hackers' List

On Wed, Sep 30, 2015 at 6:51 PM, Peter Stephenson
<p.stephenson@samsung.com> wrote:
> I'd like to be able to ignore ^ at the start of a git range
> specification to support things like
>
>   git log r1 ^r2

Can't say anything helpful about the completion, but you may find this helpful,

function _self_insert_git() {
  if [[ $BUFFER = (git(-| )|gitk |qgit )* ]]; then
    if [[ ! $LBUFFER[-1] = '\' && $LBUFFER != *\ --\ * ]]; then
      LBUFFER+='\'
    fi
  fi
  zle self-insert
}

zle -N self-insert-git _self_insert_git
bindkey '^' self-insert-git
bindkey -M isearch '^' self-insert

-- 
Mikael Magnusson


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

end of thread, other threads:[~2015-09-30 17:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-09-30 16:51 PATCH: (maybe) negative ranges Peter Stephenson
2015-09-30 17:26 ` Mikael Magnusson

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