aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2012-05-17 00:03:09 -0300
committerFabián Ezequiel Gallina2012-05-17 00:03:09 -0300
commitc0428ba0bd8f0d9e4e05bc12aa7fce2df4e2dc11 (patch)
treec557a1b8dde932a2c0bb4051478526eba717a646 /lisp
parent9f1537ef3e5e6782edacfacbf9f4396e3ab11bd1 (diff)
downloademacs-c0428ba0bd8f0d9e4e05bc12aa7fce2df4e2dc11.tar.gz
emacs-c0428ba0bd8f0d9e4e05bc12aa7fce2df4e2dc11.zip
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')
-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."
963 963
964(defcustom python-shell-interpreter "python" 964(defcustom python-shell-interpreter "python"
965 "Default Python interpreter for shell." 965 "Default Python interpreter for shell."
966 :group 'python
967 :type 'string 966 :type 'string
967 :group 'python
968 :safe 'stringp) 968 :safe 'stringp)
969 969
970(defcustom python-shell-interpreter-args "-i" 970(defcustom python-shell-interpreter-args "-i"
971 "Default arguments for the Python interpreter." 971 "Default arguments for the Python interpreter."
972 :group 'python
973 :type 'string 972 :type 'string
973 :group 'python
974 :safe 'stringp) 974 :safe 'stringp)
975 975
976(defcustom python-shell-prompt-regexp ">>> " 976(defcustom python-shell-prompt-regexp ">>> "
@@ -1001,6 +1001,18 @@ The regex should not contain a caret (^) at the beginning."
1001 :group 'python 1001 :group 'python
1002 :safe 'stringp) 1002 :safe 'stringp)
1003 1003
1004(defcustom python-shell-setup-codes '(python-shell-completion-setup-code
1005 python-ffap-setup-code
1006 python-eldoc-setup-code)
1007 "List of code run by `python-shell-send-setup-codes'.
1008Each variable can be either a simple string with the code to
1009execute or a cons with the form (CODE . DESCRIPTION), where CODE
1010is a string with the code to execute and DESCRIPTION is the
1011description of it."
1012 :type '(repeat symbol)
1013 :group 'python
1014 :safe 'listp)
1015
1004(defcustom python-shell-compilation-regexp-alist 1016(defcustom python-shell-compilation-regexp-alist
1005 `((,(rx line-start (1+ (any " \t")) "File \"" 1017 `((,(rx line-start (1+ (any " \t")) "File \""
1006 (group (1+ (not (any "\"<")))) ; avoid `<stdin>' &c 1018 (group (1+ (not (any "\"<")))) ; avoid `<stdin>' &c
@@ -1256,6 +1268,24 @@ FILE-NAME."
1256 (interactive) 1268 (interactive)
1257 (pop-to-buffer (process-buffer (python-shell-get-or-create-process)) t)) 1269 (pop-to-buffer (process-buffer (python-shell-get-or-create-process)) t))
1258 1270
1271(defun python-shell-send-setup-code ()
1272 "Send all setup code for shell.
1273This function takes the list of setup code to send from the
1274`python-shell-setup-codes' list."
1275 (let ((msg "Sent %s")
1276 (process (get-buffer-process (current-buffer))))
1277 (accept-process-output process 1)
1278 (dolist (code python-shell-setup-codes)
1279 (when code
1280 (when (consp code)
1281 (setq msg (cdr code)))
1282 (message (format msg code))
1283 (python-shell-send-string-no-output
1284 (symbol-value code) process)))))
1285
1286(add-hook 'inferior-python-mode-hook
1287 #'python-shell-send-setup-code)
1288
1259 1289
1260;;; Shell completion 1290;;; Shell completion
1261 1291
@@ -1286,16 +1316,6 @@ else:
1286 "';'.join(__COMPLETER_all_completions('''%s'''))\n" 1316 "';'.join(__COMPLETER_all_completions('''%s'''))\n"
1287 "Python code used to get a string of completions separated by semicolons.") 1317 "Python code used to get a string of completions separated by semicolons.")
1288 1318
1289(defun python-shell-completion-setup ()
1290 "Send `python-shell-completion-setup-code' to inferior Python process.
1291It is specially designed to be added to the
1292`inferior-python-mode-hook'."
1293 (when (> (length python-shell-completion-setup-code) 0)
1294 (python-shell-send-string-no-output
1295 python-shell-completion-setup-code
1296 (get-buffer-process (current-buffer)))
1297 (message "Completion setup code sent.")))
1298
1299(defun python-shell-completion--get-completions (input process) 1319(defun python-shell-completion--get-completions (input process)
1300 "Retrieve available completions for INPUT using PROCESS." 1320 "Retrieve available completions for INPUT using PROCESS."
1301 (with-current-buffer (process-buffer process) 1321 (with-current-buffer (process-buffer process)
@@ -1349,9 +1369,6 @@ complete."
1349 (indent-for-tab-command) 1369 (indent-for-tab-command)
1350 (comint-dynamic-complete))) 1370 (comint-dynamic-complete)))
1351 1371
1352(add-hook 'inferior-python-mode-hook
1353 #'python-shell-completion-setup)
1354
1355 1372
1356;;; PDB Track integration 1373;;; PDB Track integration
1357 1374
@@ -1698,17 +1715,6 @@ The skeleton will be bound to python-skeleton-NAME."
1698 "__FFAP_get_module_path('''%s''')\n" 1715 "__FFAP_get_module_path('''%s''')\n"
1699 "Python code used to get a string with the path of a module.") 1716 "Python code used to get a string with the path of a module.")
1700 1717
1701(defun python-ffap-setup ()
1702 "Send `python-ffap-setup-code' to inferior Python process.
1703It is specially designed to be added to the
1704`inferior-python-mode-hook'."
1705
1706 (when (> (length python-ffap-setup-code) 0)
1707 (python-shell-send-string-no-output
1708 python-ffap-setup-code
1709 (get-buffer-process (current-buffer)))
1710 (message "FFAP setup code sent.")))
1711
1712(defun python-ffap-module-path (module) 1718(defun python-ffap-module-path (module)
1713 "Function for `ffap-alist' to return path for MODULE." 1719 "Function for `ffap-alist' to return path for MODULE."
1714 (let ((process (or 1720 (let ((process (or
@@ -1728,9 +1734,6 @@ It is specially designed to be added to the
1728 (push '(python-mode . python-ffap-module-path) ffap-alist) 1734 (push '(python-mode . python-ffap-module-path) ffap-alist)
1729 (push '(inferior-python-mode . python-ffap-module-path) ffap-alist))) 1735 (push '(inferior-python-mode . python-ffap-module-path) ffap-alist)))
1730 1736
1731(add-hook 'inferior-python-mode-hook
1732 #'python-ffap-setup)
1733
1734 1737
1735;;; Code check 1738;;; Code check
1736 1739
@@ -1781,16 +1784,6 @@ Runs COMMAND, a shell command, as if by `compile'. See
1781 "__PYDOC_get_help('''%s''')\n" 1784 "__PYDOC_get_help('''%s''')\n"
1782 "Python code used to get a string with the documentation of an object.") 1785 "Python code used to get a string with the documentation of an object.")
1783 1786
1784(defun python-eldoc-setup ()
1785 "Send `python-eldoc-setup-code' to inferior Python process.
1786It is specially designed to be added to the
1787`inferior-python-mode-hook'."
1788 (when (> (length python-eldoc-setup-code) 0)
1789 (python-shell-send-string-no-output
1790 python-eldoc-setup-code
1791 (get-buffer-process (current-buffer)))
1792 (message "Eldoc setup code sent.")))
1793
1794(defun python-eldoc--get-doc-at-point (&optional force-input force-process) 1787(defun python-eldoc--get-doc-at-point (&optional force-input force-process)
1795 "Internal implementation to get documentation at point. 1788 "Internal implementation to get documentation at point.
1796If not FORCE-INPUT is passed then what `current-word' returns 1789If not FORCE-INPUT is passed then what `current-word' returns
@@ -1862,9 +1855,6 @@ Interactively, prompt for symbol."
1862 (python-eldoc--get-doc-at-point symbol process)) 1855 (python-eldoc--get-doc-at-point symbol process))
1863 (help-print-return-message))))))) 1856 (help-print-return-message)))))))
1864 1857
1865(add-hook 'inferior-python-mode-hook
1866 #'python-eldoc-setup)
1867
1868 1858
1869;;; Misc helpers 1859;;; Misc helpers
1870 1860