From 138df813695f6434f986bd1c55dc3005ed32af75 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Fabi=C3=A1n=20Ezequiel=20Gallina?= Date: Thu, 17 May 2012 00:02:59 -0300 Subject: [PATCH] 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 --- lisp/progmodes/python.el | 58 ++++++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 17 deletions(-) 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." -- 2.39.2