Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9db9cb0

Browse files
committed
feat: config eldoc for elisp
1 parent fe93807 commit 9db9cb0

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

modules/lang/emacs-lisp/config.el

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,61 @@
1313
(file-header-defins jcs-insert-lisp-template "lisp" "default.txt"
1414
"Lisp file header format.")
1515

16+
;;
17+
;; (@* "ElDoc" )
18+
;;
19+
20+
(defun jcs--eldoc-remove-signature (str)
21+
"Remove function signature from STR."
22+
(with-temp-buffer
23+
(insert str)
24+
(goto-char (point-max))
25+
(when (jcs-current-char-equal-p ")")
26+
(backward-sexp)
27+
(delete-region (point) (point-max)))
28+
(string-trim (buffer-string))))
29+
30+
(defun jcs--elisp-eldoc-var-docstring-with-value (callback &rest _)
31+
"Edited from the function `elisp-eldoc-var-docstring-with-value'."
32+
(when-let ((cs (elisp--current-symbol)))
33+
(when (and (boundp cs)
34+
;; nil and t are boundp!
35+
(not (null cs))
36+
(not (eq cs t)))
37+
(funcall callback
38+
(format "%.100S\n%s"
39+
(symbol-value cs)
40+
(let* ((doc (documentation-property
41+
cs 'variable-documentation t))
42+
(more (- (length doc) 1000)))
43+
(concat (propertize
44+
(jcs-fill-string
45+
(if (string= doc "nil")
46+
"Undocumented."
47+
doc))
48+
'face 'font-lock-doc-face)
49+
(when (> more 0)
50+
(format "[%sc more]" more)))))
51+
:thing cs
52+
:face 'font-lock-variable-name-face))))
53+
54+
(defun jcs--elisp-eldoc-funcall (callback &rest _ignored)
55+
"Edited from the function `elisp-eldoc-funcall'."
56+
(let* ((sym-info (elisp--fnsym-in-current-sexp))
57+
(fn-sym (car sym-info))
58+
(doc (or (ignore-errors (documentation fn-sym t))
59+
""))
60+
(doc (jcs--eldoc-remove-signature doc))
61+
(doc (jcs-fill-string doc)))
62+
(when fn-sym
63+
(funcall callback (format "%s\n\n%s"
64+
(apply #'elisp-get-fnsym-args-string sym-info)
65+
(propertize doc 'face 'font-lock-doc-face))
66+
:thing fn-sym
67+
:face (if (functionp fn-sym)
68+
'font-lock-function-name-face
69+
'font-lock-keyword-face)))))
70+
1671
;;
1772
;; (@* "Hooks" )
1873
;;
@@ -25,6 +80,11 @@
2580

2681
(company-fuzzy-backend-add-before 'company-elisp-keywords 'company-dabbrev)
2782

83+
(add-hook 'eldoc-documentation-functions
84+
#'jcs--elisp-eldoc-funcall nil t)
85+
(add-hook 'eldoc-documentation-functions
86+
#'jcs--elisp-eldoc-var-docstring-with-value nil t)
87+
2888
(eask-api-setup))
2989

3090
(jcs-add-hook 'emacs-lisp-compilation-mode-hook

0 commit comments

Comments
 (0)