zsh-workers
 help / color / mirror / code / Atom feed
From: Mikael Magnusson <mikachu@gmail.com>
To: Bart Schaefer <schaefer@brasslantern.com>
Cc: Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: %! prompt code shows incorrect number
Date: Fri, 21 May 2021 20:58:39 +0200	[thread overview]
Message-ID: <CAHYJk3Rb+dE94zB6yAhP8n9EZ5b2ms5W2=1y9r2ZYenPGDiDLA@mail.gmail.com> (raw)
In-Reply-To: <CAH+w=7azOR7dnsFYVDAHq7kXjKi0AvuZZ1yS13MB-0Cgh3yFrA@mail.gmail.com>

On 5/17/21, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Sun, May 16, 2021 at 9:49 PM Mikael Magnusson <mikachu@gmail.com> wrote:
>>
>> Perhaps we could import events as numbers that are unused instead of
>> overriding the number we have told the user is going to be used for
>> the command they run?
>
> Then the events would be out of order, which sort of ruins the
> "incremental" part.
>
> I don't think there's any simple fix here.  Possibly reprint the
> prompt at (approximately) preexec time to show the correct number?

I've gone with the below hack for now. What I want to be able to do is
copy the history number from the prompt and paste it back into the
terminal, and have my paste handler grab the corresponding entry from
$history and paste it into the prompt for me. With the hack I can
simply add "l" to this query and it seems to work as I want... I'm not
submitting this for inclusion, just as is.

I don't think there's any existing way to check if a history entry is
external other than parsing the * out of fc -l output?

diff --git a/Src/Modules/parameter.c b/Src/Modules/parameter.c
index ef9148d7b6..6c73daf557 100644
--- a/Src/Modules/parameter.c
+++ b/Src/Modules/parameter.c
@@ -1158,6 +1158,7 @@ getpmhistory(UNUSED(HashTable ht), const char *name)
     Histent he;
     const char *p;
     int ok = 1;
+    int local = 0;

     pm = (Param) hcalloc(sizeof(struct param));
     pm->node.nam = dupstring(name);
@@ -1169,13 +1170,18 @@ getpmhistory(UNUSED(HashTable ht), const char *name)
 	    ok = 0;
 	else {
 	    for (p = name; *p && idigit(*p); p++);
-	    if (*p)
+	    if (p[0] == 'l' && !p[1])
+		local = 1;
+	    else if (*p)
 		ok = 0;
 	}
     }
-    if (ok && (he = quietgethist(atoi(name))))
+    if (ok && (he = quietgethist(atoi(name)))) {
+	if (local && (he->node.flags & HIST_FOREIGN)) {
+	    while ((he = down_histent(he)) && (he->node.flags & HIST_FOREIGN));
+	}
 	pm->u.str = dupstring(he->node.nam);
-    else {
+    } else {
 	pm->u.str = dupstring("");
 	pm->node.flags |= (PM_UNSET|PM_SPECIAL);
     }


-- 
Mikael Magnusson


  reply	other threads:[~2021-05-21 18:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-17  4:48 Mikael Magnusson
2021-05-17  5:05 ` Bart Schaefer
2021-05-21 18:58   ` Mikael Magnusson [this message]
2021-05-21 23:55     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHYJk3Rb+dE94zB6yAhP8n9EZ5b2ms5W2=1y9r2ZYenPGDiDLA@mail.gmail.com' \
    --to=mikachu@gmail.com \
    --cc=schaefer@brasslantern.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).