Added function and key binding to show docs through built-in "help" Python function.
--- a/.emacs-my Sun Feb 14 21:06:19 2016 +0200
+++ b/.emacs-my Mon Feb 15 20:16:43 2016 +0200
@@ -2780,6 +2780,9 @@
(defvar my/python-eldoc-string-code "__PYDOC_get_full_help('''%s''')"
"Python code used to get a string with the documentation of an object.")
+(defvar my/python-eldoc-string-code2 "help('''%s''')"
+ "Python code used to get a string with the documentation of an object.")
+
;; For built-in python.el
(my--eval-after-load python
(add-to-list 'python-shell-setup-codes 'my/python-eldoc-setup-code) ; Used inside (python-shell-send-setup-code)
@@ -2800,6 +2803,35 @@
(erase-buffer)
(insert (python-eldoc--get-doc-at-point symbol))
(goto-char (point-min))
+ (when (re-search-forward "^u?['\"]" (line-end-position) t)
+ (replace-match ""))
+ (while (re-search-forward "\\\\n" nil t)
+ (replace-match "\n"))
+ (goto-char (point-min))
+ (while (re-search-forward "\\\\'" nil t)
+ (replace-match "['\"]"))
+ (goto-char (point-max))
+ (when (eq ?' (char-before))
+ (delete-char -1))
+ (read-only-mode 1)
+ (goto-char (point-min))))
+ (define-key python-mode-map "\C-c\C-d" 'my/python-eldoc-at-point)
+ (defun my/python-eldoc-at-point2 (&optional symbol)
+ "Show full docs for symbol at point."
+ (interactive
+ (let ((symbol (python-info-current-symbol t))
+ (enable-recursive-minibuffers t))
+ (list (read-string (if symbol
+ (format "Describe symbol (default %s): " symbol)
+ "Describe symbol: ")
+ nil nil symbol))))
+ (let ( (python-eldoc-string-code my/python-eldoc-string-code2) )
+ (switch-to-buffer (get-buffer-create "*Python-doc*"))
+ (read-only-mode -1)
+ (buffer-disable-undo)
+ (erase-buffer)
+ (insert (python-eldoc--get-doc-at-point symbol))
+ (goto-char (point-min))
(when (re-search-forward "^u?'" (line-end-position) t)
(replace-match ""))
(while (re-search-forward "\\\\n" nil t)
@@ -2812,7 +2844,7 @@
(delete-char -1))
(read-only-mode 1)
(goto-char (point-min))))
- (define-key python-mode-map "\C-c\C-d" 'my/python-eldoc-at-point)
+ (define-key python-mode-map "\C-c\C-g" 'my/python-eldoc-at-point2)
(defun my-python/send-paragraph ()
(interactive)