当point在一个函数上时,minibuffer显示这个函数的参数列表;当company active时,minibuffer显示当前candidate的文档。
我希望:按下某个键时,minibuffer显示point下这个函数的文档,当我移动光标或做其它操作之后,minibuffer又回到默认的 显示参数列表 的行为。
当point在一个函数上时,minibuffer显示这个函数的参数列表;当company active时,minibuffer显示当前candidate的文档。
我希望:按下某个键时,minibuffer显示point下这个函数的文档,当我移动光标或做其它操作之后,minibuffer又回到默认的 显示参数列表 的行为。
从 companyelisp中得到的代码
(defun company-elisp--doc (symbol)
(let* ((symbol (intern symbol))
(doc (if (fboundp symbol)
(documentation symbol t)
(documentation-property symbol 'variable-documentation t))))
(and (stringp doc)
(string-match ".*$" doc)
(match-string 0 doc))))
其实不用按某个键
显示参数是eldoc的作用
看看eldoc 让他显示文档就可以了吧
可以参考company-quickhelp
把company这个函数抄过来包装一下就成了:
(defun my/company-elisp--doc (symbol-string)
(let* ((symbol (intern symbol-string))
(doc (if (fboundp symbol)
(documentation symbol t)
(documentation-property symbol 'variable-documentation t))))
(and (stringp doc)
(string-match ".*$" doc)
(match-string 0 doc))))
(defun my/elisp-doc-at-point ()
"Show documentation for symbol at piont."
(interactive)
(message (my/company-elisp--doc (thing-at-point 'symbol))))
让 Eldoc 在 Emacs Lisp 中显示函数的文档,根据自己喜好调整(文档常常比较长,多余一行,不方便显示,我只显示一行):
(define-advice elisp-get-fnsym-args-string (:around (orig-fun sym &rest r) docstring)
"If SYM is a function, append its docstring."
(concat
(apply orig-fun sym r)
(let* ((doc (and (fboundp sym) (documentation sym 'raw)))
(oneline (and doc (substring doc 0 (string-match "\n" doc)))))
(and oneline
(stringp oneline)
(not (string= "" oneline))
(concat " | " (propertize oneline 'face 'italic))))))
改成了nadvice的来练习一下:
(advice-add
'elisp-get-fnsym-args-string :around
(lambda (oldfun sym &rest args)
"If SYM is a function, append its docstring."
(concat
(apply oldfun sym args)
(let* ((doc (and (fboundp sym) (documentation sym 'raw)))
(oneline (and doc (substring doc 0 (string-match "\n" doc)))))
(and oneline
(stringp oneline)
(not (string= "" oneline))
(concat " | " (propertize oneline 'face 'italic))))))
'((name . "docstring")))
define-advice
效果等于 advice-add
+ defun
,同样也是 nadvice 提供的。
要把doc里面的advice那行去掉:
(replace-regexp-in-string
;; regex from ivy-rich
":\\(\\(before\\|after\\)\\(-\\(while\\|until\\)\\)?\\|around\\|override\\|\\(filter-\\(args\\|return\\)\\)\\) advice:[ ]*‘.+?’[\r\n]+"
""
doc)