aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2012-05-17 00:03:00 -0300
committerFabián Ezequiel Gallina2012-05-17 00:03:00 -0300
commit78334b439dac55783347e4062cba58cfef638201 (patch)
treedc73b9e3536da2374a21e82f091bab15b305f0ae /lisp/progmodes/python.el
parent8b3e0e76ee48f73c33d0d6af67fdc7be10497dae (diff)
downloademacs-78334b439dac55783347e4062cba58cfef638201.tar.gz
emacs-78334b439dac55783347e4062cba58cfef638201.zip
Implemented python-eldoc-at-point (python-describe-symbol replacement)
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el53
1 files changed, 42 insertions, 11 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 211978f15dd..16a6d4b45d0 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -136,6 +136,7 @@
136 (define-key map "\C-c\C-z" 'python-shell-switch-to-shell) 136 (define-key map "\C-c\C-z" 'python-shell-switch-to-shell)
137 ;; Some util commands 137 ;; Some util commands
138 (define-key map "\C-c\C-v" 'python-check) 138 (define-key map "\C-c\C-v" 'python-check)
139 (define-key map "\C-c\C-f" 'python-eldoc-at-point)
139 ;; Utilities 140 ;; Utilities
140 (substitute-key-definition 'complete-symbol 'completion-at-point 141 (substitute-key-definition 'complete-symbol 'completion-at-point
141 map global-map) 142 map global-map)
@@ -175,6 +176,8 @@
175 "-" 176 "-"
176 ["Check file" python-check 177 ["Check file" python-check
177 :help "Check file for errors"] 178 :help "Check file for errors"]
179 ["Help on symbol" python-eldoc-at-point
180 :help "Get help on symbol at point"]
178 ["Complete symbol" completion-at-point 181 ["Complete symbol" completion-at-point
179 :help "Complete symbol before point"])) 182 :help "Complete symbol before point"]))
180 map) 183 map)
@@ -1554,20 +1557,16 @@ It is specially designed to be added to the
1554 (python-shell-send-file temp-file (get-buffer-process (current-buffer))) 1557 (python-shell-send-file temp-file (get-buffer-process (current-buffer)))
1555 (message (format "Eldoc setup code sent."))))) 1558 (message (format "Eldoc setup code sent.")))))
1556 1559
1557(defun python-eldoc-function () 1560(defun python-eldoc--get-doc-at-point (&optional force-input force-process)
1558 "`eldoc-documentation-function' for Python. 1561 (let ((process (or force-process (python-shell-get-process))))
1559For this to work the best as possible you should call
1560`python-shell-send-buffer' from time to time so context in
1561inferior python process is updated properly."
1562 (interactive)
1563 (let ((process (python-shell-get-process)))
1564 (if (not process) 1562 (if (not process)
1565 "Eldoc needs an inferior Python process running." 1563 "Eldoc needs an inferior Python process running."
1566 (let* ((current-defun (python-info-current-defun)) 1564 (let* ((current-defun (python-info-current-defun))
1567 (input (with-syntax-table python-dotty-syntax-table 1565 (input (or force-input
1568 (if (not current-defun) 1566 (with-syntax-table python-dotty-syntax-table
1569 (current-word) 1567 (if (not current-defun)
1570 (concat current-defun "." (current-word))))) 1568 (current-word)
1569 (concat current-defun "." (current-word))))))
1571 (ppss (syntax-ppss)) 1570 (ppss (syntax-ppss))
1572 (help (when (and input 1571 (help (when (and input
1573 (not (string= input (concat current-defun "."))) 1572 (not (string= input (concat current-defun ".")))
@@ -1593,6 +1592,38 @@ inferior python process is updated properly."
1593 (not (string= help "\n"))) 1592 (not (string= help "\n")))
1594 help))))) 1593 help)))))
1595 1594
1595(defun python-eldoc-function ()
1596 "`eldoc-documentation-function' for Python.
1597For this to work the best as possible you should call
1598`python-shell-send-buffer' from time to time so context in
1599inferior python process is updated properly."
1600 (python-eldoc--get-doc-at-point))
1601
1602(defun python-eldoc-at-point (symbol)
1603 "Get help on SYMBOL using `help'.
1604Interactively, prompt for symbol."
1605 (interactive
1606 (let ((symbol (with-syntax-table python-dotty-syntax-table
1607 (current-word)))
1608 (enable-recursive-minibuffers t))
1609 (list (read-string (if symbol
1610 (format "Describe symbol (default %s): " symbol)
1611 "Describe symbol: ")
1612 nil nil symbol))))
1613 (let ((process (python-shell-get-process)))
1614 (if (not process)
1615 (message "Eldoc needs an inferior Python process running.")
1616 (let ((temp-buffer-show-hook
1617 (lambda ()
1618 (toggle-read-only 1)
1619 (setq view-return-to-alist
1620 (list (cons (selected-window) help-return-method))))))
1621 (with-output-to-temp-buffer (help-buffer)
1622 (with-current-buffer standard-output
1623 (insert
1624 (python-eldoc--get-doc-at-point symbol process))
1625 (help-print-return-message)))))))
1626
1596(add-hook 'inferior-python-mode-hook 1627(add-hook 'inferior-python-mode-hook
1597 #'python-eldoc-setup) 1628 #'python-eldoc-setup)
1598 1629