Skip to content

Commit

Permalink
Minor fixes and test adpatation
Browse files Browse the repository at this point in the history
  • Loading branch information
galaunay committed Aug 5, 2020
1 parent 86aa703 commit 17a9d09
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
41 changes: 25 additions & 16 deletions elpy.el
Original file line number Diff line number Diff line change
Expand Up @@ -3103,12 +3103,12 @@ and return the list."
(eldoc-add-command-completions "python-indent-dedent-line-backspace")
(set (make-local-variable 'company-frontends)
(remq 'company-echo-metadata-frontend company-frontends))
;; New (Emacs >= 28) vs old eldoc API
(if (boundp 'eldoc-documentation-functions)
(add-hook 'eldoc-documentation-functions
'elpy-eldoc-documentation
nil t))
(set (make-local-variable 'eldoc-documentation-function)
'elpy-eldoc-documentation))
'elpy-eldoc-documentation nil t)
(set (make-local-variable 'eldoc-documentation-function)
'elpy-eldoc-documentation))
(eldoc-mode 1))
(`buffer-stop
(eldoc-mode -1)
Expand All @@ -3117,24 +3117,31 @@ and return the list."
(defun elpy-eldoc-documentation (&optional callback &rest _more)
"Return some interesting information for the code at point.
This function is good to place in
`eldoc-documentation-functions' (plural), (for newer Emacsen) and
also `eldoc-documentation-function' (for older Emacsen).
This function is meant to be added to `eldoc-documentation-functions'
\(for Emacs >= 28) or set in `eldoc-documentation-function' (for older
Emacs versions).
This will return flymake errors for the line at point if there
are any. If not, this will do an asynchronous call to the RPC
backend to get a call tip, and display that using
`eldoc-message'. If the backend has no call tip, this will
display the current class and method instead."
This will return flymake errors for the line at point if there are
any. If not, this will do an asynchronous call to the RPC backend to
get a call tip, and display that using `eldoc-message'. If the backend
has no call tip, this will display the current class and method
instead.
If specified, CALLBACK is the function called to display the
documentation (only used for Emacs >= 28)."
(let ((cb (or callback
(lambda (doc &rest plist)
(let ((thing (plist-get plist :thing))
(face (plist-get plist :face)))
(when thing
(setq thing (propertize thing
'face
'font-lock-function-name-face))
(setq doc
(if (version<= emacs-version "25")
(format "%s%s" thing doc)
(eldoc-docstring-format-sym-doc thing doc face))))
(let ((eldoc-echo-area-use-multiline-p nil))
(eldoc-docstring-format-sym-doc thing doc)))))
(eldoc-message doc)))))
(flymake-error (elpy-flymake-error-at-point)))
(if flymake-error
Expand All @@ -3144,7 +3151,7 @@ display the current class and method instead."
(cond
;; INFO is a string, just display it
((stringp info)
(funcall callback info))
(funcall cb info))
;; INFO is a calltip
((string= (cdr (assq 'kind info)) "calltip")
(let ((name (cdr (assq 'name info)))
Expand All @@ -3158,12 +3165,14 @@ display the current class and method instead."
(let ((prefix (propertize name 'face
'font-lock-function-name-face))
(args (format "(%s)" (mapconcat #'identity params ", "))))
(funcall callback args :thing prefix))))
(funcall cb args
:thing prefix))))
;; INFO is a oneline docstring
((string= (cdr (assq 'kind info)) "oneline_doc")
(let ((name (cdr (assq 'name info)))
(docs (cdr (assq 'doc info))))
(funcall cb docs :thing name)))
(funcall cb docs
:thing (format "%s: " name))))
;; INFO is nil, maybe display the current function
(t
(if elpy-eldoc-show-current-function
Expand Down
1 change: 1 addition & 0 deletions test/elpy-eldoc-documentation-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
(kind . "calltip")
(params "foo" "bar"))))
(calltip nil)
(window-width (buff) 100000000)
(eldoc-message (tip) (setq calltip tip)))

(elpy-eldoc-documentation)
Expand Down

0 comments on commit 17a9d09

Please sign in to comment.