Function: ghostel--imenu-create-index
ghostel--imenu-create-index is a natively compiled function defined in
ghostel-shell.el.
Signature
(ghostel--imenu-create-index)
Documentation
Build an imenu alist of OSC 133 prompts in the current buffer.
Each entry's label is "<cwd> <command>"; cwd is omitted when no
recorded entry aligns with the region (e.g. a still-active prompt
whose 'C' has not fired). Empty-command prompts are
skipped. Labels are truncated to 80 columns.
Source Code
;; Defined in /nix/store/1252krff0gb2kisjcpp45m50cpdskfrl-emacs-packages-deps/share/emacs/site-lisp/ghostel-shell.el
(defun ghostel--imenu-create-index ()
"Build an imenu alist of OSC 133 prompts in the current buffer.
Each entry's label is \"<cwd> <command>\"; cwd is omitted when no
recorded entry aligns with the region (e.g. a still-active prompt
whose \\='C\\=' has not fired). Empty-command prompts are
skipped. Labels are truncated to 80 columns."
(let* ((regions (ghostel--imenu--collect-prompt-regions))
(cwds (reverse ghostel--imenu-cwds)) ; oldest first
;; Scrollback eviction removes prompts from the buffer top
;; but leaves cwds in the list. Drop the oldest cwds so
;; the remaining list aligns with the current regions.
(extra (max 0 (- (length cwds) (length regions))))
(cwds (nthcdr extra cwds))
;; Trim the stored list opportunistically so it doesn't
;; grow unboundedly across long sessions.
(_ (when (> extra 0)
(setq ghostel--imenu-cwds
(seq-take ghostel--imenu-cwds (- (length ghostel--imenu-cwds)
extra)))))
(index nil))
(cl-loop for region in regions
for cwd = (pop cwds)
do (let* ((pos (car region))
(prompt-end (cdr region))
(cmd-end (save-excursion
(goto-char prompt-end)
(line-end-position)))
(cmd (string-trim
(buffer-substring-no-properties prompt-end cmd-end))))
(unless (string-empty-p cmd)
(let ((label (if cwd
(format "%s %s"
(abbreviate-file-name
(directory-file-name cwd))
cmd)
cmd)))
(push (cons (truncate-string-to-width label 80 nil nil t)
pos)
index)))))
(nreverse index)))