Function: ghostel--redraw-now

ghostel--redraw-now is a natively compiled function defined in ghostel.el.

Signature

(ghostel--redraw-now BUFFER &optional FORCE)

Documentation

Attempt to redraw BUFFER and retain the request until it succeeds.

The renderer preserves buffer positions while applying terminal mutations; this function anchors windows that were following the live viewport.

With FORCE non-nil, redraw even while synchronized output (mode 2026) is open. Normal redraws remain pending when the native renderer declines them during synchronized output or when BUFFER has no render window.

Source Code

;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel.el
(defun ghostel--redraw-now (buffer &optional force)
  "Attempt to redraw BUFFER and retain the request until it succeeds.
The renderer preserves buffer positions while applying terminal mutations;
this function anchors windows that were following the live viewport.

With FORCE non-nil, redraw even while synchronized output (mode 2026)
is open.  Normal redraws remain pending when the native renderer declines
them during synchronized output or when BUFFER has no render window."
  (when (buffer-live-p buffer)
    (with-current-buffer buffer
      (setq ghostel--pending-redraw t)
      (when force (setq ghostel--force-next-redraw t))
      (when ghostel--redraw-timer
        (cancel-timer ghostel--redraw-timer)
        (setq ghostel--redraw-timer nil))
      (when (and ghostel--term
                 (ghostel--terminal-live-p)
                 (not (ghostel--maybe-defer-redraw buffer)))
        (when-let* ((render-win (ghostel--get-render-window buffer)))
          ;; Pause line mode if alt-screen just turned on.  This must run
          ;; before the snapshot so a pause can take ownership of its input.
          (ghostel--line-mode-pre-redraw)
          (let* ((anchored (ghostel--anchored-windows buffer t))
                 ;; Line-mode input is not part of libghostty's grid.  Remove
                 ;; it while native rendering runs, then restore it after
                 ;; rendering.
                 (line-snapshot (and (eq ghostel--input-mode 'line)
                                     (ghostel--line-mode-snapshot)))
                 (inhibit-read-only t)
                 (inhibit-redisplay t)
                 (inhibit-modification-hooks t)
                 (gc-cons-threshold most-positive-fixnum)
                 (rendered
                  (with-selected-window render-win
                    ;; FULL and FORCE-SYNC are separate native policies.
                    (ghostel--redraw ghostel--term
                                     (eq ghostel--input-mode 'line)
                                     ghostel--force-next-redraw))))
            (when rendered
              (setq ghostel--pending-redraw nil
                    ghostel--force-next-redraw nil))
            (ghostel--apply-cursor-style)
            ;; FOLLOWING=t: the render advanced the cursor while preserving
            ;; window-point, so the pre-render snapshot carries the Emacs-mode
            ;; follow decision.
            (dolist (win anchored) (ghostel--anchor-window win nil t))
            (let ((line-restored
                   (and line-snapshot
                        (ghostel--line-mode-restore line-snapshot))))
              ;; Restore failed because the prompt moved or disappeared;
              ;; forward the saved input rather than silently losing it.
              (when (and line-snapshot (not line-restored))
                (let ((input (plist-get line-snapshot :input)))
                  (when (and input (> (length input) 0))
                    (ghostel--write-pty ghostel--term input)
                    (message
                     "ghostel: line-mode prompt lost; input forwarded raw"))))
              (when rendered (ghostel--deactivate-repainted-region))
              (ghostel--schedule-link-detection))
            ;; Resume line mode if alt-screen just turned off, and update the
            ;; alt-screen-prev cache for the next cycle.
            (ghostel--line-mode-post-redraw)
            (ghostel--detect-password-prompt)))))))