(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 ">>> "
: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
(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)
+
\f
;;; Shell completion
"';'.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)
(indent-for-tab-command)
(comint-dynamic-complete)))
-(add-hook 'inferior-python-mode-hook
- #'python-shell-completion-setup)
-
\f
;;; PDB Track integration
"__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
(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)
-
\f
;;; Code check
"__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
(python-eldoc--get-doc-at-point symbol process))
(help-print-return-message)))))))
-(add-hook 'inferior-python-mode-hook
- #'python-eldoc-setup)
-
\f
;;; Misc helpers