[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r114852: * lisp/progmodes/python.el (python-shell-ge
From: |
Stefan Monnier |
Subject: |
[Emacs-diffs] trunk r114852: * lisp/progmodes/python.el (python-shell-get-buffer): New function. |
Date: |
Wed, 30 Oct 2013 01:28:41 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 114852
revision-id: address@hidden
parent: address@hidden
committer: Stefan Monnier <address@hidden>
branch nick: trunk
timestamp: Tue 2013-10-29 21:28:36 -0400
message:
* lisp/progmodes/python.el (python-shell-get-buffer): New function.
(python-shell-get-process): Use it.
(python-shell-send-string): Always use utf-8 and add a cookie to tell
Python which encoding was used. Don't split-string since we only care
about the first line. Return the temp-file, if applicable.
(python-shell-send-region): Tell compile.el how to turn locations in
the temp-file into locations in the source buffer.
modified:
lisp/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1432
lisp/progmodes/python.el python.el-20091113204419-o5vbwnq5f7feedwu-3008
=== modified file 'lisp/ChangeLog'
--- a/lisp/ChangeLog 2013-10-29 21:05:35 +0000
+++ b/lisp/ChangeLog 2013-10-30 01:28:36 +0000
@@ -1,3 +1,13 @@
+2013-10-30 Stefan Monnier <address@hidden>
+
+ * progmodes/python.el (python-shell-get-buffer): New function.
+ (python-shell-get-process): Use it.
+ (python-shell-send-string): Always use utf-8 and add a cookie to tell
+ Python which encoding was used. Don't split-string since we only care
+ about the first line. Return the temp-file, if applicable.
+ (python-shell-send-region): Tell compile.el how to turn locations in
+ the temp-file into locations in the source buffer.
+
2013-10-29 Stefan Monnier <address@hidden>
* subr.el (undefined): Add missing behavior from the C code for
=== modified file 'lisp/progmodes/python.el'
--- a/lisp/progmodes/python.el 2013-10-07 18:51:26 +0000
+++ b/lisp/progmodes/python.el 2013-10-30 01:28:36 +0000
@@ -1968,17 +1968,21 @@
(python-shell-parse-command)
(python-shell-internal-get-process-name) nil t))))
+(defun python-shell-get-buffer ()
+ "Get inferior Python buffer for current buffer and return it."
+ (let* ((dedicated-proc-name (python-shell-get-process-name t))
+ (dedicated-proc-buffer-name (format "*%s*" dedicated-proc-name))
+ (global-proc-name (python-shell-get-process-name nil))
+ (global-proc-buffer-name (format "*%s*" global-proc-name))
+ (dedicated-running (comint-check-proc dedicated-proc-buffer-name))
+ (global-running (comint-check-proc global-proc-buffer-name)))
+ ;; Always prefer dedicated
+ (or (and dedicated-running dedicated-proc-buffer-name)
+ (and global-running global-proc-buffer-name))))
+
(defun python-shell-get-process ()
"Get inferior Python process for current buffer and return it."
- (let* ((dedicated-proc-name (python-shell-get-process-name t))
- (dedicated-proc-buffer-name (format "*%s*" dedicated-proc-name))
- (global-proc-name (python-shell-get-process-name nil))
- (global-proc-buffer-name (format "*%s*" global-proc-name))
- (dedicated-running (comint-check-proc dedicated-proc-buffer-name))
- (global-running (comint-check-proc global-proc-buffer-name)))
- ;; Always prefer dedicated
- (get-buffer-process (or (and dedicated-running dedicated-proc-buffer-name)
- (and global-running global-proc-buffer-name)))))
+ (get-buffer-process (python-shell-get-buffer)))
(defun python-shell-get-or-create-process ()
"Get or create an inferior Python process for current buffer and return it."
@@ -2034,26 +2038,32 @@
(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."
+When MSG is non-nil messages the first line of STRING.
+If a temp file is used, return its name, otherwise return nil."
(interactive "sPython command: ")
(let ((process (or process (python-shell-get-or-create-process)))
- (lines (split-string string "\n" t)))
- (and msg (message "Sent: %s..." (nth 0 lines)))
- (if (> (length lines) 1)
+ (_ (string-match "\\`\n*\\(.*\\)\\(\n.\\)?" string))
+ (multiline (match-beginning 2)))
+ (and msg (message "Sent: %s..." (match-string 1 string)))
+ (if multiline
(let* ((temporary-file-directory
(if (file-remote-p default-directory)
(concat (file-remote-p default-directory) "/tmp")
temporary-file-directory))
(temp-file-name (make-temp-file "py"))
+ (coding-system-for-write 'utf-8)
(file-name (or (buffer-file-name) temp-file-name)))
(with-temp-file temp-file-name
+ (insert "# -*- coding: utf-8 -*-\n")
(insert string)
(delete-trailing-whitespace))
- (python-shell-send-file file-name process temp-file-name))
+ (python-shell-send-file file-name process temp-file-name)
+ temp-file-name)
(comint-send-string process string)
(when (or (not (string-match "\n$" string))
(string-match "\n[ \t].*\n?$" string))
- (comint-send-string process "\n")))))
+ (comint-send-string process "\n"))
+ nil)))
(defvar python-shell-output-filter-in-progress nil)
(defvar python-shell-output-filter-buffer nil)
@@ -2179,11 +2189,18 @@
(line-number-at-pos if-name-main-start)) ?\n)))))
(buffer-substring-no-properties (point-min) (point-max)))))
+(declare-function compilation-fake-loc "compile"
+ (marker file &optional line col))
+
(defun python-shell-send-region (start end)
"Send the region delimited by START and END to inferior Python process."
(interactive "r")
- (python-shell-send-string
- (python-shell-buffer-substring start end) nil t))
+ (let ((temp-file-name
+ (python-shell-send-string
+ (python-shell-buffer-substring start end) nil t)))
+ (when temp-file-name
+ (with-current-buffer (python-shell-get-buffer)
+ (compilation-fake-loc (copy-marker start) temp-file-name)))))
(defun python-shell-send-buffer (&optional arg)
"Send the entire buffer to inferior Python process.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r114852: * lisp/progmodes/python.el (python-shell-get-buffer): New function.,
Stefan Monnier <=