Function: ghostel--line-mode-snapshot

ghostel--line-mode-snapshot is a natively compiled function defined in ghostel-line-mode.el.

Signature

(ghostel--line-mode-snapshot)

Documentation

Capture in-progress input plus point/mark offsets and clear the input region.

Returns a plist (:input STR :point-offset N-or-nil :mark-offset N-or-nil) suitable for ghostel--line-mode-restore, or nil when there is no live input marker. The input region is bounded by ghostel--line-input-start and ghostel--line-input-end (not point-max) so any content drawn past the input — e.g. a status bar below the prompt — stays untouched.

Source Code

;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel-line-mode.el
(defun ghostel--line-mode-snapshot ()
  "Capture in-progress input plus point/mark offsets and clear the input region.
Returns a plist (:input STR :point-offset N-or-nil :mark-offset N-or-nil)
suitable for `ghostel--line-mode-restore', or nil when there is no
live input marker.  The input region is bounded by
`ghostel--line-input-start' and `ghostel--line-input-end' (not
`point-max') so any content drawn past the input — e.g. a status
bar below the prompt — stays untouched."
  (let ((start-pos (and (markerp ghostel--line-input-start)
                        (marker-position ghostel--line-input-start)))
        (end-pos (and (markerp ghostel--line-input-end)
                      (marker-position ghostel--line-input-end))))
    (when (and start-pos end-pos)
      (let* ((point-offset (and (>= (point) start-pos)
                                (<= (point) end-pos)
                                (- (point) start-pos)))
             (mark-pos (and mark-active (mark)))
             (mark-offset (and mark-pos
                               (>= mark-pos start-pos)
                               (<= mark-pos end-pos)
                               (- mark-pos start-pos)))
             (input (buffer-substring-no-properties start-pos end-pos)))
        ;; Disarm undo for the rest of the redraw pass: this delete, the
        ;; native redraw, and the re-insert in `ghostel--line-mode-restore'
        ;; are renderer bookkeeping, not user edits.  `restore' re-arms.
        (setq buffer-undo-list t)
        (let ((inhibit-read-only t))
          (delete-region start-pos end-pos))
        (list :input input
              :point-offset point-offset
              :mark-offset mark-offset)))))