]> git.eshelyaron.com Git - emacs.git/commitdiff
Implemented python-eldoc-at-point (python-describe-symbol replacement)
authorFabián Ezequiel Gallina <fgallina@cuca>
Thu, 17 May 2012 03:03:00 +0000 (00:03 -0300)
committerFabián Ezequiel Gallina <fgallina@gnu.org>
Thu, 17 May 2012 03:03:00 +0000 (00:03 -0300)
lisp/progmodes/python.el

index 211978f15dd219ddbe3bb380e5f7793014e9b419..16a6d4b45d079f4ad554004f6796110622bda072 100644 (file)
     (define-key map "\C-c\C-z" 'python-shell-switch-to-shell)
     ;; Some util commands
     (define-key map "\C-c\C-v" 'python-check)
+    (define-key map "\C-c\C-f" 'python-eldoc-at-point)
     ;; Utilities
     (substitute-key-definition 'complete-symbol 'completion-at-point
                               map global-map)
         "-"
        ["Check file" python-check
         :help "Check file for errors"]
+       ["Help on symbol" python-eldoc-at-point
+        :help "Get help on symbol at point"]
        ["Complete symbol" completion-at-point
         :help "Complete symbol before point"]))
     map)
@@ -1554,20 +1557,16 @@ It is specially designed to be added to the
       (python-shell-send-file temp-file (get-buffer-process (current-buffer)))
       (message (format "Eldoc setup code sent.")))))
 
-(defun python-eldoc-function ()
-  "`eldoc-documentation-function' for Python.
-For this to work the best as possible you should call
-`python-shell-send-buffer' from time to time so context in
-inferior python process is updated properly."
-  (interactive)
-  (let ((process (python-shell-get-process)))
+(defun python-eldoc--get-doc-at-point (&optional force-input force-process)
+  (let ((process (or force-process (python-shell-get-process))))
     (if (not process)
         "Eldoc needs an inferior Python process running."
       (let* ((current-defun (python-info-current-defun))
-             (input (with-syntax-table python-dotty-syntax-table
-                      (if (not current-defun)
-                          (current-word)
-                        (concat current-defun "." (current-word)))))
+             (input (or force-input
+                        (with-syntax-table python-dotty-syntax-table
+                          (if (not current-defun)
+                              (current-word)
+                            (concat current-defun "." (current-word))))))
              (ppss (syntax-ppss))
              (help (when (and input
                               (not (string= input (concat current-defun ".")))
@@ -1593,6 +1592,38 @@ inferior python process is updated properly."
                    (not (string= help "\n")))
           help)))))
 
+(defun python-eldoc-function ()
+  "`eldoc-documentation-function' for Python.
+For this to work the best as possible you should call
+`python-shell-send-buffer' from time to time so context in
+inferior python process is updated properly."
+  (python-eldoc--get-doc-at-point))
+
+(defun python-eldoc-at-point (symbol)
+  "Get help on SYMBOL using `help'.
+Interactively, prompt for symbol."
+    (interactive
+     (let ((symbol (with-syntax-table python-dotty-syntax-table
+                     (current-word)))
+           (enable-recursive-minibuffers t))
+       (list (read-string (if symbol
+                              (format "Describe symbol (default %s): " symbol)
+                            "Describe symbol: ")
+                          nil nil symbol))))
+    (let ((process (python-shell-get-process)))
+      (if (not process)
+          (message "Eldoc needs an inferior Python process running.")
+        (let ((temp-buffer-show-hook
+               (lambda ()
+                 (toggle-read-only 1)
+                 (setq view-return-to-alist
+                       (list (cons (selected-window) help-return-method))))))
+          (with-output-to-temp-buffer (help-buffer)
+            (with-current-buffer standard-output
+              (insert
+               (python-eldoc--get-doc-at-point symbol process))
+              (help-print-return-message)))))))
+
 (add-hook 'inferior-python-mode-hook
           #'python-eldoc-setup)