Subject: bug#19637: 25.0.50; ipython eldoc keep visible while typing parameters

From: Carlos Pita <[email-masked]>
Date: Thu, 5 Feb 2015 16:21:03 -0300

Here is a tentative patch.

What it does is the following:

1) If point is in a paren context it escapes to the opening parenthesis

2) Now, if point is left (or was there from the very beginning) over
an opening (, then the relevant symbol is the one to the left of the
(, so whitespaces, newlines and backslashes are skipped backwards.
Presumably the point is now over a symbol.

3) We call (python-info-current-symbol). If a symbol is indeed parsed,
it's returned, if not, then the point position is restored and
(python-info-current-symbol) is called as usual.

Notice that the above allows for nested calls. But the exact behavior
is as follows (say * marks the position of the point):

a) m*ap(xx           will return map
b) map(xx*           will return map
c) map(open*       will also return map
d) map(open(xx*  will return open

I think this is almost always what you want. But a more complex
sequence could be implemented for c that first checks if there is any
documentation for 'open' and only in case there was no documentation
for the symbol, it showed the documentation for 'map'. I don't think
it's worth the extra complexity.

Cheers
--
Carlos
diff --git a/.emacs.d/lisp/python.el b/.emacs.d/lisp/python.el
index 4c8f4c6..3fe62e0 100644
--- a/.emacs.d/lisp/python.el
+++ b/.emacs.d/lisp/python.el
@@ -3940,15 +3940,25 @@ See `python-check-command' for the default."
   :type 'string
   :group 'python)
 
+(defun python-eldoc--get-symbol-at-point ()
+  (or (save-excursion
+        (when (let ((start (python-syntax-context 'paren)))
+                (when start
+                  (goto-char start))
+                (= (char-after) ?\())
+          (skip-chars-backward " \t\n\\\\")
+          (python-info-current-symbol)))
+      (python-info-current-symbol)))
+
 (defun python-eldoc--get-doc-at-point (&optional force-input force-process)
   "Internal implementation to get documentation at point.
-If not FORCE-INPUT is passed then what `python-info-current-symbol'
+If not FORCE-INPUT is passed then what `python-eldoc--get-symbol-at-point'
 returns will be used.  If not FORCE-PROCESS is passed what
 `python-shell-get-process' returns is used."
   (let ((process (or force-process (python-shell-get-process))))
     (when process
       (let ((input (or force-input
-                       (python-info-current-symbol t))))
+                       (python-eldoc--get-symbol-at-point))))
         (and input
              ;; Prevent resizing the echo area when iPython is
              ;; enabled.  Bug#18794.