From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9161 invoked from network); 5 Oct 2008 13:41:06 -0000 X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=AWL,BAYES_00 autolearn=ham version=3.2.5 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 5 Oct 2008 13:41:06 -0000 Received-SPF: none (ns1.primenet.com.au: domain at sunsite.dk does not designate permitted sender hosts) Received: (qmail 32788 invoked from network); 5 Oct 2008 13:40:44 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 5 Oct 2008 13:40:44 -0000 Received: (qmail 7443 invoked by alias); 5 Oct 2008 13:40:33 -0000 Mailing-List: contact zsh-workers-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 25810 Received: (qmail 7421 invoked from network); 5 Oct 2008 13:40:32 -0000 Received: from bifrost.dotsrc.org (130.225.254.106) by sunsite.dk with SMTP; 5 Oct 2008 13:40:32 -0000 Received: from ik-out-1112.google.com (ik-out-1112.google.com [66.249.90.178]) by bifrost.dotsrc.org (Postfix) with ESMTP id 987F480308BF for ; Sun, 5 Oct 2008 15:40:17 +0200 (CEST) Received: by ik-out-1112.google.com with SMTP id c30so1452647ika.5 for ; Sun, 05 Oct 2008 06:40:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=qObgvFRQa43nQg3HnE/9jVszixHlzlVU0vqJWCcplq4=; b=hmFix0JIVv2iYqPkGB8oVmBms5yGR9mWxui7gGzkq2jq/G87vjmj5BBYO8k+onVLTE 6uMhi3GafrLIPv35aNTzX6pMhNNsE8LhwDyVd09+/R+yxB6IIVo6YFy0+fcXHIFK5afb 2c5/xV2CSxE6BW72ZUwIROUxthC4H0Bf6MmO8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=Dcy/dZOPwbEBlZWrq2BtyI8OId9NWYrFk90U26eAYmgyLOxnVLe60lj3wry4xvn4zj jjD0KMdID4KmJwZMpeLQqMma614/3LH/xUTzPTQ7uCx1LB051LxFeprv9+DqhOHRo8+2 LI/tRpQI5ZfFuIMRMez5FkUdI1FVYZ13bE/GE= Received: by 10.210.66.1 with SMTP id o1mr4672700eba.42.1223214017355; Sun, 05 Oct 2008 06:40:17 -0700 (PDT) Received: by 10.210.19.20 with HTTP; Sun, 5 Oct 2008 06:40:17 -0700 (PDT) Message-ID: <237967ef0810050640n7c536bafl9255e870f83d15f8@mail.gmail.com> Date: Sun, 5 Oct 2008 15:40:17 +0200 From: "Mikael Magnusson" To: zsh-workers Subject: [rfc + bad patch] Allow to get the current cursor command from zle, for doing a nicer run-help. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: ClamAV 0.92.1/8374/Sat Oct 4 19:41:34 2008 on bifrost X-Virus-Status: Clean (the patch will be badly linebroken likely, but it's just for illustration). Let's say you have the command line git add -u; git commit - # hmm, was it -m or -M for message? *press alt-h* Now, also assume you have the run-help-git stuff set up, but it will still show you the manpage for git-add instead of git-commit. Since the run-help widget does a push-line, we can't use $CURSOR to find out which is the actual command, this is how i solved it. function _runhelp() { local lookup if [[ "$CURSORCOMMAND" = git ]]; then # tiny bug here, want CURSOR+1 so you get the right result when on the # first letter, but then it breaks when at the end of the line which is # the far more common case. lookup=git-${${(z)BUFFER[(b:CURSOR:R)$CURSORCOMMAND,-1]}[2]} else lookup=$CURSORCOMMAND fi _runcmdhidden man $lookup } function _runcmdhidden() { "$@" >& /dev/null < /dev/null &| } function man () { urxvt +sb +ip -e pinfo -m "$@" &|: } (this can of course be made to do a push-line manually and open in man in the same terminal as usual, but I like the new window.) diff --git a/Src/Zle/zle_params.c b/Src/Zle/zle_params.c index efa6286..ae5271a 100644 --- a/Src/Zle/zle_params.c +++ b/Src/Zle/zle_params.c @@ -48,6 +48,8 @@ static const struct gsu_scalar buffer_gsu = { get_buffer, set_buffer, zleunsetfn }; static const struct gsu_scalar context_gsu = { get_context, nullstrsetfn, zleunsetfn }; +static const struct gsu_scalar cursor_command_gsu = +{ getcurcmd, nullstrsetfn, zleunsetfn }; static const struct gsu_scalar cutbuffer_gsu = { get_cutbuffer, set_cutbuffer, unset_cutbuffer }; static const struct gsu_scalar keymap_gsu = @@ -106,6 +108,7 @@ static struct zleparam { { "BUFFER", PM_SCALAR, GSU(buffer_gsu), NULL }, { "BUFFERLINES", PM_INTEGER | PM_READONLY, GSU(bufferlines_gsu), NULL }, + { "CURSORCOMMAND", PM_SCALAR | PM_READONLY, GSU(cursor_command_gsu), NULL }, { "CONTEXT", PM_SCALAR | PM_READONLY, GSU(context_gsu), NULL }, { "CURSOR", PM_INTEGER, GSU(cursor_gsu), diff --git a/Src/Zle/zle_tricky.c b/Src/Zle/zle_tricky.c index bc01524..6c57842 100644 --- a/Src/Zle/zle_tricky.c +++ b/Src/Zle/zle_tricky.c @@ -2757,7 +2757,7 @@ expandhistory(UNUSED(char **args)) static int cmdwb, cmdwe; /**/ -static char * +char * getcurcmd(void) { int curlincmd; -- Mikael Magnusson