Skip to content

History navigation: restore the in-progress prompt #592

@alberti42

Description

@alberti42

There is something that has always bugged me which can be potentially fixed in a few lines. I wanted to share it with you.

Problem

I type a long prompt; maybe I spend 3 minutes crafting it, and then I want to move a few paragraphs up (e.g., I use an agent to write prose and ask it to improve my text). I often end up typing C-up and C-down arrows because of muscle memory. This has unpleasant consequences because, as the prompt rolls to the previous one, I am no longer able to recover the prompt I was writing. Rolling back to a previous prompt is a great feature to have—sometimes it is precisely what I need. However, I often want to be able to roll back to the prompt I am composing. Currently, this is not possible. The prompt I was typing is gone, and I need to type it again—something frustrating.

Solution

Comint already has a solution, and agent-shell makes use of it, but the input that gets stashed is truncated because shell-maker overrides comint-get-old-input with a forward-sexp-based grabber. For prose, like when prompting an agent, the truncation implemented by shell-maker is the wrong behavior. The fix is just two/three lines. While it perfectly works for me with a hook, I thought you may want to share this fix with all your users by integrating something like this directly into upstream:

  ;; History navigation: preserve the full in-progress prompt.  shell-maker sets
  ;; `comint-get-old-input' to a function that grabs a single `forward-sexp', so
  ;; multi-word/multi-line prompts are truncated when comint stashes them on the
  ;; first C-up.  Override to capture the entire input region; comint's built-in
  ;; `comint-restore-input' then brings the full text back when C-down
  ;; overshoots the newest history entry.
  (defun my/agent-shell-get-old-input ()
    "Return the entire pending input from process-mark to point-max."
    (when-let ((proc (get-buffer-process (current-buffer))))
      (buffer-substring-no-properties (process-mark proc) (point-max))))
  (add-hook 'agent-shell-mode-hook
            (lambda ()
              (setq-local comint-get-old-input
                          #'my/agent-shell-get-old-input)))

If you like, I can open a PR with a suggestion so that we can discuss the concrete implementation in the code. Or perhaps you prefer to implement the few lines of code above, which essentially fix comint-get-old-input (already used in agent-shell).

Checklist

  • I agree to communicate with the author myself (not AI-generated).
  • I've read the README's Filing issues section.
  • I'm running the latest versions (fill in below).
  • Emacs: GNU Emacs 31.0.60
  • agent-shell: 67babec (2026-05-16, merge of Add Hermes Agent Support  #583)
  • acp.el: 03099fa (2026-05-03, merge of Add support for devcontainer #18)
  • ACP package: OpenCode adapter (agent-shell-opencode.el, bundled with agent-shell)
  • Agent CLI: opencode 0.0.0-integrated-202605150926 (personal fork with --attach support; see config below)
  • For requesting new agent support, I'm including a link to the ACP-capable agent or related ACP package.
  • For issues, I'm including ACP traffic (as per README).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions