Shell processes: enhancements to startup and CEDET compatibility.

* progmodes/python.el (python-shell-send-setup-max-wait): Delete var.
(python-shell-make-comint): accept-process-output at startup.
(run-python-internal): Set inferior-python-mode-hook to nil.
(python-shell-internal-get-or-create-process): call sit-for.
(python-preoutput-result): Add obsolete alias.
(python-shell-internal-send-string): Use it.
(python-shell-send-setup-code): Remove call to
accept-process-output.
This commit is contained in:
Fabián Ezequiel Gallina 2012-07-31 20:43:31 -03:00
parent bc96620af4
commit 0d49da68b9
2 changed files with 53 additions and 28 deletions

View file

@ -1,3 +1,15 @@
2012-07-31 Fabián Ezequiel Gallina <fgallina@cuca>
Shell processes: enhancements to startup and CEDET compatibility.
* progmodes/python.el (python-shell-send-setup-max-wait): Delete var.
(python-shell-make-comint): accept-process-output at startup.
(run-python-internal): Set inferior-python-mode-hook to nil.
(python-shell-internal-get-or-create-process): call sit-for.
(python-preoutput-result): Add obsolete alias.
(python-shell-internal-send-string): Use it.
(python-shell-send-setup-code): Remove call to
accept-process-output.
2012-07-31 Andreas Schwab <schwab@linux-m68k.org>
* buff-menu.el (list-buffers-noselect): Use prefix-numeric-value.

View file

@ -1354,14 +1354,6 @@ Restart the python shell after changing this variable for it to take effect."
:group 'python
:safe 'booleanp)
(defcustom python-shell-send-setup-max-wait 5
"Seconds to wait for process output before code setup.
If output is received before the specified time then control is
returned in that moment and not after waiting."
:type 'integer
:group 'python
:safe 'integerp)
(defcustom python-shell-process-environment nil
"List of environment variables for Python shell.
This variable follows the same rules as `process-environment'
@ -1571,7 +1563,8 @@ non-nil the buffer is shown."
(current-buffer (current-buffer)))
(with-current-buffer buffer
(inferior-python-mode)
(python-util-clone-local-variables current-buffer))))
(python-util-clone-local-variables current-buffer))
(accept-process-output (get-buffer-process buffer))))
(and pop (pop-to-buffer proc-buffer-name t))
proc-buffer-name)))
@ -1605,17 +1598,19 @@ process buffer for a list of commands.)"
"Run an inferior Internal Python process.
Input and output via buffer named after
`python-shell-internal-buffer-name' and what
`python-shell-internal-get-process-name' returns. This new kind
of shell is intended to be used for generic communication related
to defined configurations. The main difference with global or
dedicated shells is that these ones are attached to a
configuration, not a buffer. This means that can be used for
example to retrieve the sys.path and other stuff, without messing
with user shells. Runs the hook
`inferior-python-mode-hook' (after the `comint-mode-hook' is
run). \(Type \\[describe-mode] in the process buffer for a list
of commands.)"
(let ((python-shell-enable-font-lock nil))
`python-shell-internal-get-process-name' returns.
This new kind of shell is intended to be used for generic
communication related to defined configurations, the main
difference with global or dedicated shells is that these ones are
attached to a configuration, not a buffer. This means that can
be used for example to retrieve the sys.path and other stuff,
without messing with user shells. Note that
`python-shell-enable-font-lock' and `inferior-python-mode-hook'
are set to nil for these shells, so setup codes are not sent at
startup."
(let ((python-shell-enable-font-lock nil)
(inferior-python-mode-hook nil))
(set-process-query-on-exit-flag
(get-buffer-process
(python-shell-make-comint
@ -1658,12 +1653,25 @@ This is really not necessary at all for the code to work but it's
there for compatibility with CEDET.")
(make-variable-buffer-local 'python-shell-internal-buffer)
(defvar python-shell-internal-last-output nil
"Last output captured by the internal shell.
This is really not necessary at all for the code to work but it's
there for compatibility with CEDET.")
(make-variable-buffer-local 'python-shell-internal-last-output)
(defun python-shell-internal-get-or-create-process ()
"Get or create an inferior Internal Python process."
(let* ((proc-name (python-shell-internal-get-process-name))
(proc-buffer-name (format "*%s*" proc-name)))
(run-python-internal)
(setq python-shell-internal-buffer proc-buffer-name)
(when (not (process-live-p proc-name))
(run-python-internal)
(setq python-shell-internal-buffer proc-buffer-name)
;; XXX: Why is this `sit-for' needed?
;; `python-shell-make-comint' calls `accept-process-output'
;; already but it is not helping to get proper output on
;; 'gnu/linux when the internal shell process is not running and
;; a call to `python-shell-internal-send-string' is issued.
(sit-for 0.1 t))
(get-buffer-process proc-buffer-name)))
(define-obsolete-function-alias
@ -1672,6 +1680,9 @@ there for compatibility with CEDET.")
(define-obsolete-variable-alias
'python-buffer 'python-shell-internal-buffer "24.2")
(define-obsolete-variable-alias
'python-preoutput-result 'python-shell-internal-last-output "24.2")
(defun python-shell-send-string (string &optional process msg)
"Send STRING to inferior Python PROCESS.
When MSG is non-nil messages the first line of STRING."
@ -1723,11 +1734,14 @@ the output."
(defun python-shell-internal-send-string (string)
"Send STRING to the Internal Python interpreter.
Returns the output. See `python-shell-send-string-no-output'."
(python-shell-send-string-no-output
;; Makes this function compatible with the old
;; python-send-receive. (At least for CEDET).
(replace-regexp-in-string "_emacs_out +" "" string)
(python-shell-internal-get-or-create-process) nil))
;; XXX Remove `python-shell-internal-last-output' once CEDET is
;; updated to support this new mode.
(setq python-shell-internal-last-output
(python-shell-send-string-no-output
;; Makes this function compatible with the old
;; python-send-receive. (At least for CEDET).
(replace-regexp-in-string "_emacs_out +" "" string)
(python-shell-internal-get-or-create-process) nil)))
(define-obsolete-function-alias
'python-send-receive 'python-shell-internal-send-string "24.2")
@ -1808,7 +1822,6 @@ 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 python-shell-send-setup-max-wait)
(dolist (code python-shell-setup-codes)
(when code
(message (format msg code))