Function: shell-command-set-point-after-cmd

shell-command-set-point-after-cmd is a byte-compiled function defined in simple.el.gz.

Signature

(shell-command-set-point-after-cmd &optional BUFFER)

Documentation

Set point in BUFFER after command complete.

BUFFER is the output buffer of the command; if nil, then defaults to the current BUFFER. Set point to the cdr of the element in shell-command-saved-pos whose car is BUFFER.

Probably introduced at or before Emacs version 27.1.

Source Code

;; Defined in /usr/src/emacs/lisp/simple.el.gz
(defun shell-command-set-point-after-cmd (&optional buffer)
  "Set point in BUFFER after command complete.
BUFFER is the output buffer of the command; if nil, then defaults
to the current BUFFER.
Set point to the `cdr' of the element in `shell-command-saved-pos'
whose `car' is BUFFER."
  (when shell-command-dont-erase-buffer
    (let* ((sym  shell-command-dont-erase-buffer)
           (buf  (or buffer (current-buffer)))
           (pos  (alist-get buf shell-command-saved-pos)))
      (setq shell-command-saved-pos
            (assq-delete-all buf shell-command-saved-pos))
      (when (buffer-live-p buf)
        (let ((win   (car (get-buffer-window-list buf)))
              (pmax  (with-current-buffer buf (point-max))))

          ;; The first time we run a command in a freshly created buffer
          ;; we have not saved positions yet; advance to `point-max', so that
          ;; successive commands know where to start.
          (unless (and pos (memq sym '(save-point beg-last-out end-last-out)))
            (setq pos pmax))
          ;; Set point in the window displaying buf, if any; otherwise
          ;; display buf temporary in selected frame and set the point.
          (if win
              (set-window-point win pos)
            (when pos
              (with-current-buffer buf (goto-char pos)))
            (save-window-excursion
              (let ((win (display-buffer
                          buf
                          '(nil (inhibit-switch-frame . t)))))
                (set-window-point win pos)))))))))