fix(eshell): don't error if command manpages has no SYNOPSIS

Fix: #6867
Ref: tom-tan/esh-help#7
This commit is contained in:
Henrik Lissner
2025-04-13 02:43:31 -04:00
parent 6e92ca594f
commit c7ca3ea8cc

View File

@ -218,7 +218,27 @@ Emacs versions < 29."
(use-package! esh-help
:after eshell
:config (setup-esh-help-eldoc))
:config
(setup-esh-help-eldoc)
;; HACK: Fixes tom-tan/esh-help#7.
(defadvice! +eshell-esh-help-eldoc-man-minibuffer-string-a (cmd)
"Return minibuffer help string for the shell command CMD.
Return nil if there is none."
:override #'esh-help-eldoc-man-minibuffer-string
(if-let* ((cache-result (gethash cmd esh-help-man-cache)))
(unless (eql 'none cache-result)
cache-result)
(let ((str (split-string (esh-help-man-string cmd) "\n")))
(if (equal (concat "No manual entry for " cmd) (car str))
(ignore (puthash cmd 'none esh-help-man-cache))
(puthash cmd
(-some->> str
(--drop-while (not (string-match-p "^SYNOPSIS$" it)))
(nth 1)
(funcall (lambda (s)
(let ((idx (string-match "[^\s\t]" s)))
(substring s idx)))))
esh-help-man-cache))))))
(use-package! eshell-did-you-mean