aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabián Ezequiel Gallina2012-05-17 00:02:59 -0300
committerFabián Ezequiel Gallina2012-05-17 00:02:59 -0300
commit138df813695f6434f986bd1c55dc3005ed32af75 (patch)
treeddc31d9bacbf5c0757aaad20dd67e24cbc6fbdec
parent9e6629387daaee10adb18baa892b4af58d2c5a33 (diff)
downloademacs-138df813695f6434f986bd1c55dc3005ed32af75.tar.gz
emacs-138df813695f6434f986bd1c55dc3005ed32af75.zip
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
-rw-r--r--lisp/progmodes/python.el58
1 files 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.)"
1024 global-proc-buffer-name)))) 1024 global-proc-buffer-name))))
1025 1025
1026(defun python-shell-send-string (string &optional process) 1026(defun python-shell-send-string (string &optional process)
1027 "Send STRING to inferior Python process." 1027 "Send STRING to inferior Python PROCESS."
1028 (interactive "sPython command: ") 1028 (interactive "sPython command: ")
1029 (let ((process (or process (python-shell-get-or-create-process)))) 1029 (let ((process (or process (python-shell-get-or-create-process))))
1030 (when (called-interactively-p 'interactive) 1030 (when (called-interactively-p 'interactive)
@@ -1085,6 +1085,41 @@ When argument ARG is non-nil sends the innermost defun."
1085 full-file-name full-file-name) 1085 full-file-name full-file-name)
1086 process))) 1086 process)))
1087 1087
1088(defun python-shell-clear-latest-output ()
1089 "Clear latest output from the Python shell.
1090Return the cleaned output."
1091 (interactive)
1092 (when (and comint-last-output-start
1093 comint-last-prompt-overlay)
1094 (save-excursion
1095 (let* ((last-output-end
1096 (save-excursion
1097 (goto-char
1098 (overlay-start comint-last-prompt-overlay))
1099 (forward-comment -1)
1100 (point-marker)))
1101 (last-output
1102 (buffer-substring-no-properties
1103 comint-last-output-start last-output-end)))
1104 (when (< 0 (length last-output))
1105 (goto-char comint-last-output-start)
1106 (delete-region comint-last-output-start last-output-end)
1107 (delete-char -1)
1108 last-output)))))
1109
1110(defun python-shell-send-and-clear-output (string process)
1111 "Send STRING to PROCESS and clear the output.
1112Return the cleaned output."
1113 (interactive)
1114 (python-shell-send-string string process)
1115 (accept-process-output process)
1116 (with-current-buffer (process-buffer process)
1117 (let ((output (python-shell-clear-latest-output)))
1118 (forward-line -1)
1119 (kill-whole-line)
1120 (goto-char (overlay-end comint-last-prompt-overlay))
1121 output)))
1122
1088(defun python-shell-switch-to-shell () 1123(defun python-shell-switch-to-shell ()
1089 "Switch to inferior Python process buffer." 1124 "Switch to inferior Python process buffer."
1090 (interactive) 1125 (interactive)
@@ -1146,22 +1181,11 @@ It is specially designed to be added to the
1146(defun python-shell-completion--get-completions (input process) 1181(defun python-shell-completion--get-completions (input process)
1147 "Retrieve available completions for INPUT using PROCESS." 1182 "Retrieve available completions for INPUT using PROCESS."
1148 (with-current-buffer (process-buffer process) 1183 (with-current-buffer (process-buffer process)
1149 (let ((completions)) 1184 (split-string
1150 (python-shell-send-string 1185 (or (python-shell-send-and-clear-output
1151 (format python-shell-completion-strings-code input) 1186 (format python-shell-completion-strings-code input)
1152 process) 1187 process) "")
1153 (accept-process-output process) 1188 ";\\|\"\\|'\\|(" t)))
1154 (when comint-last-output-start
1155 (setq completions
1156 (split-string
1157 (buffer-substring-no-properties
1158 comint-last-output-start
1159 (save-excursion
1160 (goto-char comint-last-output-start)
1161 (line-end-position)))
1162 ";\\|\"\\|'\\|(" t))
1163 (comint-delete-output)
1164 completions))))
1165 1189
1166(defun python-shell-completion--get-completion (input completions) 1190(defun python-shell-completion--get-completion (input completions)
1167 "Get completion for INPUT using COMPLETIONS." 1191 "Get completion for INPUT using COMPLETIONS."