]> git.eshelyaron.com Git - emacs.git/commitdiff
python.el: Keep eldoc visible while typing args.
authorFabián Ezequiel Gallina <fgallina@gnu.org>
Sat, 7 Feb 2015 21:39:07 +0000 (18:39 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Sat, 7 Feb 2015 21:39:07 +0000 (18:39 -0300)
Fixes: debbugs:19637
* lisp/progmodes/python.el (python-eldoc--get-symbol-at-point): New
function.
(python-eldoc--get-doc-at-point, python-eldoc-at-point): Use it.

* test/automated/python-tests.el
(python-eldoc--get-symbol-at-point-1)
(python-eldoc--get-symbol-at-point-2)
(python-eldoc--get-symbol-at-point-3)
(python-eldoc--get-symbol-at-point-4): New tests.

lisp/ChangeLog
lisp/progmodes/python.el
test/ChangeLog
test/automated/python-tests.el

index 655ae574468dadfc25f07f1c3b13540f53ae5215..34d401379bb9b3e401324b3666c748e70ee74427 100644 (file)
@@ -1,3 +1,11 @@
+2015-02-07  Fabián Ezequiel Gallina  <fgallina@gnu.org>
+
+       python.el: Keep eldoc visible while typing args.  (Bug#19637)
+
+       * progmodes/python.el (python-eldoc--get-symbol-at-point): New
+       function.
+       (python-eldoc--get-doc-at-point, python-eldoc-at-point): Use it.
+
 2015-02-07  Fabián Ezequiel Gallina  <fgallina@gnu.org>
 
        Fix hideshow integration.  (Bug#19761)
index 3399429538f1cdb70569452f9301de94ac3ae2f4..72a76a461a6da65ce0a9eacadba402975a2be657 100644 (file)
@@ -3921,15 +3921,29 @@ See `python-check-command' for the default."
   :type 'string
   :group 'python)
 
+(defun python-eldoc--get-symbol-at-point ()
+  "Get the current symbol for eldoc.
+Returns the current symbol handling point within arguments."
+  (save-excursion
+    (let ((start (python-syntax-context 'paren)))
+      (when start
+        (goto-char start))
+      (when (or start
+                (eobp)
+                (memq (char-syntax (char-after)) '(?\ ?-)))
+        ;; Try to adjust to closest symbol if not in one.
+        (python-util-forward-comment -1)))
+    (python-info-current-symbol t)))
+
 (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.
@@ -3949,7 +3963,7 @@ inferior Python process is updated properly."
   "Get help on SYMBOL using `help'.
 Interactively, prompt for symbol."
   (interactive
-   (let ((symbol (python-info-current-symbol t))
+   (let ((symbol (python-eldoc--get-symbol-at-point))
          (enable-recursive-minibuffers t))
      (list (read-string (if symbol
                             (format "Describe symbol (default %s): " symbol)
index b1e21511d658673d2813c5c8d6f7f308cf757376..ff02bd6a25d785f7c46e18b4ac9d68a8ccb707a4 100644 (file)
@@ -1,3 +1,11 @@
+2015-02-07  Fabián Ezequiel Gallina  <fgallina@gnu.org>
+
+       * automated/python-tests.el
+       (python-eldoc--get-symbol-at-point-1)
+       (python-eldoc--get-symbol-at-point-2)
+       (python-eldoc--get-symbol-at-point-3)
+       (python-eldoc--get-symbol-at-point-4): New tests.
+
 2015-02-07  Fabián Ezequiel Gallina  <fgallina@gnu.org>
 
        * automated/python-tests.el
index e5fcda9501251ac01a7b62a527a5e852674e1d76..47e2a6e819509e59c304f7ce6beb66d1b5221bc3 100644 (file)
@@ -2943,6 +2943,63 @@ class Foo(models.Model):
 \f
 ;;; Eldoc
 
+(ert-deftest python-eldoc--get-symbol-at-point-1 ()
+  "Test paren handling."
+  (python-tests-with-temp-buffer
+   "
+map(xx
+map(codecs.open('somefile'
+"
+   (python-tests-look-at "ap(xx")
+   (should (string= (python-eldoc--get-symbol-at-point) "map"))
+   (goto-char (line-end-position))
+   (should (string= (python-eldoc--get-symbol-at-point) "map"))
+   (python-tests-look-at "('somefile'")
+   (should (string= (python-eldoc--get-symbol-at-point) "map"))
+   (goto-char (line-end-position))
+   (should (string= (python-eldoc--get-symbol-at-point) "codecs.open"))))
+
+(ert-deftest python-eldoc--get-symbol-at-point-2 ()
+  "Ensure self is replaced with the class name."
+  (python-tests-with-temp-buffer
+   "
+class TheClass:
+
+    def some_method(self, n):
+        return n
+
+    def other(self):
+        return self.some_method(1234)
+
+"
+   (python-tests-look-at "self.some_method")
+   (should (string= (python-eldoc--get-symbol-at-point)
+                    "TheClass.some_method"))
+   (python-tests-look-at "1234)")
+   (should (string= (python-eldoc--get-symbol-at-point)
+                    "TheClass.some_method"))))
+
+(ert-deftest python-eldoc--get-symbol-at-point-3 ()
+  "Ensure symbol is found when point is at end of buffer."
+  (python-tests-with-temp-buffer
+   "
+some_symbol
+
+"
+   (goto-char (point-max))
+   (should (string= (python-eldoc--get-symbol-at-point)
+                    "some_symbol"))))
+
+(ert-deftest python-eldoc--get-symbol-at-point-4 ()
+  "Ensure symbol is found when point is at whitespace."
+  (python-tests-with-temp-buffer
+   "
+some_symbol   some_other_symbol
+"
+   (python-tests-look-at "  some_other_symbol")
+   (should (string= (python-eldoc--get-symbol-at-point)
+                    "some_symbol"))))
+
 \f
 ;;; Imenu