Files
sydnix/users/crumb/programs/emacs/modules/lang/syd-lang-emacs-lisp.el
Madeleine Sydney aa1cd2c69f feat: Lookup docs
2025-02-01 10:41:15 -07:00

47 lines
1.6 KiB
EmacsLisp

;;; emacs-lisp.el -*- lexical-binding: t; -*-
(require 'syd-handle-repl)
(require 'syd-handle-lookup)
;; (require 'handle)
;; Don't `use-package' `ielm', since it's loaded by Emacs. You'll get weird
;; autoload errors if you do.
;; https://www.reddit.com/r/emacs/comments/q7fjbi/comment/lml127d
(use-package emacs
:custom ((ielm-history-file-name ; Stay out of my config dir!
(file-name-concat syd-cache-dir "ielm-history.eld"))))
(defun syd/open-emacs-lisp-repl ()
(interactive)
(pop-to-buffer
(or (get-buffer "*ielm*")
(progn (ielm) ; Creates the *ielm* buffer.
(let ((b (get-buffer "*ielm*")))
;; We leave it to the enclosing `pop-to-buffer' to display the
;; buffer.
(bury-buffer b)
b)))))
(defun syd-emacs-lisp-lookup-documentation (identifier)
"Lookup IDENTIFIER with `describe-symbol'"
;; HACK: Much to my frustration, `describe-symbol' has no defined
;; return value. To test if the call was successful or not, we
;; check if any window is displaying the help buffer. This probably
;; breaks if `syd-emacs-lisp-lookup-documentation' is called while
;; the help buffer is already open.
(describe-symbol (intern identifier))
(let ((buffer (get-buffer (help-buffer))))
(and (get-buffer-window-list buffer)
buffer)))
(set-repl-handler! 'emacs-lisp-mode
#'syd/open-emacs-lisp-repl)
(defun syd-emacs-set-handlers ()
(setq-local syd-lookup-documentation-handlers
(list #'syd-emacs-lisp-lookup-documentation)))
(add-hook 'emacs-lisp-mode-hook #'syd-emacs-set-handlers)
(provide 'syd-lang-emacs-lisp)