summaryrefslogtreecommitdiff
path: root/lisp/progmodes/python.el
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina <fgallina@cuca>2012-05-17 00:03:09 -0300
committerFabián Ezequiel Gallina <fgallina@gnu.org>2012-05-17 00:03:09 -0300
commitc0428ba0bd8f0d9e4e05bc12aa7fce2df4e2dc11 (patch)
treec557a1b8dde932a2c0bb4051478526eba717a646 /lisp/progmodes/python.el
parent9f1537ef3e5e6782edacfacbf9f4396e3ab11bd1 (diff)
Better shell setup using the new python-shell-send-setup-codes function.
At the moment of shell setup, all the pending output is accepted so the prompt is always displayed correctly.
Diffstat (limited to 'lisp/progmodes/python.el')
-rw-r--r--lisp/progmodes/python.el74
1 files changed, 32 insertions, 42 deletions
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index b745050f551..92a19309dc1 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -963,14 +963,14 @@ Returns nil if point is not in a def or class."
(defcustom python-shell-interpreter "python"
"Default Python interpreter for shell."
- :group 'python
:type 'string
+ :group 'python
:safe 'stringp)
(defcustom python-shell-interpreter-args "-i"
"Default arguments for the Python interpreter."
- :group 'python
:type 'string
+ :group 'python
:safe 'stringp)
(defcustom python-shell-prompt-regexp ">>> "
@@ -1001,6 +1001,18 @@ The regex should not contain a caret (^) at the beginning."
:group 'python
:safe 'stringp)
+(defcustom python-shell-setup-codes '(python-shell-completion-setup-code
+ python-ffap-setup-code
+ python-eldoc-setup-code)
+ "List of code run by `python-shell-send-setup-codes'.
+Each variable can be either a simple string with the code to
+execute or a cons with the form (CODE . DESCRIPTION), where CODE
+is a string with the code to execute and DESCRIPTION is the
+description of it."
+ :type '(repeat symbol)
+ :group 'python
+ :safe 'listp)
+
(defcustom python-shell-compilation-regexp-alist
`((,(rx line-start (1+ (any " \t")) "File \""
(group (1+ (not (any "\"<")))) ; avoid `<stdin>' &c
@@ -1256,6 +1268,24 @@ FILE-NAME."
(interactive)
(pop-to-buffer (process-buffer (python-shell-get-or-create-process)) t))
+(defun python-shell-send-setup-code ()
+ "Send all setup code for shell.
+This function takes the list of setup code to send from the
+`python-shell-setup-codes' list."
+ (let ((msg "Sent %s")
+ (process (get-buffer-process (current-buffer))))
+ (accept-process-output process 1)
+ (dolist (code python-shell-setup-codes)
+ (when code
+ (when (consp code)
+ (setq msg (cdr code)))
+ (message (format msg code))
+ (python-shell-send-string-no-output
+ (symbol-value code) process)))))
+
+(add-hook 'inferior-python-mode-hook
+ #'python-shell-send-setup-code)
+
;;; Shell completion
@@ -1286,16 +1316,6 @@ else:
"';'.join(__COMPLETER_all_completions('''%s'''))\n"
"Python code used to get a string of completions separated by semicolons.")
-(defun python-shell-completion-setup ()
- "Send `python-shell-completion-setup-code' to inferior Python process.
-It is specially designed to be added to the
-`inferior-python-mode-hook'."
- (when (> (length python-shell-completion-setup-code) 0)
- (python-shell-send-string-no-output
- python-shell-completion-setup-code
- (get-buffer-process (current-buffer)))
- (message "Completion setup code sent.")))
-
(defun python-shell-completion--get-completions (input process)
"Retrieve available completions for INPUT using PROCESS."
(with-current-buffer (process-buffer process)
@@ -1349,9 +1369,6 @@ complete."
(indent-for-tab-command)
(comint-dynamic-complete)))
-(add-hook 'inferior-python-mode-hook
- #'python-shell-completion-setup)
-
;;; PDB Track integration
@@ -1698,17 +1715,6 @@ The skeleton will be bound to python-skeleton-NAME."
"__FFAP_get_module_path('''%s''')\n"
"Python code used to get a string with the path of a module.")
-(defun python-ffap-setup ()
- "Send `python-ffap-setup-code' to inferior Python process.
-It is specially designed to be added to the
-`inferior-python-mode-hook'."
-
- (when (> (length python-ffap-setup-code) 0)
- (python-shell-send-string-no-output
- python-ffap-setup-code
- (get-buffer-process (current-buffer)))
- (message "FFAP setup code sent.")))
-
(defun python-ffap-module-path (module)
"Function for `ffap-alist' to return path for MODULE."
(let ((process (or
@@ -1728,9 +1734,6 @@ It is specially designed to be added to the
(push '(python-mode . python-ffap-module-path) ffap-alist)
(push '(inferior-python-mode . python-ffap-module-path) ffap-alist)))
-(add-hook 'inferior-python-mode-hook
- #'python-ffap-setup)
-
;;; Code check
@@ -1781,16 +1784,6 @@ Runs COMMAND, a shell command, as if by `compile'. See
"__PYDOC_get_help('''%s''')\n"
"Python code used to get a string with the documentation of an object.")
-(defun python-eldoc-setup ()
- "Send `python-eldoc-setup-code' to inferior Python process.
-It is specially designed to be added to the
-`inferior-python-mode-hook'."
- (when (> (length python-eldoc-setup-code) 0)
- (python-shell-send-string-no-output
- python-eldoc-setup-code
- (get-buffer-process (current-buffer)))
- (message "Eldoc setup code sent.")))
-
(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 `current-word' returns
@@ -1862,9 +1855,6 @@ Interactively, prompt for symbol."
(python-eldoc--get-doc-at-point symbol process))
(help-print-return-message)))))))
-(add-hook 'inferior-python-mode-hook
- #'python-eldoc-setup)
-
;;; Misc helpers