Open tuhdo opened 7 years ago
Actually, eldoc-documentation-function
is not supposed to message
by itself, it should just return the string. As a result, this would be a minimal working example:
(defun rtags-eldoc-function () (rtags-get-summary-text 1))
For syntax highlighting, you could use this helper function:
(defun fontify-string (str mode)
"Return STR fontified according to MODE."
(with-temp-buffer
(insert str)
(delay-mode-hooks (funcall mode))
(font-lock-default-function mode)
(font-lock-default-fontify-region
(point-min) (point-max) nil)
(buffer-string)))
and for a bit more polished eldoc, something like this:
(defun rtags-eldoc-function ()
(let ((summary (rtags-get-summary-text)))
(and summary
(fontify-string
(replace-regexp-in-string
"{[^}]*$" ""
(mapconcat
(lambda (str) (if (= 0 (length str)) "//" (string-trim str)))
(split-string summary "\r?\n")
" "))
major-mode))))
(It joins all lines into one, converts brief docs into a trailing comments and strips incomplete function bodies)
I execute "rtags-symbol-type" function every time when I am interested in a variable. I hope I can see the type information automatically on message buffer. However I don't know how to do it:( Looks the above code is something for that, could anyone explain more how to make it happen? If you can explain how rtags-eldoc-function is called, that will be much better.
Since rtags can already display full symbol info at point, it is easy to add integration with Eldoc. Here is an Elisp snippet that I whipped out quickly to get it done:
Just to show how easy it is to add Eldoc support.
I guess it could be made more polished e.g. type information is colorized with
font-lock-type-face
.