aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2015-02-07 18:39:07 -0300
committerFabián Ezequiel Gallina2015-02-07 18:39:07 -0300
commit2155973e5e35d11a50ce6773bb34d5df68beea57 (patch)
tree682fa184b144ec057533839858c6617c8d166b46
parent2d467a0ff0cd446ec0d83044a0be819cbf874cdf (diff)
downloademacs-2155973e5e35d11a50ce6773bb34d5df68beea57.tar.gz
emacs-2155973e5e35d11a50ce6773bb34d5df68beea57.zip
python.el: Keep eldoc visible while typing args.
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.
-rw-r--r--lisp/ChangeLog8
-rw-r--r--lisp/progmodes/python.el20
-rw-r--r--test/ChangeLog8
-rw-r--r--test/automated/python-tests.el57
4 files changed, 90 insertions, 3 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 655ae574468..34d401379bb 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,13 @@
12015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org> 12015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org>
2 2
3 python.el: Keep eldoc visible while typing args. (Bug#19637)
4
5 * progmodes/python.el (python-eldoc--get-symbol-at-point): New
6 function.
7 (python-eldoc--get-doc-at-point, python-eldoc-at-point): Use it.
8
92015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org>
10
3 Fix hideshow integration. (Bug#19761) 11 Fix hideshow integration. (Bug#19761)
4 12
5 * progmodes/python.el 13 * progmodes/python.el
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 3399429538f..72a76a461a6 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -3921,15 +3921,29 @@ See `python-check-command' for the default."
3921 :type 'string 3921 :type 'string
3922 :group 'python) 3922 :group 'python)
3923 3923
3924(defun python-eldoc--get-symbol-at-point ()
3925 "Get the current symbol for eldoc.
3926Returns the current symbol handling point within arguments."
3927 (save-excursion
3928 (let ((start (python-syntax-context 'paren)))
3929 (when start
3930 (goto-char start))
3931 (when (or start
3932 (eobp)
3933 (memq (char-syntax (char-after)) '(?\ ?-)))
3934 ;; Try to adjust to closest symbol if not in one.
3935 (python-util-forward-comment -1)))
3936 (python-info-current-symbol t)))
3937
3924(defun python-eldoc--get-doc-at-point (&optional force-input force-process) 3938(defun python-eldoc--get-doc-at-point (&optional force-input force-process)
3925 "Internal implementation to get documentation at point. 3939 "Internal implementation to get documentation at point.
3926If not FORCE-INPUT is passed then what `python-info-current-symbol' 3940If not FORCE-INPUT is passed then what `python-eldoc--get-symbol-at-point'
3927returns will be used. If not FORCE-PROCESS is passed what 3941returns will be used. If not FORCE-PROCESS is passed what
3928`python-shell-get-process' returns is used." 3942`python-shell-get-process' returns is used."
3929 (let ((process (or force-process (python-shell-get-process)))) 3943 (let ((process (or force-process (python-shell-get-process))))
3930 (when process 3944 (when process
3931 (let ((input (or force-input 3945 (let ((input (or force-input
3932 (python-info-current-symbol t)))) 3946 (python-eldoc--get-symbol-at-point))))
3933 (and input 3947 (and input
3934 ;; Prevent resizing the echo area when iPython is 3948 ;; Prevent resizing the echo area when iPython is
3935 ;; enabled. Bug#18794. 3949 ;; enabled. Bug#18794.
@@ -3949,7 +3963,7 @@ inferior Python process is updated properly."
3949 "Get help on SYMBOL using `help'. 3963 "Get help on SYMBOL using `help'.
3950Interactively, prompt for symbol." 3964Interactively, prompt for symbol."
3951 (interactive 3965 (interactive
3952 (let ((symbol (python-info-current-symbol t)) 3966 (let ((symbol (python-eldoc--get-symbol-at-point))
3953 (enable-recursive-minibuffers t)) 3967 (enable-recursive-minibuffers t))
3954 (list (read-string (if symbol 3968 (list (read-string (if symbol
3955 (format "Describe symbol (default %s): " symbol) 3969 (format "Describe symbol (default %s): " symbol)
diff --git a/test/ChangeLog b/test/ChangeLog
index b1e21511d65..ff02bd6a25d 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,6 +1,14 @@
12015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org> 12015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org>
2 2
3 * automated/python-tests.el 3 * automated/python-tests.el
4 (python-eldoc--get-symbol-at-point-1)
5 (python-eldoc--get-symbol-at-point-2)
6 (python-eldoc--get-symbol-at-point-3)
7 (python-eldoc--get-symbol-at-point-4): New tests.
8
92015-02-07 Fabián Ezequiel Gallina <fgallina@gnu.org>
10
11 * automated/python-tests.el
4 (python-tests-visible-string): New function. 12 (python-tests-visible-string): New function.
5 (python-parens-electric-indent-1) 13 (python-parens-electric-indent-1)
6 (python-triple-quote-pairing): Fix indentation, move require calls. 14 (python-triple-quote-pairing): Fix indentation, move require calls.
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index e5fcda95012..47e2a6e8195 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -2943,6 +2943,63 @@ class Foo(models.Model):
2943 2943
2944;;; Eldoc 2944;;; Eldoc
2945 2945
2946(ert-deftest python-eldoc--get-symbol-at-point-1 ()
2947 "Test paren handling."
2948 (python-tests-with-temp-buffer
2949 "
2950map(xx
2951map(codecs.open('somefile'
2952"
2953 (python-tests-look-at "ap(xx")
2954 (should (string= (python-eldoc--get-symbol-at-point) "map"))
2955 (goto-char (line-end-position))
2956 (should (string= (python-eldoc--get-symbol-at-point) "map"))
2957 (python-tests-look-at "('somefile'")
2958 (should (string= (python-eldoc--get-symbol-at-point) "map"))
2959 (goto-char (line-end-position))
2960 (should (string= (python-eldoc--get-symbol-at-point) "codecs.open"))))
2961
2962(ert-deftest python-eldoc--get-symbol-at-point-2 ()
2963 "Ensure self is replaced with the class name."
2964 (python-tests-with-temp-buffer
2965 "
2966class TheClass:
2967
2968 def some_method(self, n):
2969 return n
2970
2971 def other(self):
2972 return self.some_method(1234)
2973
2974"
2975 (python-tests-look-at "self.some_method")
2976 (should (string= (python-eldoc--get-symbol-at-point)
2977 "TheClass.some_method"))
2978 (python-tests-look-at "1234)")
2979 (should (string= (python-eldoc--get-symbol-at-point)
2980 "TheClass.some_method"))))
2981
2982(ert-deftest python-eldoc--get-symbol-at-point-3 ()
2983 "Ensure symbol is found when point is at end of buffer."
2984 (python-tests-with-temp-buffer
2985 "
2986some_symbol
2987
2988"
2989 (goto-char (point-max))
2990 (should (string= (python-eldoc--get-symbol-at-point)
2991 "some_symbol"))))
2992
2993(ert-deftest python-eldoc--get-symbol-at-point-4 ()
2994 "Ensure symbol is found when point is at whitespace."
2995 (python-tests-with-temp-buffer
2996 "
2997some_symbol some_other_symbol
2998"
2999 (python-tests-look-at " some_other_symbol")
3000 (should (string= (python-eldoc--get-symbol-at-point)
3001 "some_symbol"))))
3002
2946 3003
2947;;; Imenu 3004;;; Imenu
2948 3005