From: Fabián Ezequiel Gallina Date: Thu, 17 May 2012 03:02:59 +0000 (-0300) Subject: Implemeneted python-shell-clear-latest-output and python-shell-send-and-clear-output X-Git-Tag: emacs-24.2.90~1199^2~613 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=138df813695f6434f986bd1c55dc3005ed32af75;p=emacs.git Implemeneted python-shell-clear-latest-output and python-shell-send-and-clear-output Also Simplified python-shell-completion--get-completions using python-shell-send-and-clear-output --- diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el index 739b137d566..ed6bb3189c9 100644 --- a/lisp/progmodes/python.el +++ b/lisp/progmodes/python.el @@ -1024,7 +1024,7 @@ commands.)" global-proc-buffer-name)))) (defun python-shell-send-string (string &optional process) - "Send STRING to inferior Python process." + "Send STRING to inferior Python PROCESS." (interactive "sPython command: ") (let ((process (or process (python-shell-get-or-create-process)))) (when (called-interactively-p 'interactive) @@ -1085,6 +1085,41 @@ When argument ARG is non-nil sends the innermost defun." full-file-name full-file-name) process))) +(defun python-shell-clear-latest-output () + "Clear latest output from the Python shell. +Return the cleaned output." + (interactive) + (when (and comint-last-output-start + comint-last-prompt-overlay) + (save-excursion + (let* ((last-output-end + (save-excursion + (goto-char + (overlay-start comint-last-prompt-overlay)) + (forward-comment -1) + (point-marker))) + (last-output + (buffer-substring-no-properties + comint-last-output-start last-output-end))) + (when (< 0 (length last-output)) + (goto-char comint-last-output-start) + (delete-region comint-last-output-start last-output-end) + (delete-char -1) + last-output))))) + +(defun python-shell-send-and-clear-output (string process) + "Send STRING to PROCESS and clear the output. +Return the cleaned output." + (interactive) + (python-shell-send-string string process) + (accept-process-output process) + (with-current-buffer (process-buffer process) + (let ((output (python-shell-clear-latest-output))) + (forward-line -1) + (kill-whole-line) + (goto-char (overlay-end comint-last-prompt-overlay)) + output))) + (defun python-shell-switch-to-shell () "Switch to inferior Python process buffer." (interactive) @@ -1146,22 +1181,11 @@ It is specially designed to be added to the (defun python-shell-completion--get-completions (input process) "Retrieve available completions for INPUT using PROCESS." (with-current-buffer (process-buffer process) - (let ((completions)) - (python-shell-send-string - (format python-shell-completion-strings-code input) - process) - (accept-process-output process) - (when comint-last-output-start - (setq completions - (split-string - (buffer-substring-no-properties - comint-last-output-start - (save-excursion - (goto-char comint-last-output-start) - (line-end-position))) - ";\\|\"\\|'\\|(" t)) - (comint-delete-output) - completions)))) + (split-string + (or (python-shell-send-and-clear-output + (format python-shell-completion-strings-code input) + process) "") + ";\\|\"\\|'\\|(" t))) (defun python-shell-completion--get-completion (input completions) "Get completion for INPUT using COMPLETIONS."