aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlenn Morris2014-07-21 02:03:08 -0400
committerGlenn Morris2014-07-21 02:03:08 -0400
commit190644a0115a592f237b5f7c91f0f96e82edb864 (patch)
treed3a5848df4a3f2fe4e67be8032c9195db0df4985
parent4d6abf2449a4c4da10949b50510b90d6d019ae7c (diff)
parentef3b7194838482c4bcb55beb951f3a8e2e0f44ac (diff)
downloademacs-190644a0115a592f237b5f7c91f0f96e82edb864.tar.gz
emacs-190644a0115a592f237b5f7c91f0f96e82edb864.zip
Merge from emacs-24; up to 2014-06-25T10:17:41Z!rgm@gnu.org
-rw-r--r--doc/emacs/ChangeLog4
-rw-r--r--doc/emacs/emacs.texi11
-rw-r--r--etc/NEWS16
-rw-r--r--lisp/ChangeLog64
-rw-r--r--lisp/bindings.el2
-rw-r--r--lisp/bs.el2
-rw-r--r--lisp/buff-menu.el2
-rw-r--r--lisp/dired.el2
-rw-r--r--lisp/files.el8
-rw-r--r--lisp/progmodes/hideif.el5
-rw-r--r--lisp/progmodes/python.el507
-rw-r--r--lisp/view.el6
-rw-r--r--src/ChangeLog34
-rw-r--r--src/macfont.h1
-rw-r--r--src/macfont.m2
-rw-r--r--src/nsterm.h1
-rw-r--r--src/nsterm.m21
-rw-r--r--src/w16select.c2
-rw-r--r--src/w32select.c2
-rw-r--r--src/xdisp.c31
-rw-r--r--test/ChangeLog36
-rw-r--r--test/automated/python-tests.el488
22 files changed, 1045 insertions, 202 deletions
diff --git a/doc/emacs/ChangeLog b/doc/emacs/ChangeLog
index a9c4995d49b..a1d2688470d 100644
--- a/doc/emacs/ChangeLog
+++ b/doc/emacs/ChangeLog
@@ -1,3 +1,7 @@
12014-07-21 Glenn Morris <rgm@gnu.org>
2
3 * emacs.texi (Intro): Workaround makeinfo 4 @acronym bug. (Bug#18040)
4
12014-07-09 Juri Linkov <juri@jurta.org> 52014-07-09 Juri Linkov <juri@jurta.org>
2 6
3 * search.texi (Regexp Search): Update lax space matching that is 7 * search.texi (Regexp Search): Update lax space matching that is
diff --git a/doc/emacs/emacs.texi b/doc/emacs/emacs.texi
index 51e226dd388..b1cb196c3c2 100644
--- a/doc/emacs/emacs.texi
+++ b/doc/emacs/emacs.texi
@@ -1476,7 +1476,16 @@ Neal Ziring, Teodor Zlatanov, and Detlev Zundel.
1476 1476
1477 You are reading about GNU Emacs, the GNU incarnation of the 1477 You are reading about GNU Emacs, the GNU incarnation of the
1478advanced, self-documenting, customizable, extensible editor Emacs. 1478advanced, self-documenting, customizable, extensible editor Emacs.
1479(The @samp{G} in @acronym{GNU, @acronym{GNU}'s Not Unix} is not silent.) 1479(The @samp{G} in
1480@c Workaround makeinfo 4 bug.
1481@c http://lists.gnu.org/archive/html/bug-texinfo/2004-08/msg00009.html
1482@iftex
1483@acronym{GNU, @acronym{GNU}'s Not Unix}
1484@end iftex
1485@ifnottex
1486@acronym{GNU, GNU's Not Unix}
1487@end ifnottex
1488is not silent.)
1480 1489
1481 We call Emacs @dfn{advanced} because it can do much more than simple 1490 We call Emacs @dfn{advanced} because it can do much more than simple
1482insertion and deletion of text. It can control subprocesses, indent 1491insertion and deletion of text. It can control subprocesses, indent
diff --git a/etc/NEWS b/etc/NEWS
index 1a86f41314e..558e1608dfb 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -870,6 +870,22 @@ display a "Homepage" header.)
870** In Prolog mode, `prolog-use-smie' has been removed, 870** In Prolog mode, `prolog-use-smie' has been removed,
871along with the non-SMIE indentation code. 871along with the non-SMIE indentation code.
872 872
873** Python mode
874
875*** Out of the box support for CPython, iPython and readline based shells.
876**** `python-shell-completion-module-string-code` is no longer used.
877
878*** Automatic shell prompt detection. New user options:
879**** `python-shell-interpreter-interactive-arg'.
880**** `python-shell-prompt-detect-enabled'.
881**** `python-shell-prompt-detect-failure-warning'.
882**** `python-shell-prompt-input-regexps'.
883**** `python-shell-prompt-output-regexps'.
884
885*** Python shell support for remote hosts via tramp.
886
887*** Correct display of line numbers for code sent to the Python shell.
888
873** Remember 889** Remember
874 890
875*** The new command `remember-notes' creates a buffer that is saved on exit. 891*** The new command `remember-notes' creates a buffer that is saved on exit.
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 5ed7d6918d3..1c557c91602 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,67 @@
12014-07-21 Glenn Morris <rgm@gnu.org>
2
3 * progmodes/hideif.el (hide-ifdef-mode-submap):
4 Also substitute read-only-mode.
5 * bindings.el (mode-line-toggle-read-only):
6 * bs.el (bs-toggle-readonly):
7 * buff-menu.el (Buffer-menu-toggle-read-only):
8 * dired.el (dired-toggle-read-only):
9 * files.el (view-read-only, find-file-read-only)
10 (find-file-read-only-other-window)
11 (find-file-read-only-other-frame):
12 * progmodes/hideif.el (hide-ifdef-toggle-outside-read-only):
13 Doc fixes re toggle-read-only.
14
152014-07-21 Fabián Ezequiel Gallina <fgallina@gnu.org>
16
17 * progmodes/python.el: Add comment about pipe buffering and
18 solutions for missing/delayed output in inferior Python shells.
19 (Bug#17304)
20
21 * progmodes/python.el (python-mode): Don't set
22 mode-require-final-newline. (Bug#17990)
23
24 Make python.el work with IPython automatically. (Bug#15510)
25 * progmodes/python.el:
26 (python-shell-completion-setup-code): New value supporting iPython.
27 (python-shell-completion-string-code): New value supporting iPython.
28 (python-shell-completion-get-completions): Use them.
29 (python-shell-completion-module-string-code): Make obsolete.
30 (python-shell-prompt-input-regexps)
31 (python-shell-prompt-output-regexps): Add safeguard for ipdb.
32 (python-shell-output-filter): Fix comment typo.
33
34 Fix Python shell prompts detection for remote hosts.
35 * progmodes/python.el (python-shell-prompt-detect): Replace
36 call-process with process-file and make it more robust.
37
38 Autodetect Python shell prompts. (Bug#17370)
39 * progmodes/python.el:
40 (python-shell-interpreter-interactive-arg)
41 (python-shell-prompt-detect-enabled)
42 (python-shell-prompt-detect-failure-warning)
43 (python-shell-prompt-input-regexps)
44 (python-shell-prompt-output-regexps): New vars.
45 (python-shell-prompt-calculated-input-regexp)
46 (python-shell-prompt-calculated-output-regexp): New vars.
47 (python-shell-get-process-name)
48 (python-shell-internal-get-process-name)
49 (python-shell-output-filter)
50 (python-shell-completion-get-completions): Use them.
51 (python-shell-prompt-detect)
52 (python-shell-prompt-validate-regexps): New functions.
53 (python-shell-prompt-set-calculated-regexps): New function.
54 (inferior-python-mode): Use it. Also honor overriden
55 python-shell-interpreter and python-shell-interpreter-args.
56 (python-shell-make-comint): Honor overriden
57 python-shell-interpreter and python-shell-interpreter-args.
58 (python-shell-get-or-create-process): Make it testable by allowing
59 to call run-python non-interactively.
60 (python-util-valid-regexp-p): New function.
61 (python-shell-prompt-regexp, python-shell-prompt-block-regexp)
62 (python-shell-prompt-output-regexp)
63 (python-shell-prompt-pdb-regexp): Use it as defcustom :safe.
64
12014-07-21 Stefan Monnier <monnier@iro.umontreal.ca> 652014-07-21 Stefan Monnier <monnier@iro.umontreal.ca>
2 66
3 * emacs-lisp/smie.el (smie-config--guess-1): Split from 67 * emacs-lisp/smie.el (smie-config--guess-1): Split from
diff --git a/lisp/bindings.el b/lisp/bindings.el
index 911ab63e8d0..ac31723e02d 100644
--- a/lisp/bindings.el
+++ b/lisp/bindings.el
@@ -36,7 +36,7 @@ corresponding to the mode line clicked."
36 36
37 37
38(defun mode-line-toggle-read-only (event) 38(defun mode-line-toggle-read-only (event)
39 "Like `toggle-read-only', for the mode-line." 39 "Like toggling `read-only-mode', for the mode-line."
40 (interactive "e") 40 (interactive "e")
41 (with-selected-window (posn-window (event-start event)) 41 (with-selected-window (posn-window (event-start event))
42 (read-only-mode 'toggle))) 42 (read-only-mode 'toggle)))
diff --git a/lisp/bs.el b/lisp/bs.el
index 73b3684e566..5e9c6908f28 100644
--- a/lisp/bs.el
+++ b/lisp/bs.el
@@ -954,7 +954,7 @@ Default is `bs--current-sort-function'."
954 954
955(defun bs-toggle-readonly () 955(defun bs-toggle-readonly ()
956 "Toggle read-only status for buffer on current line. 956 "Toggle read-only status for buffer on current line.
957Uses function `toggle-read-only'." 957Uses function `read-only-mode'."
958 (interactive) 958 (interactive)
959 (with-current-buffer (bs--current-buffer) 959 (with-current-buffer (bs--current-buffer)
960 (read-only-mode 'toggle)) 960 (read-only-mode 'toggle))
diff --git a/lisp/buff-menu.el b/lisp/buff-menu.el
index d85caca6216..f1772b3d20c 100644
--- a/lisp/buff-menu.el
+++ b/lisp/buff-menu.el
@@ -539,7 +539,7 @@ The current window remains selected."
539 539
540(defun Buffer-menu-toggle-read-only () 540(defun Buffer-menu-toggle-read-only ()
541 "Toggle read-only status of buffer on this line. 541 "Toggle read-only status of buffer on this line.
542This behaves like invoking \\[toggle-read-only] in that buffer." 542This behaves like invoking \\[read-only-mode] in that buffer."
543 (interactive) 543 (interactive)
544 (let ((read-only 544 (let ((read-only
545 (with-current-buffer (Buffer-menu-buffer t) 545 (with-current-buffer (Buffer-menu-buffer t)
diff --git a/lisp/dired.el b/lisp/dired.el
index 25b70219c7d..4cc252c7492 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -2015,7 +2015,7 @@ Actual changes in files cannot be undone by Emacs."))
2015 "Edit Dired buffer with Wdired, or make it read-only. 2015 "Edit Dired buffer with Wdired, or make it read-only.
2016If the current buffer can be edited with Wdired, (i.e. the major 2016If the current buffer can be edited with Wdired, (i.e. the major
2017mode is `dired-mode'), call `wdired-change-to-wdired-mode'. 2017mode is `dired-mode'), call `wdired-change-to-wdired-mode'.
2018Otherwise, call `toggle-read-only'." 2018Otherwise, toggle `read-only-mode'."
2019 (interactive) 2019 (interactive)
2020 (if (derived-mode-p 'dired-mode) 2020 (if (derived-mode-p 'dired-mode)
2021 (wdired-change-to-wdired-mode) 2021 (wdired-change-to-wdired-mode)
diff --git a/lisp/files.el b/lisp/files.el
index d3aa063e788..252ae76fa0b 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -564,7 +564,7 @@ A value of nil means ignore them; anything else means query."
564In fact, this means that all read-only buffers normally have 564In fact, this means that all read-only buffers normally have
565View mode enabled, including buffers that are read-only because 565View mode enabled, including buffers that are read-only because
566you visit a file you cannot alter, and buffers you make read-only 566you visit a file you cannot alter, and buffers you make read-only
567using \\[toggle-read-only]." 567using \\[read-only-mode]."
568 :type 'boolean 568 :type 'boolean
569 :group 'view) 569 :group 'view)
570 570
@@ -1502,7 +1502,7 @@ file names with wildcards."
1502(defun find-file-read-only (filename &optional wildcards) 1502(defun find-file-read-only (filename &optional wildcards)
1503 "Edit file FILENAME but don't allow changes. 1503 "Edit file FILENAME but don't allow changes.
1504Like \\[find-file], but marks buffer as read-only. 1504Like \\[find-file], but marks buffer as read-only.
1505Use \\[toggle-read-only] to permit editing." 1505Use \\[read-only-mode] to permit editing."
1506 (interactive 1506 (interactive
1507 (find-file-read-args "Find file read-only: " 1507 (find-file-read-args "Find file read-only: "
1508 (confirm-nonexistent-file-or-buffer))) 1508 (confirm-nonexistent-file-or-buffer)))
@@ -1511,7 +1511,7 @@ Use \\[toggle-read-only] to permit editing."
1511(defun find-file-read-only-other-window (filename &optional wildcards) 1511(defun find-file-read-only-other-window (filename &optional wildcards)
1512 "Edit file FILENAME in another window but don't allow changes. 1512 "Edit file FILENAME in another window but don't allow changes.
1513Like \\[find-file-other-window], but marks buffer as read-only. 1513Like \\[find-file-other-window], but marks buffer as read-only.
1514Use \\[toggle-read-only] to permit editing." 1514Use \\[read-only-mode] to permit editing."
1515 (interactive 1515 (interactive
1516 (find-file-read-args "Find file read-only other window: " 1516 (find-file-read-args "Find file read-only other window: "
1517 (confirm-nonexistent-file-or-buffer))) 1517 (confirm-nonexistent-file-or-buffer)))
@@ -1520,7 +1520,7 @@ Use \\[toggle-read-only] to permit editing."
1520(defun find-file-read-only-other-frame (filename &optional wildcards) 1520(defun find-file-read-only-other-frame (filename &optional wildcards)
1521 "Edit file FILENAME in another frame but don't allow changes. 1521 "Edit file FILENAME in another frame but don't allow changes.
1522Like \\[find-file-other-frame], but marks buffer as read-only. 1522Like \\[find-file-other-frame], but marks buffer as read-only.
1523Use \\[toggle-read-only] to permit editing." 1523Use \\[read-only-mode] to permit editing."
1524 (interactive 1524 (interactive
1525 (find-file-read-args "Find file read-only other frame: " 1525 (find-file-read-args "Find file read-only other frame: "
1526 (confirm-nonexistent-file-or-buffer))) 1526 (confirm-nonexistent-file-or-buffer)))
diff --git a/lisp/progmodes/hideif.el b/lisp/progmodes/hideif.el
index d60c009e66d..b1eaa6ad66c 100644
--- a/lisp/progmodes/hideif.el
+++ b/lisp/progmodes/hideif.el
@@ -189,6 +189,9 @@ Effective only if `hide-ifdef-expand-reinclusion-protection' is t."
189 (define-key map "\C-q" 'hide-ifdef-toggle-read-only) 189 (define-key map "\C-q" 'hide-ifdef-toggle-read-only)
190 (define-key map "\C-w" 'hide-ifdef-toggle-shadowing) 190 (define-key map "\C-w" 'hide-ifdef-toggle-shadowing)
191 (substitute-key-definition 191 (substitute-key-definition
192 'read-only-mode 'hide-ifdef-toggle-outside-read-only map)
193 ;; `toggle-read-only' is obsoleted by `read-only-mode'.
194 (substitute-key-definition
192 'toggle-read-only 'hide-ifdef-toggle-outside-read-only map) 195 'toggle-read-only 'hide-ifdef-toggle-outside-read-only map)
193 map) 196 map)
194 "Keymap used by `hide-ifdef-mode' under `hide-ifdef-mode-prefix-key'.") 197 "Keymap used by `hide-ifdef-mode' under `hide-ifdef-mode-prefix-key'.")
@@ -1789,7 +1792,7 @@ It does not do the work that's pointless to redo on a recursive entry."
1789 (force-mode-line-update)) 1792 (force-mode-line-update))
1790 1793
1791(defun hide-ifdef-toggle-outside-read-only () 1794(defun hide-ifdef-toggle-outside-read-only ()
1792 "Replacement for `toggle-read-only' within Hide-Ifdef mode." 1795 "Replacement for `read-only-mode' within Hide-Ifdef mode."
1793 (interactive) 1796 (interactive)
1794 (setq hif-outside-read-only (not hif-outside-read-only)) 1797 (setq hif-outside-read-only (not hif-outside-read-only))
1795 (message "Read only %s" 1798 (message "Read only %s"
diff --git a/lisp/progmodes/python.el b/lisp/progmodes/python.el
index 1187636c663..89ef12d49eb 100644
--- a/lisp/progmodes/python.el
+++ b/lisp/progmodes/python.el
@@ -4,7 +4,7 @@
4 4
5;; Author: Fabián E. Gallina <fabian@anue.biz> 5;; Author: Fabián E. Gallina <fabian@anue.biz>
6;; URL: https://github.com/fgallina/python.el 6;; URL: https://github.com/fgallina/python.el
7;; Version: 0.24.2 7;; Version: 0.24.4
8;; Maintainer: emacs-devel@gnu.org 8;; Maintainer: emacs-devel@gnu.org
9;; Created: Jul 2010 9;; Created: Jul 2010
10;; Keywords: languages 10;; Keywords: languages
@@ -62,57 +62,80 @@
62;; (add-hook 'python-mode-hook 62;; (add-hook 'python-mode-hook
63;; (lambda () (setq forward-sexp-function nil))) 63;; (lambda () (setq forward-sexp-function nil)))
64 64
65;; Shell interaction: is provided and allows you to execute easily any 65;; Shell interaction: is provided and allows opening Python shells
66;; block of code of your current buffer in an inferior Python process. 66;; inside Emacs and executing any block of code of your current buffer
67;; in that inferior Python process.
68
69;; Besides that only the standard CPython (2.x and 3.x) shell and
70;; IPython are officially supported out of the box, the interaction
71;; should support any other readline based Python shells as well
72;; (e.g. Jython and Pypy have been reported to work). You can change
73;; your default interpreter and commandline arguments by setting the
74;; `python-shell-interpreter' and `python-shell-interpreter-args'
75;; variables. This example enables IPython globally:
76
77;; (setq python-shell-interpreter "ipython"
78;; python-shell-interpreter-args "-i")
79
80;; Using the "console" subcommand to start IPython in server-client
81;; mode is known to fail intermittently due a bug on IPython itself
82;; (see URL `http://debbugs.gnu.org/cgi/bugreport.cgi?bug=18052#27').
83;; There seems to be a race condition in the IPython server (A.K.A
84;; kernel) when code is sent while it is still initializing, sometimes
85;; causing the shell to get stalled. With that said, if an IPython
86;; kernel is already running, "console --existing" seems to work fine.
87
88;; Running IPython on Windows needs more tweaking. The way you should
89;; set `python-shell-interpreter' and `python-shell-interpreter-args'
90;; is as follows (of course you need to modify the paths according to
91;; your system):
92
93;; (setq python-shell-interpreter "C:\\Python27\\python.exe"
94;; python-shell-interpreter-args
95;; "-i C:\\Python27\\Scripts\\ipython-script.py")
96
97;; If you are experiencing missing or delayed output in your shells,
98;; that's likely caused by your Operating System's pipe buffering
99;; (e.g. this is known to happen running CPython 3.3.4 in Windows 7.
100;; See URL `http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17304'). To
101;; fix this, using CPython's "-u" commandline argument or setting the
102;; "PYTHONUNBUFFERED" environment variable should help: See URL
103;; `https://docs.python.org/3/using/cmdline.html#cmdoption-u'.
104
105;; The interaction relies upon having prompts for input (e.g. ">>> "
106;; and "... " in standard Python shell) and output (e.g. "Out[1]: " in
107;; IPython) detected properly. Failing that Emacs may hang but, in
108;; the case that happens, you can recover with \\[keyboard-quit]. To
109;; avoid this issue, a two-step prompt autodetection mechanism is
110;; provided: the first step is manual and consists of a collection of
111;; regular expressions matching common prompts for Python shells
112;; stored in `python-shell-prompt-input-regexps' and
113;; `python-shell-prompt-output-regexps', and dir-local friendly vars
114;; `python-shell-prompt-regexp', `python-shell-prompt-block-regexp',
115;; `python-shell-prompt-output-regexp' which are appended to the
116;; former automatically when a shell spawns; the second step is
117;; automatic and depends on the `python-shell-prompt-detect' helper
118;; function. See its docstring for details on global variables that
119;; modify its behavior.
67 120
68;; Shell completion: hitting tab will try to complete the current 121;; Shell completion: hitting tab will try to complete the current
69;; word. Shell completion is implemented in a manner that if you 122;; word. Shell completion is implemented in such way that if you
70;; change the `python-shell-interpreter' to any other (for example 123;; change the `python-shell-interpreter' it should be possible to
71;; IPython) it should be easy to integrate another way to calculate 124;; integrate custom logic to calculate completions. To achieve this
72;; completions. You just need to specify your custom 125;; you just need to set `python-shell-completion-setup-code' and
73;; `python-shell-completion-setup-code' and 126;; `python-shell-completion-string-code'. The default provided code,
74;; `python-shell-completion-string-code'. 127;; enables autocompletion for both CPython and IPython (and ideally
75 128;; any readline based Python shell). This code depends on the
76;; Here is a complete example of the settings you would use for
77;; iPython 0.11:
78
79;; (setq
80;; python-shell-interpreter "ipython"
81;; python-shell-interpreter-args ""
82;; python-shell-prompt-regexp "In \\[[0-9]+\\]: "
83;; python-shell-prompt-output-regexp "Out\\[[0-9]+\\]: "
84;; python-shell-completion-setup-code
85;; "from IPython.core.completerlib import module_completion"
86;; python-shell-completion-module-string-code
87;; "';'.join(module_completion('''%s'''))\n"
88;; python-shell-completion-string-code
89;; "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
90
91;; For iPython 0.10 everything would be the same except for
92;; `python-shell-completion-string-code' and
93;; `python-shell-completion-module-string-code':
94
95;; (setq python-shell-completion-string-code
96;; "';'.join(__IP.complete('''%s'''))\n"
97;; python-shell-completion-module-string-code "")
98
99;; Unfortunately running iPython on Windows needs some more tweaking.
100;; The way you must set `python-shell-interpreter' and
101;; `python-shell-interpreter-args' is as follows:
102
103;; (setq
104;; python-shell-interpreter "C:\\Python27\\python.exe"
105;; python-shell-interpreter-args
106;; "-i C:\\Python27\\Scripts\\ipython-script.py")
107
108;; That will spawn the iPython process correctly (Of course you need
109;; to modify the paths according to your system).
110
111;; Please note that the default completion system depends on the
112;; readline module, so if you are using some Operating System that 129;; readline module, so if you are using some Operating System that
113;; bundles Python without it (like Windows) just install the 130;; bundles Python without it (like Windows), installing pyreadline
114;; pyreadline from http://ipython.scipy.org/moin/PyReadline/Intro and 131;; from URL `http://ipython.scipy.org/moin/PyReadline/Intro' should
115;; you should be good to go. 132;; suffice. To troubleshoot why you are not getting any completions
133;; you can try the following in your Python shell:
134
135;; >>> import readline, rlcompleter
136
137;; If you see an error, then you need to either install pyreadline or
138;; setup custom code that avoids that dependency.
116 139
117;; Shell virtualenv support: The shell also contains support for 140;; Shell virtualenv support: The shell also contains support for
118;; virtualenvs and other special environment modifications thanks to 141;; virtualenvs and other special environment modifications thanks to
@@ -211,7 +234,9 @@
211;;; Code: 234;;; Code:
212 235
213(require 'ansi-color) 236(require 'ansi-color)
237(require 'cl-lib)
214(require 'comint) 238(require 'comint)
239(require 'json)
215 240
216;; Avoid compiler warnings 241;; Avoid compiler warnings
217(defvar view-return-to-alist) 242(defvar view-return-to-alist)
@@ -1705,33 +1730,60 @@ position, else returns nil."
1705 :type 'string 1730 :type 'string
1706 :group 'python) 1731 :group 'python)
1707 1732
1733(defcustom python-shell-interpreter-interactive-arg "-i"
1734 "Interpreter argument to force it to run interactively."
1735 :type 'string
1736 :version "24.4")
1737
1738(defcustom python-shell-prompt-detect-enabled t
1739 "Non-nil enables autodetection of interpreter prompts."
1740 :type 'boolean
1741 :safe 'booleanp
1742 :version "24.4")
1743
1744(defcustom python-shell-prompt-detect-failure-warning t
1745 "Non-nil enables warnings when detection of prompts fail."
1746 :type 'boolean
1747 :safe 'booleanp
1748 :version "24.4")
1749
1750(defcustom python-shell-prompt-input-regexps
1751 '(">>> " "\\.\\.\\. " ; Python
1752 "In \\[[0-9]+\\]: " ; IPython
1753 ;; Using ipdb outside IPython may fail to cleanup and leave static
1754 ;; IPython prompts activated, this adds some safeguard for that.
1755 "In : " "\\.\\.\\.: ")
1756 "List of regular expressions matching input prompts."
1757 :type '(repeat string)
1758 :version "24.4")
1759
1760(defcustom python-shell-prompt-output-regexps
1761 '("" ; Python
1762 "Out\\[[0-9]+\\]: " ; IPython
1763 "Out :") ; ipdb safeguard
1764 "List of regular expressions matching output prompts."
1765 :type '(repeat string)
1766 :version "24.4")
1767
1708(defcustom python-shell-prompt-regexp ">>> " 1768(defcustom python-shell-prompt-regexp ">>> "
1709 "Regular expression matching top-level input prompt of Python shell. 1769 "Regular expression matching top level input prompt of Python shell.
1710It should not contain a caret (^) at the beginning." 1770It should not contain a caret (^) at the beginning."
1711 :type 'string 1771 :type 'string)
1712 :group 'python
1713 :safe 'stringp)
1714 1772
1715(defcustom python-shell-prompt-block-regexp "[.][.][.] " 1773(defcustom python-shell-prompt-block-regexp "\\.\\.\\. "
1716 "Regular expression matching block input prompt of Python shell. 1774 "Regular expression matching block input prompt of Python shell.
1717It should not contain a caret (^) at the beginning." 1775It should not contain a caret (^) at the beginning."
1718 :type 'string 1776 :type 'string)
1719 :group 'python
1720 :safe 'stringp)
1721 1777
1722(defcustom python-shell-prompt-output-regexp "" 1778(defcustom python-shell-prompt-output-regexp ""
1723 "Regular expression matching output prompt of Python shell. 1779 "Regular expression matching output prompt of Python shell.
1724It should not contain a caret (^) at the beginning." 1780It should not contain a caret (^) at the beginning."
1725 :type 'string 1781 :type 'string)
1726 :group 'python
1727 :safe 'stringp)
1728 1782
1729(defcustom python-shell-prompt-pdb-regexp "[(<]*[Ii]?[Pp]db[>)]+ " 1783(defcustom python-shell-prompt-pdb-regexp "[(<]*[Ii]?[Pp]db[>)]+ "
1730 "Regular expression matching pdb input prompt of Python shell. 1784 "Regular expression matching pdb input prompt of Python shell.
1731It should not contain a caret (^) at the beginning." 1785It should not contain a caret (^) at the beginning."
1732 :type 'string 1786 :type 'string)
1733 :group 'python
1734 :safe 'stringp)
1735 1787
1736(defcustom python-shell-enable-font-lock t 1788(defcustom python-shell-enable-font-lock t
1737 "Should syntax highlighting be enabled in the Python shell buffer? 1789 "Should syntax highlighting be enabled in the Python shell buffer?
@@ -1801,6 +1853,167 @@ virtualenv."
1801 :type '(alist string) 1853 :type '(alist string)
1802 :group 'python) 1854 :group 'python)
1803 1855
1856(defvar python-shell--prompt-calculated-input-regexp nil
1857 "Calculated input prompt regexp for inferior python shell.
1858Do not set this variable directly, instead use
1859`python-shell-prompt-set-calculated-regexps'.")
1860
1861(defvar python-shell--prompt-calculated-output-regexp nil
1862 "Calculated output prompt regexp for inferior python shell.
1863Do not set this variable directly, instead use
1864`python-shell-set-prompt-regexp'.")
1865
1866(defun python-shell-prompt-detect ()
1867 "Detect prompts for the current `python-shell-interpreter'.
1868When prompts can be retrieved successfully from the
1869`python-shell-interpreter' run with
1870`python-shell-interpreter-interactive-arg', returns a list of
1871three elements, where the first two are input prompts and the
1872last one is an output prompt. When no prompts can be detected
1873and `python-shell-prompt-detect-failure-warning' is non-nil,
1874shows a warning with instructions to avoid hangs and returns nil.
1875When `python-shell-prompt-detect-enabled' is nil avoids any
1876detection and just returns nil."
1877 (when python-shell-prompt-detect-enabled
1878 (let* ((process-environment (python-shell-calculate-process-environment))
1879 (exec-path (python-shell-calculate-exec-path))
1880 (code (concat
1881 "import sys\n"
1882 "ps = [getattr(sys, 'ps%s' % i, '') for i in range(1,4)]\n"
1883 ;; JSON is built manually for compatibility
1884 "ps_json = '\\n[\"%s\", \"%s\", \"%s\"]\\n' % tuple(ps)\n"
1885 "print (ps_json)\n"
1886 "sys.exit(0)\n"))
1887 (output
1888 (with-temp-buffer
1889 ;; TODO: improve error handling by using
1890 ;; `condition-case' and displaying the error message to
1891 ;; the user in the no-prompts warning.
1892 (ignore-errors
1893 (let ((code-file (python-shell--save-temp-file code)))
1894 ;; Use `process-file' as it is remote-host friendly.
1895 (process-file
1896 (executable-find python-shell-interpreter)
1897 code-file
1898 '(t nil)
1899 nil
1900 python-shell-interpreter-interactive-arg)
1901 ;; Try to cleanup
1902 (delete-file code-file)))
1903 (buffer-string)))
1904 (prompts
1905 (catch 'prompts
1906 (dolist (line (split-string output "\n" t))
1907 (let ((res
1908 ;; Check if current line is a valid JSON array
1909 (and (string= (substring line 0 2) "[\"")
1910 (ignore-errors
1911 ;; Return prompts as a list, not vector
1912 (append (json-read-from-string line) nil)))))
1913 ;; The list must contain 3 strings, where the first
1914 ;; is the input prompt, the second is the block
1915 ;; prompt and the last one is the output prompt. The
1916 ;; input prompt is the only one that can't be empty.
1917 (when (and (= (length res) 3)
1918 (cl-every #'stringp res)
1919 (not (string= (car res) "")))
1920 (throw 'prompts res))))
1921 nil)))
1922 (when (and (not prompts)
1923 python-shell-prompt-detect-failure-warning)
1924 (warn
1925 (concat
1926 "Python shell prompts cannot be detected.\n"
1927 "If your emacs session hangs when starting python shells\n"
1928 "recover with `keyboard-quit' and then try fixing the\n"
1929 "interactive flag for your interpreter by adjusting the\n"
1930 "`python-shell-interpreter-interactive-arg' or add regexps\n"
1931 "matching shell prompts in the directory-local friendly vars:\n"
1932 " + `python-shell-prompt-regexp'\n"
1933 " + `python-shell-prompt-block-regexp'\n"
1934 " + `python-shell-prompt-output-regexp'\n"
1935 "Or alternatively in:\n"
1936 " + `python-shell-prompt-input-regexps'\n"
1937 " + `python-shell-prompt-output-regexps'")))
1938 prompts)))
1939
1940(defun python-shell-prompt-validate-regexps ()
1941 "Validate all user provided regexps for prompts.
1942Signals `user-error' if any of these vars contain invalid
1943regexps: `python-shell-prompt-regexp',
1944`python-shell-prompt-block-regexp',
1945`python-shell-prompt-pdb-regexp',
1946`python-shell-prompt-output-regexp',
1947`python-shell-prompt-input-regexps',
1948`python-shell-prompt-output-regexps'."
1949 (dolist (symbol (list 'python-shell-prompt-input-regexps
1950 'python-shell-prompt-output-regexps
1951 'python-shell-prompt-regexp
1952 'python-shell-prompt-block-regexp
1953 'python-shell-prompt-pdb-regexp
1954 'python-shell-prompt-output-regexp))
1955 (dolist (regexp (let ((regexps (symbol-value symbol)))
1956 (if (listp regexps)
1957 regexps
1958 (list regexps))))
1959 (when (not (python-util-valid-regexp-p regexp))
1960 (user-error "Invalid regexp %s in `%s'"
1961 regexp symbol)))))
1962
1963(defun python-shell-prompt-set-calculated-regexps ()
1964 "Detect and set input and output prompt regexps.
1965Build and set the values for `python-shell-input-prompt-regexp'
1966and `python-shell-output-prompt-regexp' using the values from
1967`python-shell-prompt-regexp', `python-shell-prompt-block-regexp',
1968`python-shell-prompt-pdb-regexp',
1969`python-shell-prompt-output-regexp',
1970`python-shell-prompt-input-regexps',
1971`python-shell-prompt-output-regexps' and detected prompts from
1972`python-shell-prompt-detect'."
1973 (when (not (and python-shell--prompt-calculated-input-regexp
1974 python-shell--prompt-calculated-output-regexp))
1975 (let* ((detected-prompts (python-shell-prompt-detect))
1976 (input-prompts nil)
1977 (output-prompts nil)
1978 (build-regexp
1979 (lambda (prompts)
1980 (concat "^\\("
1981 (mapconcat #'identity
1982 (sort prompts
1983 (lambda (a b)
1984 (let ((length-a (length a))
1985 (length-b (length b)))
1986 (if (= length-a length-b)
1987 (string< a b)
1988 (> (length a) (length b))))))
1989 "\\|")
1990 "\\)"))))
1991 ;; Validate ALL regexps
1992 (python-shell-prompt-validate-regexps)
1993 ;; Collect all user defined input prompts
1994 (dolist (prompt (append python-shell-prompt-input-regexps
1995 (list python-shell-prompt-regexp
1996 python-shell-prompt-block-regexp
1997 python-shell-prompt-pdb-regexp)))
1998 (cl-pushnew prompt input-prompts :test #'string=))
1999 ;; Collect all user defined output prompts
2000 (dolist (prompt (cons python-shell-prompt-output-regexp
2001 python-shell-prompt-output-regexps))
2002 (cl-pushnew prompt output-prompts :test #'string=))
2003 ;; Collect detected prompts if any
2004 (when detected-prompts
2005 (dolist (prompt (butlast detected-prompts))
2006 (setq prompt (regexp-quote prompt))
2007 (cl-pushnew prompt input-prompts :test #'string=))
2008 (cl-pushnew (regexp-quote
2009 (car (last detected-prompts)))
2010 output-prompts :test #'string=))
2011 ;; Set input and output prompt regexps from collected prompts
2012 (setq python-shell--prompt-calculated-input-regexp
2013 (funcall build-regexp input-prompts)
2014 python-shell--prompt-calculated-output-regexp
2015 (funcall build-regexp output-prompts)))))
2016
1804(defun python-shell-get-process-name (dedicated) 2017(defun python-shell-get-process-name (dedicated)
1805 "Calculate the appropriate process name for inferior Python process. 2018 "Calculate the appropriate process name for inferior Python process.
1806If DEDICATED is t and the variable `buffer-file-name' is non-nil 2019If DEDICATED is t and the variable `buffer-file-name' is non-nil
@@ -1823,10 +2036,10 @@ uniqueness for different types of configurations."
1823 python-shell-internal-buffer-name 2036 python-shell-internal-buffer-name
1824 (md5 2037 (md5
1825 (concat 2038 (concat
1826 (python-shell-parse-command) 2039 python-shell-interpreter
1827 python-shell-prompt-regexp 2040 python-shell-interpreter-args
1828 python-shell-prompt-block-regexp 2041 python-shell--prompt-calculated-input-regexp
1829 python-shell-prompt-output-regexp 2042 python-shell--prompt-calculated-output-regexp
1830 (mapconcat #'symbol-value python-shell-setup-codes "") 2043 (mapconcat #'symbol-value python-shell-setup-codes "")
1831 (mapconcat #'identity python-shell-process-environment "") 2044 (mapconcat #'identity python-shell-process-environment "")
1832 (mapconcat #'identity python-shell-extra-pythonpaths "") 2045 (mapconcat #'identity python-shell-extra-pythonpaths "")
@@ -1920,12 +2133,19 @@ initialization of the interpreter via `python-shell-setup-codes'
1920variable. 2133variable.
1921 2134
1922\(Type \\[describe-mode] in the process buffer for a list of commands.)" 2135\(Type \\[describe-mode] in the process buffer for a list of commands.)"
1923 (and python-shell--parent-buffer 2136 (let ((interpreter python-shell-interpreter)
1924 (python-util-clone-local-variables python-shell--parent-buffer)) 2137 (args python-shell-interpreter-args))
1925 (setq comint-prompt-regexp (format "^\\(?:%s\\|%s\\|%s\\)" 2138 (when python-shell--parent-buffer
1926 python-shell-prompt-regexp 2139 (python-util-clone-local-variables python-shell--parent-buffer))
1927 python-shell-prompt-block-regexp 2140 ;; Users can override default values for these vars when calling
1928 python-shell-prompt-pdb-regexp)) 2141 ;; `run-python'. This ensures new values let-bound in
2142 ;; `python-shell-make-comint' are locally set.
2143 (set (make-local-variable 'python-shell-interpreter) interpreter)
2144 (set (make-local-variable 'python-shell-interpreter-args) args))
2145 (set (make-local-variable 'python-shell--prompt-calculated-input-regexp) nil)
2146 (set (make-local-variable 'python-shell--prompt-calculated-output-regexp) nil)
2147 (python-shell-prompt-set-calculated-regexps)
2148 (setq comint-prompt-regexp python-shell--prompt-calculated-input-regexp)
1929 (setq mode-line-process '(":%s")) 2149 (setq mode-line-process '(":%s"))
1930 (make-local-variable 'comint-output-filter-functions) 2150 (make-local-variable 'comint-output-filter-functions)
1931 (add-hook 'comint-output-filter-functions 2151 (add-hook 'comint-output-filter-functions
@@ -1988,10 +2208,20 @@ killed."
1988 (exec-path (python-shell-calculate-exec-path))) 2208 (exec-path (python-shell-calculate-exec-path)))
1989 (when (not (comint-check-proc proc-buffer-name)) 2209 (when (not (comint-check-proc proc-buffer-name))
1990 (let* ((cmdlist (split-string-and-unquote cmd)) 2210 (let* ((cmdlist (split-string-and-unquote cmd))
2211 (interpreter (car cmdlist))
2212 (args (cdr cmdlist))
1991 (buffer (apply #'make-comint-in-buffer proc-name proc-buffer-name 2213 (buffer (apply #'make-comint-in-buffer proc-name proc-buffer-name
1992 (car cmdlist) nil (cdr cmdlist))) 2214 interpreter nil args))
1993 (python-shell--parent-buffer (current-buffer)) 2215 (python-shell--parent-buffer (current-buffer))
1994 (process (get-buffer-process buffer))) 2216 (process (get-buffer-process buffer))
2217 ;; As the user may have overriden default values for
2218 ;; these vars on `run-python', let-binding them allows
2219 ;; to have the new right values in all setup code
2220 ;; that's is done in `inferior-python-mode', which is
2221 ;; important, especially for prompt detection.
2222 (python-shell-interpreter interpreter)
2223 (python-shell-interpreter-args
2224 (mapconcat #'identity args " ")))
1995 (with-current-buffer buffer 2225 (with-current-buffer buffer
1996 (inferior-python-mode)) 2226 (inferior-python-mode))
1997 (accept-process-output process) 2227 (accept-process-output process)
@@ -2063,8 +2293,12 @@ startup."
2063 "Return inferior Python process for current buffer." 2293 "Return inferior Python process for current buffer."
2064 (get-buffer-process (python-shell-get-buffer))) 2294 (get-buffer-process (python-shell-get-buffer)))
2065 2295
2066(defun python-shell-get-or-create-process () 2296(defun python-shell-get-or-create-process (&optional cmd dedicated show)
2067 "Get or create an inferior Python process for current buffer and return it." 2297 "Get or create an inferior Python process for current buffer and return it.
2298Arguments CMD, DEDICATED and SHOW are those of `run-python' and
2299are used to start the shell. If those arguments are not
2300provided, `run-python' is called interactively and the user will
2301be asked for their values."
2068 (let* ((dedicated-proc-name (python-shell-get-process-name t)) 2302 (let* ((dedicated-proc-name (python-shell-get-process-name t))
2069 (dedicated-proc-buffer-name (format "*%s*" dedicated-proc-name)) 2303 (dedicated-proc-buffer-name (format "*%s*" dedicated-proc-name))
2070 (global-proc-name (python-shell-get-process-name nil)) 2304 (global-proc-name (python-shell-get-process-name nil))
@@ -2072,7 +2306,11 @@ startup."
2072 (dedicated-running (comint-check-proc dedicated-proc-buffer-name)) 2306 (dedicated-running (comint-check-proc dedicated-proc-buffer-name))
2073 (global-running (comint-check-proc global-proc-buffer-name))) 2307 (global-running (comint-check-proc global-proc-buffer-name)))
2074 (when (and (not dedicated-running) (not global-running)) 2308 (when (and (not dedicated-running) (not global-running))
2075 (if (call-interactively 'run-python) 2309 (if (if (not cmd)
2310 ;; XXX: Refactor code such that calling `run-python'
2311 ;; interactively is not needed anymore.
2312 (call-interactively 'run-python)
2313 (run-python cmd dedicated show))
2076 (setq dedicated-running t) 2314 (setq dedicated-running t)
2077 (setq global-running t))) 2315 (setq global-running t)))
2078 ;; Always prefer dedicated 2316 ;; Always prefer dedicated
@@ -2155,10 +2393,13 @@ detecting a prompt at the end of the buffer."
2155 (when (string-match 2393 (when (string-match
2156 ;; XXX: It seems on OSX an extra carriage return is attached 2394 ;; XXX: It seems on OSX an extra carriage return is attached
2157 ;; at the end of output, this handles that too. 2395 ;; at the end of output, this handles that too.
2158 (format "\r?\n\\(?:%s\\|%s\\|%s\\)$" 2396 (concat
2159 python-shell-prompt-regexp 2397 "\r?\n"
2160 python-shell-prompt-block-regexp 2398 ;; Remove initial caret from calculated regexp
2161 python-shell-prompt-pdb-regexp) 2399 (replace-regexp-in-string
2400 (rx string-start ?^) ""
2401 python-shell--prompt-calculated-input-regexp)
2402 "$")
2162 python-shell-output-filter-buffer) 2403 python-shell-output-filter-buffer)
2163 ;; Output ends when `python-shell-output-filter-buffer' contains 2404 ;; Output ends when `python-shell-output-filter-buffer' contains
2164 ;; the prompt attached at the end of it. 2405 ;; the prompt attached at the end of it.
@@ -2166,10 +2407,10 @@ detecting a prompt at the end of the buffer."
2166 python-shell-output-filter-buffer 2407 python-shell-output-filter-buffer
2167 (substring python-shell-output-filter-buffer 2408 (substring python-shell-output-filter-buffer
2168 0 (match-beginning 0))) 2409 0 (match-beginning 0)))
2169 (when (and (> (length python-shell-prompt-output-regexp) 0) 2410 (when (string-match
2170 (string-match (concat "^" python-shell-prompt-output-regexp) 2411 python-shell--prompt-calculated-output-regexp
2171 python-shell-output-filter-buffer)) 2412 python-shell-output-filter-buffer)
2172 ;; Some shells, like iPython might append a prompt before the 2413 ;; Some shells, like IPython might append a prompt before the
2173 ;; output, clean that. 2414 ;; output, clean that.
2174 (setq python-shell-output-filter-buffer 2415 (setq python-shell-output-filter-buffer
2175 (substring python-shell-output-filter-buffer (match-end 0))))) 2416 (substring python-shell-output-filter-buffer (match-end 0)))))
@@ -2379,23 +2620,35 @@ This function takes the list of setup code to send from the
2379 2620
2380(defcustom python-shell-completion-setup-code 2621(defcustom python-shell-completion-setup-code
2381 "try: 2622 "try:
2382 import readline 2623 import readline, rlcompleter
2383except ImportError: 2624except ImportError:
2384 def __COMPLETER_all_completions(text): [] 2625 def __PYTHON_EL_get_completions(text):
2626 return []
2385else: 2627else:
2386 import rlcompleter 2628 def __PYTHON_EL_get_completions(text):
2387 readline.set_completer(rlcompleter.Completer().complete)
2388 def __COMPLETER_all_completions(text):
2389 import sys
2390 completions = [] 2629 completions = []
2391 try: 2630 try:
2392 i = 0 2631 splits = text.split()
2393 while True: 2632 is_module = splits and splits[0] in ('from', 'import')
2394 res = readline.get_completer()(text, i) 2633 is_ipython = getattr(
2395 if not res: break 2634 __builtins__, '__IPYTHON__',
2396 i += 1 2635 getattr(__builtins__, '__IPYTHON__active', False))
2397 completions.append(res) 2636 if is_module:
2398 except NameError: 2637 from IPython.core.completerlib import module_completion
2638 completions = module_completion(text.strip())
2639 elif is_ipython and getattr(__builtins__, '__IP', None):
2640 completions = __IP.complete(text)
2641 elif is_ipython and getattr(__builtins__, 'get_ipython', None):
2642 completions = get_ipython().Completer.all_completions(text)
2643 else:
2644 i = 0
2645 while True:
2646 res = readline.get_completer()(text, i)
2647 if not res:
2648 break
2649 i += 1
2650 completions.append(res)
2651 except:
2399 pass 2652 pass
2400 return completions" 2653 return completions"
2401 "Code used to setup completion in inferior Python processes." 2654 "Code used to setup completion in inferior Python processes."
@@ -2403,24 +2656,18 @@ else:
2403 :group 'python) 2656 :group 'python)
2404 2657
2405(defcustom python-shell-completion-string-code 2658(defcustom python-shell-completion-string-code
2406 "';'.join(__COMPLETER_all_completions('''%s'''))\n" 2659 "';'.join(__PYTHON_EL_get_completions('''%s'''))\n"
2407 "Python code used to get a string of completions separated by semicolons." 2660 "Python code used to get a string of completions separated by semicolons.
2661The string passed to the function is the current python name or
2662the full statement in the case of imports."
2408 :type 'string 2663 :type 'string
2409 :group 'python) 2664 :group 'python)
2410 2665
2411(defcustom python-shell-completion-module-string-code "" 2666(define-obsolete-variable-alias
2412 "Python code used to get completions separated by semicolons for imports. 2667 'python-shell-completion-module-string-code
2413 2668 'python-shell-completion-string-code
2414For IPython v0.11, add the following line to 2669 "24.4"
2415`python-shell-completion-setup-code': 2670 "Completion string code must also autocomplete modules.")
2416
2417from IPython.core.completerlib import module_completion
2418
2419and use the following as the value of this variable:
2420
2421';'.join(module_completion('''%s'''))\n"
2422 :type 'string
2423 :group 'python)
2424 2671
2425(defcustom python-shell-completion-pdb-string-code 2672(defcustom python-shell-completion-pdb-string-code
2426 "';'.join(globals().keys() + locals().keys())" 2673 "';'.join(globals().keys() + locals().keys())"
@@ -2443,33 +2690,23 @@ LINE is used to detect the context on how to complete given INPUT."
2443 (re-search-backward "^") 2690 (re-search-backward "^")
2444 (python-util-forward-comment) 2691 (python-util-forward-comment)
2445 (point)))))) 2692 (point))))))
2446 (completion-context 2693 (completion-code
2447 ;; Check whether a prompt matches a pdb string, an import 2694 ;; Check whether a prompt matches a pdb string, an import
2448 ;; statement or just the standard prompt and use the 2695 ;; statement or just the standard prompt and use the
2449 ;; correct python-shell-completion-*-code string 2696 ;; correct python-shell-completion-*-code string
2450 (cond ((and (> (length python-shell-completion-pdb-string-code) 0) 2697 (cond ((and (> (length python-shell-completion-pdb-string-code) 0)
2451 (string-match 2698 (string-match
2452 (concat "^" python-shell-prompt-pdb-regexp) prompt)) 2699 (concat "^" python-shell-prompt-pdb-regexp) prompt))
2453 'pdb) 2700 python-shell-completion-pdb-string-code)
2454 ((and (>
2455 (length python-shell-completion-module-string-code) 0)
2456 (string-match
2457 (concat "^" python-shell-prompt-regexp) prompt)
2458 (string-match "^[ \t]*\\(from\\|import\\)[ \t]" line))
2459 'import)
2460 ((string-match 2701 ((string-match
2461 (concat "^" python-shell-prompt-regexp) prompt) 2702 python-shell--prompt-calculated-input-regexp prompt)
2462 'default) 2703 python-shell-completion-string-code)
2463 (t nil))) 2704 (t nil)))
2464 (completion-code
2465 (pcase completion-context
2466 (`pdb python-shell-completion-pdb-string-code)
2467 (`import python-shell-completion-module-string-code)
2468 (`default python-shell-completion-string-code)
2469 (_ nil)))
2470 (input 2705 (input
2471 (if (eq completion-context 'import) 2706 (if (string-match
2472 (replace-regexp-in-string "^[ \t]+" "" line) 2707 (python-rx (+ space) (or "from" "import") space)
2708 line)
2709 line
2473 input))) 2710 input)))
2474 (and completion-code 2711 (and completion-code
2475 (> (length input) 0) 2712 (> (length input) 0)
@@ -3710,6 +3947,10 @@ returned as is."
3710 "" 3947 ""
3711 string)) 3948 string))
3712 3949
3950(defun python-util-valid-regexp-p (regexp)
3951 "Return non-nil if REGEXP is valid."
3952 (ignore-errors (string-match regexp "") t))
3953
3713 3954
3714(defun python-electric-pair-string-delimiter () 3955(defun python-electric-pair-string-delimiter ()
3715 (when (and electric-pair-mode 3956 (when (and electric-pair-mode
@@ -3794,8 +4035,6 @@ returned as is."
3794 ,(lambda (_arg) 4035 ,(lambda (_arg)
3795 (python-nav-end-of-defun)) nil)) 4036 (python-nav-end-of-defun)) nil))
3796 4037
3797 (set (make-local-variable 'mode-require-final-newline) t)
3798
3799 (set (make-local-variable 'outline-regexp) 4038 (set (make-local-variable 'outline-regexp)
3800 (python-rx (* space) block-start)) 4039 (python-rx (* space) block-start))
3801 (set (make-local-variable 'outline-heading-end-regexp) ":[^\n]*\n") 4040 (set (make-local-variable 'outline-heading-end-regexp) ":[^\n]*\n")
diff --git a/lisp/view.el b/lisp/view.el
index a5992ccb62a..9f914b03f56 100644
--- a/lisp/view.el
+++ b/lisp/view.el
@@ -491,12 +491,12 @@ Entry to view-mode runs the normal hook `view-mode-hook'."
491(defun view--disable () 491(defun view--disable ()
492 (remove-hook 'change-major-mode-hook 'view--disable t) 492 (remove-hook 'change-major-mode-hook 'view--disable t)
493 (and view-overlay (delete-overlay view-overlay)) 493 (and view-overlay (delete-overlay view-overlay))
494 ;; Calling toggle-read-only while View mode is enabled 494 ;; Calling read-only-mode while View mode is enabled
495 ;; sets view-read-only to t as a buffer-local variable 495 ;; sets view-read-only to t as a buffer-local variable
496 ;; after exiting View mode. That arranges that the next toggle-read-only 496 ;; after exiting View mode. That arranges that the next read-only-mode
497 ;; will reenable View mode. 497 ;; will reenable View mode.
498 ;; Canceling View mode in any other way should cancel that, too, 498 ;; Canceling View mode in any other way should cancel that, too,
499 ;; so that View mode stays off if toggle-read-only is called. 499 ;; so that View mode stays off if read-only-mode is called.
500 (if (local-variable-p 'view-read-only) 500 (if (local-variable-p 'view-read-only)
501 (kill-local-variable 'view-read-only)) 501 (kill-local-variable 'view-read-only))
502 (if (boundp 'Helper-return-blurb) 502 (if (boundp 'Helper-return-blurb)
diff --git a/src/ChangeLog b/src/ChangeLog
index d4f6321faf7..25732ac9f5d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,37 @@
12014-07-21 Jan Djärv <jan.h.d@swipnet.se>
2
3 * nsterm.m (applicationDidFinishLaunching:): Call
4 antialiasThresholdDidChange, register for antialias changes (Bug#17534).
5 (antialiasThresholdDidChange:): New method for EmacsApp.
6
7 * nsterm.h (EmacsApp): Add antialiasThresholdDidChange.
8
9 * macfont.m (macfont_update_antialias_threshold): Remove static.
10
11 * macfont.h (macfont_update_antialias_threshold): Declare.
12
132014-07-21 Eli Zaretskii <eliz@gnu.org>
14
15 * w32select.c (setup_windows_coding_system): Apply
16 CODING_ANNOTATION_MASK to the common_flags member of struct
17 coding_system. Reported by martin rudalics <rudalics@gmx.at>.
18
19 * w16select.c (Fw16_get_clipboard_data): Apply
20 CODING_ANNOTATION_MASK to the common_flags member of struct
21 coding_system.
22
23 * xdisp.c (init_iterator): Initialize it->stop_charpos to the
24 buffer position where we are to start the iteration.
25 (handle_invisible_prop): Record in it->stop_charpos the position
26 where the invisible text ends. (Bug#18035)
27 (hscroll_window_tree): Don't try hscrolling windows whose cursor
28 row has zero buffer position as their start position. Reported by
29 martin rudalics <rudalics@gmx.at>.
30
31 * xdisp.c (move_it_vertically_backward, move_it_by_lines): Prevent
32 infinite looping in redisplay when display lines don't have enough
33 space to display even a single character. (Bug#18036)
34
12014-07-20 Dmitry Antipov <dmantipov@yandex.ru> 352014-07-20 Dmitry Antipov <dmantipov@yandex.ru>
2 36
3 * frame.h (struct frame) [USE_X_TOOLKIT]: New member shell_position. 37 * frame.h (struct frame) [USE_X_TOOLKIT]: New member shell_position.
diff --git a/src/macfont.h b/src/macfont.h
index 8b451357e42..7421cd63a79 100644
--- a/src/macfont.h
+++ b/src/macfont.h
@@ -144,4 +144,5 @@ typedef const struct _EmacsScreenFont *ScreenFontRef; /* opaque */
144 144
145extern void mac_register_font_driver (struct frame *f); 145extern void mac_register_font_driver (struct frame *f);
146extern void *macfont_get_nsctfont (struct font *font); 146extern void *macfont_get_nsctfont (struct font *font);
147extern void macfont_update_antialias_threshold (void);
147 148
diff --git a/src/macfont.m b/src/macfont.m
index 60f261d5549..0d702873220 100644
--- a/src/macfont.m
+++ b/src/macfont.m
@@ -728,7 +728,7 @@ static const struct
728 728
729static CGFloat macfont_antialias_threshold; 729static CGFloat macfont_antialias_threshold;
730 730
731static void 731void
732macfont_update_antialias_threshold (void) 732macfont_update_antialias_threshold (void)
733{ 733{
734 int threshold; 734 int threshold;
diff --git a/src/nsterm.h b/src/nsterm.h
index 2619b710073..7ed23f583f6 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -111,6 +111,7 @@ typedef float EmacsCGFloat;
111#endif 111#endif
112} 112}
113- (void)logNotification: (NSNotification *)notification; 113- (void)logNotification: (NSNotification *)notification;
114- (void)antialiasThresholdDidChange:(NSNotification *)notification;
114- (void)sendEvent: (NSEvent *)theEvent; 115- (void)sendEvent: (NSEvent *)theEvent;
115- (void)showPreferencesWindow: (id)sender; 116- (void)showPreferencesWindow: (id)sender;
116- (BOOL) openFile: (NSString *)fileName; 117- (BOOL) openFile: (NSString *)fileName;
diff --git a/src/nsterm.m b/src/nsterm.m
index 9420031645d..64f3be6cc06 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -4670,9 +4670,30 @@ ns_term_shutdown (int sig)
4670 ((EmacsApp *)self)->applicationDidFinishLaunchingCalled = YES; 4670 ((EmacsApp *)self)->applicationDidFinishLaunchingCalled = YES;
4671#endif 4671#endif
4672 [NSApp setServicesProvider: NSApp]; 4672 [NSApp setServicesProvider: NSApp];
4673
4674 [self antialiasThresholdDidChange:nil];
4675#ifdef NS_IMPL_COCOA
4676#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
4677 [[NSNotificationCenter defaultCenter]
4678 addObserver:self
4679 selector:@selector(antialiasThresholdDidChange:)
4680 name:NSAntialiasThresholdChangedNotification
4681 object:nil];
4682#endif
4683#endif
4684
4673 ns_send_appdefined (-2); 4685 ns_send_appdefined (-2);
4674} 4686}
4675 4687
4688- (void)antialiasThresholdDidChange:(NSNotification *)notification
4689{
4690#ifdef NS_IMPL_COCOA
4691#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
4692 macfont_update_antialias_threshold ();
4693#endif
4694#endif
4695}
4696
4676 4697
4677/* Termination sequences: 4698/* Termination sequences:
4678 C-x C-c: 4699 C-x C-c:
diff --git a/src/w16select.c b/src/w16select.c
index 1e4d35b721b..c229ba5816a 100644
--- a/src/w16select.c
+++ b/src/w16select.c
@@ -600,7 +600,7 @@ DEFUN ("w16-get-clipboard-data", Fw16_get_clipboard_data, Sw16_get_clipboard_dat
600 coding.mode |= CODING_MODE_LAST_BLOCK; 600 coding.mode |= CODING_MODE_LAST_BLOCK;
601 /* We explicitly disable composition handling because selection 601 /* We explicitly disable composition handling because selection
602 data should not contain any composition sequence. */ 602 data should not contain any composition sequence. */
603 coding.mode &= CODING_ANNOTATION_MASK; 603 coding.common_flags &= ~CODING_ANNOTATION_MASK;
604 decode_coding_object (&coding, Qnil, 0, 0, truelen, truelen, Qt); 604 decode_coding_object (&coding, Qnil, 0, 0, truelen, truelen, Qt);
605 ret = coding.dst_object; 605 ret = coding.dst_object;
606 Vlast_coding_system_used = CODING_ID_NAME (coding.id); 606 Vlast_coding_system_used = CODING_ID_NAME (coding.id);
diff --git a/src/w32select.c b/src/w32select.c
index 2ae25858bd2..7c21dde01a5 100644
--- a/src/w32select.c
+++ b/src/w32select.c
@@ -670,7 +670,7 @@ setup_windows_coding_system (Lisp_Object coding_system,
670 which both apply to ISO6429 only. We don't know if these really 670 which both apply to ISO6429 only. We don't know if these really
671 need to be unset on Windows, but it probably doesn't hurt 671 need to be unset on Windows, but it probably doesn't hurt
672 either. */ 672 either. */
673 coding->mode &= ~CODING_ANNOTATION_MASK; 673 coding->common_flags &= ~CODING_ANNOTATION_MASK;
674 coding->mode |= CODING_MODE_LAST_BLOCK | CODING_MODE_SAFE_ENCODING; 674 coding->mode |= CODING_MODE_LAST_BLOCK | CODING_MODE_SAFE_ENCODING;
675} 675}
676 676
diff --git a/src/xdisp.c b/src/xdisp.c
index f1e01146e9f..a340c6e00dd 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -3034,6 +3034,7 @@ init_iterator (struct it *it, struct window *w,
3034 getting overlays and face properties from that position. */ 3034 getting overlays and face properties from that position. */
3035 if (charpos >= BUF_BEG (current_buffer)) 3035 if (charpos >= BUF_BEG (current_buffer))
3036 { 3036 {
3037 it->stop_charpos = charpos;
3037 it->end_charpos = ZV; 3038 it->end_charpos = ZV;
3038 eassert (charpos == BYTE_TO_CHAR (bytepos)); 3039 eassert (charpos == BYTE_TO_CHAR (bytepos));
3039 IT_CHARPOS (*it) = charpos; 3040 IT_CHARPOS (*it) = charpos;
@@ -4546,7 +4547,24 @@ handle_invisible_prop (struct it *it)
4546 && get_overlay_strings (it, it->stop_charpos)) 4547 && get_overlay_strings (it, it->stop_charpos))
4547 { 4548 {
4548 handled = HANDLED_RECOMPUTE_PROPS; 4549 handled = HANDLED_RECOMPUTE_PROPS;
4549 it->stack[it->sp - 1].display_ellipsis_p = display_ellipsis_p; 4550 if (it->sp > 0)
4551 {
4552 it->stack[it->sp - 1].display_ellipsis_p = display_ellipsis_p;
4553 /* The call to get_overlay_strings above recomputes
4554 it->stop_charpos, but it only considers changes
4555 in properties and overlays beyond iterator's
4556 current position. This causes us to miss changes
4557 that happen exactly where the invisible property
4558 ended. So we play it safe here and force the
4559 iterator to check for potential stop positions
4560 immediately after the invisible text. Note that
4561 if get_overlay_strings returns non-zero, it
4562 normally also pushed the iterator stack, so we
4563 need to update the stop position in the slot
4564 below the current one. */
4565 it->stack[it->sp - 1].stop_charpos
4566 = CHARPOS (it->stack[it->sp - 1].current.pos);
4567 }
4550 } 4568 }
4551 else if (display_ellipsis_p) 4569 else if (display_ellipsis_p)
4552 { 4570 {
@@ -9351,7 +9369,7 @@ move_it_vertically_backward (struct it *it, int dy)
9351 9369
9352 /* Estimate how many newlines we must move back. */ 9370 /* Estimate how many newlines we must move back. */
9353 nlines = max (1, dy / default_line_pixel_height (it->w)); 9371 nlines = max (1, dy / default_line_pixel_height (it->w));
9354 if (it->line_wrap == TRUNCATE) 9372 if (it->line_wrap == TRUNCATE || nchars_per_row == 0)
9355 pos_limit = BEGV; 9373 pos_limit = BEGV;
9356 else 9374 else
9357 pos_limit = max (start_pos - nlines * nchars_per_row, BEGV); 9375 pos_limit = max (start_pos - nlines * nchars_per_row, BEGV);
@@ -9606,7 +9624,7 @@ move_it_by_lines (struct it *it, ptrdiff_t dvpos)
9606 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full 9624 /* Go back -DVPOS buffer lines, but no farther than -DVPOS full
9607 screen lines, and reseat the iterator there. */ 9625 screen lines, and reseat the iterator there. */
9608 start_charpos = IT_CHARPOS (*it); 9626 start_charpos = IT_CHARPOS (*it);
9609 if (it->line_wrap == TRUNCATE) 9627 if (it->line_wrap == TRUNCATE || nchars_per_row == 0)
9610 pos_limit = BEGV; 9628 pos_limit = BEGV;
9611 else 9629 else
9612 pos_limit = max (start_charpos + dvpos * nchars_per_row, BEGV); 9630 pos_limit = max (start_charpos + dvpos * nchars_per_row, BEGV);
@@ -12847,6 +12865,13 @@ hscroll_window_tree (Lisp_Object window)
12847 h_margin = hscroll_margin * WINDOW_FRAME_COLUMN_WIDTH (w); 12865 h_margin = hscroll_margin * WINDOW_FRAME_COLUMN_WIDTH (w);
12848 12866
12849 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode, w->contents)) 12867 if (!NILP (Fbuffer_local_value (Qauto_hscroll_mode, w->contents))
12868 /* In some pathological cases, like restoring a window
12869 configuration into a frame that is much smaller than
12870 the one from which the configuration was saved, we
12871 get glyph rows whose start and end have zero buffer
12872 positions, which we cannot handle below. Just skip
12873 such windows. */
12874 && CHARPOS (cursor_row->start.pos) >= BUF_BEG (w->contents)
12850 /* For left-to-right rows, hscroll when cursor is either 12875 /* For left-to-right rows, hscroll when cursor is either
12851 (i) inside the right hscroll margin, or (ii) if it is 12876 (i) inside the right hscroll margin, or (ii) if it is
12852 inside the left margin and the window is already 12877 inside the left margin and the window is already
diff --git a/test/ChangeLog b/test/ChangeLog
index dca2f7e14fe..c66ea1c739f 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,37 @@
12014-07-21 Fabián Ezequiel Gallina <fgallina@gnu.org>
2
3 * automated/python-tests.el:
4 (python-util-clone-local-variables-1): Fix test.
5
6 * automated/python-tests.el (python-shell-make-comint-1):
7 (python-shell-make-comint-2): Fix indentation.
8 (python-shell-make-comint-3)
9 (python-shell-make-comint-4): New tests.
10 (python-shell-get-or-create-process-1): Fix test.
11 (python-shell-get-or-create-process-2)
12 (python-shell-get-or-create-process-3): New tests.
13 (python-shell-internal-get-or-create-process-1): Fix test.
14 (python-shell-prompt-detect-1): New test.
15 (python-shell-prompt-detect-2): New test. (Bug#17370)
16 (python-shell-prompt-detect-3)
17 (python-shell-prompt-detect-4)
18 (python-shell-prompt-detect-5)
19 (python-shell-prompt-detect-6)
20 (python-shell-prompt-validate-regexps-1)
21 (python-shell-prompt-validate-regexps-2)
22 (python-shell-prompt-validate-regexps-3)
23 (python-shell-prompt-validate-regexps-4)
24 (python-shell-prompt-validate-regexps-5)
25 (python-shell-prompt-validate-regexps-6)
26 (python-shell-prompt-validate-regexps-7)
27 (python-shell-prompt-set-calculated-regexps-1)
28 (python-shell-prompt-set-calculated-regexps-2)
29 (python-shell-prompt-set-calculated-regexps-3)
30 (python-shell-prompt-set-calculated-regexps-4)
31 (python-shell-prompt-set-calculated-regexps-5)
32 (python-shell-prompt-set-calculated-regexps-6)
33 (python-util-valid-regexp-p-1): New tests.
34
12014-07-21 Stefan Monnier <monnier@iro.umontreal.ca> 352014-07-21 Stefan Monnier <monnier@iro.umontreal.ca>
2 36
3 * automated/advice-tests.el (advice-test-call-interactively): Make sure 37 * automated/advice-tests.el (advice-test-call-interactively): Make sure
@@ -48,7 +82,7 @@
48 82
49 * automated/python-tests.el (python-tests-self-insert): New function. 83 * automated/python-tests.el (python-tests-self-insert): New function.
50 (python-triple-quote-pairing): Use it. 84 (python-triple-quote-pairing): Use it.
51 (python-util-forward-comment-1): New test. (Bug#17658) 85 (python-parens-electric-indent-1): New test. (Bug#17658)
52 86
532014-06-30 Fabián Ezequiel Gallina <fgallina@gnu.org> 872014-06-30 Fabián Ezequiel Gallina <fgallina@gnu.org>
54 88
diff --git a/test/automated/python-tests.el b/test/automated/python-tests.el
index 3a4eda36bfe..81f4567091e 100644
--- a/test/automated/python-tests.el
+++ b/test/automated/python-tests.el
@@ -1773,8 +1773,8 @@ Using `python-shell-interpreter' and
1773 (proc-name (python-shell-get-process-name nil)) 1773 (proc-name (python-shell-get-process-name nil))
1774 (shell-buffer 1774 (shell-buffer
1775 (python-tests-with-temp-buffer 1775 (python-tests-with-temp-buffer
1776 "" (python-shell-make-comint 1776 "" (python-shell-make-comint
1777 (python-shell-parse-command) proc-name))) 1777 (python-shell-parse-command) proc-name)))
1778 (process (get-buffer-process shell-buffer))) 1778 (process (get-buffer-process shell-buffer)))
1779 (unwind-protect 1779 (unwind-protect
1780 (progn 1780 (progn
@@ -1794,8 +1794,8 @@ Using `python-shell-interpreter' and
1794 (proc-name (python-shell-internal-get-process-name)) 1794 (proc-name (python-shell-internal-get-process-name))
1795 (shell-buffer 1795 (shell-buffer
1796 (python-tests-with-temp-buffer 1796 (python-tests-with-temp-buffer
1797 "" (python-shell-make-comint 1797 "" (python-shell-make-comint
1798 (python-shell-parse-command) proc-name nil t))) 1798 (python-shell-parse-command) proc-name nil t)))
1799 (process (get-buffer-process shell-buffer))) 1799 (process (get-buffer-process shell-buffer)))
1800 (unwind-protect 1800 (unwind-protect
1801 (progn 1801 (progn
@@ -1806,6 +1806,79 @@ Using `python-shell-interpreter' and
1806 (should (string= (buffer-name) (format " *%s*" proc-name))))) 1806 (should (string= (buffer-name) (format " *%s*" proc-name)))))
1807 (kill-buffer shell-buffer)))) 1807 (kill-buffer shell-buffer))))
1808 1808
1809(ert-deftest python-shell-make-comint-3 ()
1810 "Check comint creation with overriden python interpreter and args.
1811The command passed to `python-shell-make-comint' as argument must
1812locally override global values set in `python-shell-interpreter'
1813and `python-shell-interpreter-args' in the new shell buffer."
1814 (skip-unless (executable-find python-tests-shell-interpreter))
1815 (let* ((python-shell-setup-codes nil)
1816 (python-shell-interpreter "interpreter")
1817 (python-shell-interpreter-args "--some-args")
1818 (proc-name (python-shell-get-process-name nil))
1819 (interpreter-override
1820 (concat (executable-find python-tests-shell-interpreter) " " "-i"))
1821 (shell-buffer
1822 (python-tests-with-temp-buffer
1823 "" (python-shell-make-comint interpreter-override proc-name nil)))
1824 (process (get-buffer-process shell-buffer)))
1825 (unwind-protect
1826 (progn
1827 (set-process-query-on-exit-flag process nil)
1828 (should (process-live-p process))
1829 (with-current-buffer shell-buffer
1830 (should (eq major-mode 'inferior-python-mode))
1831 (should (string= python-shell-interpreter
1832 (executable-find python-tests-shell-interpreter)))
1833 (should (string= python-shell-interpreter-args "-i"))))
1834 (kill-buffer shell-buffer))))
1835
1836(ert-deftest python-shell-make-comint-4 ()
1837 "Check shell calculated prompts regexps are set."
1838 (skip-unless (executable-find python-tests-shell-interpreter))
1839 (let* ((process-environment process-environment)
1840 (python-shell-setup-codes nil)
1841 (python-shell-interpreter
1842 (executable-find python-tests-shell-interpreter))
1843 (python-shell-interpreter-args "-i")
1844 (python-shell--prompt-calculated-input-regexp nil)
1845 (python-shell--prompt-calculated-output-regexp nil)
1846 (python-shell-prompt-detect-enabled t)
1847 (python-shell-prompt-input-regexps '("extralargeinputprompt" "sml"))
1848 (python-shell-prompt-output-regexps '("extralargeoutputprompt" "sml"))
1849 (python-shell-prompt-regexp "in")
1850 (python-shell-prompt-block-regexp "block")
1851 (python-shell-prompt-pdb-regexp "pdf")
1852 (python-shell-prompt-output-regexp "output")
1853 (startup-code (concat "import sys\n"
1854 "sys.ps1 = 'py> '\n"
1855 "sys.ps2 = '..> '\n"
1856 "sys.ps3 = 'out '\n"))
1857 (startup-file (python-shell--save-temp-file startup-code))
1858 (proc-name (python-shell-get-process-name nil))
1859 (shell-buffer
1860 (progn
1861 (setenv "PYTHONSTARTUP" startup-file)
1862 (python-tests-with-temp-buffer
1863 "" (python-shell-make-comint
1864 (python-shell-parse-command) proc-name nil))))
1865 (process (get-buffer-process shell-buffer)))
1866 (unwind-protect
1867 (progn
1868 (set-process-query-on-exit-flag process nil)
1869 (should (process-live-p process))
1870 (with-current-buffer shell-buffer
1871 (should (eq major-mode 'inferior-python-mode))
1872 (should (string=
1873 python-shell--prompt-calculated-input-regexp
1874 (concat "^\\(extralargeinputprompt\\|\\.\\.> \\|"
1875 "block\\|py> \\|pdf\\|sml\\|in\\)")))
1876 (should (string=
1877 python-shell--prompt-calculated-output-regexp
1878 "^\\(extralargeoutputprompt\\|output\\|out \\|sml\\)"))))
1879 (delete-file startup-file)
1880 (kill-buffer shell-buffer))))
1881
1809(ert-deftest python-shell-get-process-1 () 1882(ert-deftest python-shell-get-process-1 ()
1810 "Check dedicated shell process preference over global." 1883 "Check dedicated shell process preference over global."
1811 (skip-unless (executable-find python-tests-shell-interpreter)) 1884 (skip-unless (executable-find python-tests-shell-interpreter))
@@ -1840,54 +1913,370 @@ Using `python-shell-interpreter' and
1840 (ignore-errors (kill-buffer dedicated-shell-buffer)))))) 1913 (ignore-errors (kill-buffer dedicated-shell-buffer))))))
1841 1914
1842(ert-deftest python-shell-get-or-create-process-1 () 1915(ert-deftest python-shell-get-or-create-process-1 ()
1843 "Check shell process creation fallback." 1916 "Check shell dedicated process creation."
1844 :expected-result :failed 1917 (skip-unless (executable-find python-tests-shell-interpreter))
1845 (python-tests-with-temp-file 1918 (python-tests-with-temp-file
1846 "" 1919 ""
1847 ;; XXX: Break early until we can skip stuff. We need to mimic 1920 (let* ((python-shell-interpreter
1848 ;; user interaction because `python-shell-get-or-create-process' 1921 (executable-find python-tests-shell-interpreter))
1849 ;; asks for all arguments interactively when a shell process 1922 (use-dialog-box)
1850 ;; doesn't exist. 1923 (dedicated-process-name (python-shell-get-process-name t))
1851 (should nil) 1924 (dedicated-process
1852 (let* ((python-shell-interpreter 1925 (python-shell-get-or-create-process python-shell-interpreter t))
1853 (executable-find python-tests-shell-interpreter)) 1926 (dedicated-shell-buffer (process-buffer dedicated-process)))
1854 (use-dialog-box) 1927 (unwind-protect
1855 (dedicated-process-name (python-shell-get-process-name t)) 1928 (progn
1856 (dedicated-process (python-shell-get-or-create-process)) 1929 (set-process-query-on-exit-flag dedicated-process nil)
1857 (dedicated-shell-buffer (process-buffer dedicated-process))) 1930 ;; should be dedicated.
1858 (unwind-protect 1931 (should (equal (process-name dedicated-process)
1859 (progn 1932 dedicated-process-name))
1860 (set-process-query-on-exit-flag dedicated-process nil) 1933 (kill-buffer dedicated-shell-buffer)
1861 ;; Prefer dedicated if not buffer exist. 1934 ;; Check there are no processes for current buffer.
1862 (should (equal (process-name dedicated-process) 1935 (should (not (python-shell-get-process))))
1863 dedicated-process-name)) 1936 (ignore-errors (kill-buffer dedicated-shell-buffer))))))
1864 (kill-buffer dedicated-shell-buffer) 1937
1865 ;; No buffer available. 1938(ert-deftest python-shell-get-or-create-process-2 ()
1866 (should (not (python-shell-get-process)))) 1939 "Check shell global process creation."
1867 (ignore-errors (kill-buffer dedicated-shell-buffer)))))) 1940 (skip-unless (executable-find python-tests-shell-interpreter))
1941 (python-tests-with-temp-file
1942 ""
1943 (let* ((python-shell-interpreter
1944 (executable-find python-tests-shell-interpreter))
1945 (use-dialog-box)
1946 (process-name (python-shell-get-process-name nil))
1947 (process
1948 (python-shell-get-or-create-process python-shell-interpreter))
1949 (shell-buffer (process-buffer process)))
1950 (unwind-protect
1951 (progn
1952 (set-process-query-on-exit-flag process nil)
1953 ;; should be global.
1954 (should (equal (process-name process) process-name))
1955 (kill-buffer shell-buffer)
1956 ;; Check there are no processes for current buffer.
1957 (should (not (python-shell-get-process))))
1958 (ignore-errors (kill-buffer dedicated-shell-buffer))))))
1959
1960(ert-deftest python-shell-get-or-create-process-3 ()
1961 "Check shell dedicated/global process preference."
1962 (skip-unless (executable-find python-tests-shell-interpreter))
1963 (python-tests-with-temp-file
1964 ""
1965 (let* ((python-shell-interpreter
1966 (executable-find python-tests-shell-interpreter))
1967 (use-dialog-box)
1968 (dedicated-process-name (python-shell-get-process-name t))
1969 (global-process)
1970 (dedicated-process))
1971 (unwind-protect
1972 (progn
1973 ;; Create global process
1974 (run-python python-shell-interpreter nil)
1975 (setq global-process (get-buffer-process "*Python*"))
1976 (should global-process)
1977 (set-process-query-on-exit-flag global-process nil)
1978 ;; Create dedicated process
1979 (run-python python-shell-interpreter t)
1980 (setq dedicated-process (get-process dedicated-process-name))
1981 (should dedicated-process)
1982 (set-process-query-on-exit-flag dedicated-process nil)
1983 ;; Prefer dedicated.
1984 (should (equal (python-shell-get-or-create-process)
1985 dedicated-process))
1986 ;; Kill the dedicated so the global takes over.
1987 (kill-buffer (process-buffer dedicated-process))
1988 ;; Detect global.
1989 (should (equal (python-shell-get-or-create-process) global-process))
1990 ;; Kill the global.
1991 (kill-buffer (process-buffer global-process))
1992 ;; Check there are no processes for current buffer.
1993 (should (not (python-shell-get-process))))
1994 (ignore-errors (kill-buffer dedicated-shell-buffer))))))
1868 1995
1869(ert-deftest python-shell-internal-get-or-create-process-1 () 1996(ert-deftest python-shell-internal-get-or-create-process-1 ()
1870 "Check internal shell process creation fallback." 1997 "Check internal shell process creation fallback."
1871 (skip-unless (executable-find python-tests-shell-interpreter)) 1998 (skip-unless (executable-find python-tests-shell-interpreter))
1872 (python-tests-with-temp-file 1999 (python-tests-with-temp-file
1873 "" 2000 ""
1874 (should (not (process-live-p (python-shell-internal-get-process-name)))) 2001 (should (not (process-live-p (python-shell-internal-get-process-name))))
1875 (let* ((python-shell-interpreter 2002 (let* ((python-shell-interpreter
1876 (executable-find python-tests-shell-interpreter)) 2003 (executable-find python-tests-shell-interpreter))
1877 (internal-process-name (python-shell-internal-get-process-name)) 2004 (internal-process-name (python-shell-internal-get-process-name))
1878 (internal-process (python-shell-internal-get-or-create-process)) 2005 (internal-process (python-shell-internal-get-or-create-process))
1879 (internal-shell-buffer (process-buffer internal-process))) 2006 (internal-shell-buffer (process-buffer internal-process)))
1880 (unwind-protect 2007 (unwind-protect
1881 (progn 2008 (progn
1882 (set-process-query-on-exit-flag internal-process nil) 2009 (set-process-query-on-exit-flag internal-process nil)
1883 (should (equal (process-name internal-process) 2010 (should (equal (process-name internal-process)
1884 internal-process-name)) 2011 internal-process-name))
1885 (should (equal internal-process 2012 (should (equal internal-process
1886 (python-shell-internal-get-or-create-process))) 2013 (python-shell-internal-get-or-create-process)))
1887 ;; No user buffer available. 2014 ;; Assert the internal process is not a user process
1888 (should (not (python-shell-get-process))) 2015 (should (not (python-shell-get-process)))
1889 (kill-buffer internal-shell-buffer)) 2016 (kill-buffer internal-shell-buffer))
1890 (ignore-errors (kill-buffer internal-shell-buffer)))))) 2017 (ignore-errors (kill-buffer internal-shell-buffer))))))
2018
2019(ert-deftest python-shell-prompt-detect-1 ()
2020 "Check prompt autodetection."
2021 (skip-unless (executable-find python-tests-shell-interpreter))
2022 (let ((process-environment process-environment))
2023 ;; Ensure no startup file is enabled
2024 (setenv "PYTHONSTARTUP" "")
2025 (should python-shell-prompt-detect-enabled)
2026 (should (equal (python-shell-prompt-detect) '(">>> " "... " "")))))
2027
2028(ert-deftest python-shell-prompt-detect-2 ()
2029 "Check prompt autodetection with startup file. Bug#17370."
2030 (skip-unless (executable-find python-tests-shell-interpreter))
2031 (let* ((process-environment process-environment)
2032 (startup-code (concat "import sys\n"
2033 "sys.ps1 = 'py> '\n"
2034 "sys.ps2 = '..> '\n"
2035 "sys.ps3 = 'out '\n"))
2036 (startup-file (python-shell--save-temp-file startup-code)))
2037 (unwind-protect
2038 (progn
2039 ;; Ensure startup file is enabled
2040 (setenv "PYTHONSTARTUP" startup-file)
2041 (should python-shell-prompt-detect-enabled)
2042 (should (equal (python-shell-prompt-detect) '("py> " "..> " "out "))))
2043 (ignore-errors (delete-file startup-file)))))
2044
2045(ert-deftest python-shell-prompt-detect-3 ()
2046 "Check prompts are not autodetected when feature is disabled."
2047 (skip-unless (executable-find python-tests-shell-interpreter))
2048 (let ((process-environment process-environment)
2049 (python-shell-prompt-detect-enabled nil))
2050 ;; Ensure no startup file is enabled
2051 (should (not python-shell-prompt-detect-enabled))
2052 (should (not (python-shell-prompt-detect)))))
2053
2054(ert-deftest python-shell-prompt-detect-4 ()
2055 "Check warning is shown when detection fails."
2056 (skip-unless (executable-find python-tests-shell-interpreter))
2057 (let* ((process-environment process-environment)
2058 ;; Trigger failure by removing prompts in the startup file
2059 (startup-code (concat "import sys\n"
2060 "sys.ps1 = ''\n"
2061 "sys.ps2 = ''\n"
2062 "sys.ps3 = ''\n"))
2063 (startup-file (python-shell--save-temp-file startup-code)))
2064 (unwind-protect
2065 (progn
2066 (kill-buffer (get-buffer-create "*Warnings*"))
2067 (should (not (get-buffer "*Warnings*")))
2068 (setenv "PYTHONSTARTUP" startup-file)
2069 (should python-shell-prompt-detect-failure-warning)
2070 (should python-shell-prompt-detect-enabled)
2071 (should (not (python-shell-prompt-detect)))
2072 (should (get-buffer "*Warnings*")))
2073 (ignore-errors (delete-file startup-file)))))
2074
2075(ert-deftest python-shell-prompt-detect-5 ()
2076 "Check disabled warnings are not shown when detection fails."
2077 (skip-unless (executable-find python-tests-shell-interpreter))
2078 (let* ((process-environment process-environment)
2079 (startup-code (concat "import sys\n"
2080 "sys.ps1 = ''\n"
2081 "sys.ps2 = ''\n"
2082 "sys.ps3 = ''\n"))
2083 (startup-file (python-shell--save-temp-file startup-code))
2084 (python-shell-prompt-detect-failure-warning nil))
2085 (unwind-protect
2086 (progn
2087 (kill-buffer (get-buffer-create "*Warnings*"))
2088 (should (not (get-buffer "*Warnings*")))
2089 (setenv "PYTHONSTARTUP" startup-file)
2090 (should (not python-shell-prompt-detect-failure-warning))
2091 (should python-shell-prompt-detect-enabled)
2092 (should (not (python-shell-prompt-detect)))
2093 (should (not (get-buffer "*Warnings*"))))
2094 (ignore-errors (delete-file startup-file)))))
2095
2096(ert-deftest python-shell-prompt-detect-6 ()
2097 "Warnings are not shown when detection is disabled."
2098 (skip-unless (executable-find python-tests-shell-interpreter))
2099 (let* ((process-environment process-environment)
2100 (startup-code (concat "import sys\n"
2101 "sys.ps1 = ''\n"
2102 "sys.ps2 = ''\n"
2103 "sys.ps3 = ''\n"))
2104 (startup-file (python-shell--save-temp-file startup-code))
2105 (python-shell-prompt-detect-failure-warning t)
2106 (python-shell-prompt-detect-enabled nil))
2107 (unwind-protect
2108 (progn
2109 (kill-buffer (get-buffer-create "*Warnings*"))
2110 (should (not (get-buffer "*Warnings*")))
2111 (setenv "PYTHONSTARTUP" startup-file)
2112 (should python-shell-prompt-detect-failure-warning)
2113 (should (not python-shell-prompt-detect-enabled))
2114 (should (not (python-shell-prompt-detect)))
2115 (should (not (get-buffer "*Warnings*"))))
2116 (ignore-errors (delete-file startup-file)))))
2117
2118(ert-deftest python-shell-prompt-validate-regexps-1 ()
2119 "Check `python-shell-prompt-input-regexps' are validated."
2120 (let* ((python-shell-prompt-input-regexps '("\\("))
2121 (error-data (should-error (python-shell-prompt-validate-regexps)
2122 :type 'user-error)))
2123 (should
2124 (string= (cadr error-data)
2125 "Invalid regexp \\( in `python-shell-prompt-input-regexps'"))))
2126
2127(ert-deftest python-shell-prompt-validate-regexps-2 ()
2128 "Check `python-shell-prompt-output-regexps' are validated."
2129 (let* ((python-shell-prompt-output-regexps '("\\("))
2130 (error-data (should-error (python-shell-prompt-validate-regexps)
2131 :type 'user-error)))
2132 (should
2133 (string= (cadr error-data)
2134 "Invalid regexp \\( in `python-shell-prompt-output-regexps'"))))
2135
2136(ert-deftest python-shell-prompt-validate-regexps-3 ()
2137 "Check `python-shell-prompt-regexp' is validated."
2138 (let* ((python-shell-prompt-regexp "\\(")
2139 (error-data (should-error (python-shell-prompt-validate-regexps)
2140 :type 'user-error)))
2141 (should
2142 (string= (cadr error-data)
2143 "Invalid regexp \\( in `python-shell-prompt-regexp'"))))
2144
2145(ert-deftest python-shell-prompt-validate-regexps-4 ()
2146 "Check `python-shell-prompt-block-regexp' is validated."
2147 (let* ((python-shell-prompt-block-regexp "\\(")
2148 (error-data (should-error (python-shell-prompt-validate-regexps)
2149 :type 'user-error)))
2150 (should
2151 (string= (cadr error-data)
2152 "Invalid regexp \\( in `python-shell-prompt-block-regexp'"))))
2153
2154(ert-deftest python-shell-prompt-validate-regexps-5 ()
2155 "Check `python-shell-prompt-pdb-regexp' is validated."
2156 (let* ((python-shell-prompt-pdb-regexp "\\(")
2157 (error-data (should-error (python-shell-prompt-validate-regexps)
2158 :type 'user-error)))
2159 (should
2160 (string= (cadr error-data)
2161 "Invalid regexp \\( in `python-shell-prompt-pdb-regexp'"))))
2162
2163(ert-deftest python-shell-prompt-validate-regexps-6 ()
2164 "Check `python-shell-prompt-output-regexp' is validated."
2165 (let* ((python-shell-prompt-output-regexp "\\(")
2166 (error-data (should-error (python-shell-prompt-validate-regexps)
2167 :type 'user-error)))
2168 (should
2169 (string= (cadr error-data)
2170 "Invalid regexp \\( in `python-shell-prompt-output-regexp'"))))
2171
2172(ert-deftest python-shell-prompt-validate-regexps-7 ()
2173 "Check default regexps are valid."
2174 ;; should not signal error
2175 (python-shell-prompt-validate-regexps))
2176
2177(ert-deftest python-shell-prompt-set-calculated-regexps-1 ()
2178 "Check regexps are validated."
2179 (let* ((python-shell-prompt-output-regexp '("\\("))
2180 (python-shell--prompt-calculated-input-regexp nil)
2181 (python-shell--prompt-calculated-output-regexp nil)
2182 (python-shell-prompt-detect-enabled nil)
2183 (error-data (should-error (python-shell-prompt-set-calculated-regexps)
2184 :type 'user-error)))
2185 (should
2186 (string= (cadr error-data)
2187 "Invalid regexp \\( in `python-shell-prompt-output-regexp'"))))
2188
2189(ert-deftest python-shell-prompt-set-calculated-regexps-2 ()
2190 "Check `python-shell-prompt-input-regexps' are set."
2191 (let* ((python-shell-prompt-input-regexps '("my" "prompt"))
2192 (python-shell-prompt-output-regexps '(""))
2193 (python-shell-prompt-regexp "")
2194 (python-shell-prompt-block-regexp "")
2195 (python-shell-prompt-pdb-regexp "")
2196 (python-shell-prompt-output-regexp "")
2197 (python-shell--prompt-calculated-input-regexp nil)
2198 (python-shell--prompt-calculated-output-regexp nil)
2199 (python-shell-prompt-detect-enabled nil))
2200 (python-shell-prompt-set-calculated-regexps)
2201 (should (string= python-shell--prompt-calculated-input-regexp
2202 "^\\(prompt\\|my\\|\\)"))))
2203
2204(ert-deftest python-shell-prompt-set-calculated-regexps-3 ()
2205 "Check `python-shell-prompt-output-regexps' are set."
2206 (let* ((python-shell-prompt-input-regexps '(""))
2207 (python-shell-prompt-output-regexps '("my" "prompt"))
2208 (python-shell-prompt-regexp "")
2209 (python-shell-prompt-block-regexp "")
2210 (python-shell-prompt-pdb-regexp "")
2211 (python-shell-prompt-output-regexp "")
2212 (python-shell--prompt-calculated-input-regexp nil)
2213 (python-shell--prompt-calculated-output-regexp nil)
2214 (python-shell-prompt-detect-enabled nil))
2215 (python-shell-prompt-set-calculated-regexps)
2216 (should (string= python-shell--prompt-calculated-output-regexp
2217 "^\\(prompt\\|my\\|\\)"))))
2218
2219(ert-deftest python-shell-prompt-set-calculated-regexps-4 ()
2220 "Check user defined prompts are set."
2221 (let* ((python-shell-prompt-input-regexps '(""))
2222 (python-shell-prompt-output-regexps '(""))
2223 (python-shell-prompt-regexp "prompt")
2224 (python-shell-prompt-block-regexp "block")
2225 (python-shell-prompt-pdb-regexp "pdb")
2226 (python-shell-prompt-output-regexp "output")
2227 (python-shell--prompt-calculated-input-regexp nil)
2228 (python-shell--prompt-calculated-output-regexp nil)
2229 (python-shell-prompt-detect-enabled nil))
2230 (python-shell-prompt-set-calculated-regexps)
2231 (should (string= python-shell--prompt-calculated-input-regexp
2232 "^\\(prompt\\|block\\|pdb\\|\\)"))
2233 (should (string= python-shell--prompt-calculated-output-regexp
2234 "^\\(output\\|\\)"))))
2235
2236(ert-deftest python-shell-prompt-set-calculated-regexps-5 ()
2237 "Check order of regexps (larger first)."
2238 (let* ((python-shell-prompt-input-regexps '("extralargeinputprompt" "sml"))
2239 (python-shell-prompt-output-regexps '("extralargeoutputprompt" "sml"))
2240 (python-shell-prompt-regexp "in")
2241 (python-shell-prompt-block-regexp "block")
2242 (python-shell-prompt-pdb-regexp "pdf")
2243 (python-shell-prompt-output-regexp "output")
2244 (python-shell--prompt-calculated-input-regexp nil)
2245 (python-shell--prompt-calculated-output-regexp nil)
2246 (python-shell-prompt-detect-enabled nil))
2247 (python-shell-prompt-set-calculated-regexps)
2248 (should (string= python-shell--prompt-calculated-input-regexp
2249 "^\\(extralargeinputprompt\\|block\\|pdf\\|sml\\|in\\)"))
2250 (should (string= python-shell--prompt-calculated-output-regexp
2251 "^\\(extralargeoutputprompt\\|output\\|sml\\)"))))
2252
2253(ert-deftest python-shell-prompt-set-calculated-regexps-6 ()
2254 "Check detected prompts are included `regexp-quote'd."
2255 (skip-unless (executable-find python-tests-shell-interpreter))
2256 (let* ((python-shell-prompt-input-regexps '(""))
2257 (python-shell-prompt-output-regexps '(""))
2258 (python-shell-prompt-regexp "")
2259 (python-shell-prompt-block-regexp "")
2260 (python-shell-prompt-pdb-regexp "")
2261 (python-shell-prompt-output-regexp "")
2262 (python-shell--prompt-calculated-input-regexp nil)
2263 (python-shell--prompt-calculated-output-regexp nil)
2264 (python-shell-prompt-detect-enabled t)
2265 (process-environment process-environment)
2266 (startup-code (concat "import sys\n"
2267 "sys.ps1 = 'p.> '\n"
2268 "sys.ps2 = '..> '\n"
2269 "sys.ps3 = 'o.t '\n"))
2270 (startup-file (python-shell--save-temp-file startup-code)))
2271 (unwind-protect
2272 (progn
2273 (setenv "PYTHONSTARTUP" startup-file)
2274 (python-shell-prompt-set-calculated-regexps)
2275 (should (string= python-shell--prompt-calculated-input-regexp
2276 "^\\(\\.\\.> \\|p\\.> \\|\\)"))
2277 (should (string= python-shell--prompt-calculated-output-regexp
2278 "^\\(o\\.t \\|\\)")))
2279 (ignore-errors (delete-file startup-file)))))
1891 2280
1892 2281
1893;;; Shell completion 2282;;; Shell completion
@@ -3230,8 +3619,6 @@ def foo(a, b, c):
3230 (python-shell-extra-pythonpaths "/home/user/pylib/") 3619 (python-shell-extra-pythonpaths "/home/user/pylib/")
3231 (python-shell-completion-setup-code 3620 (python-shell-completion-setup-code
3232 . "from IPython.core.completerlib import module_completion") 3621 . "from IPython.core.completerlib import module_completion")
3233 (python-shell-completion-module-string-code
3234 . "';'.join(module_completion('''%s'''))\n")
3235 (python-shell-completion-string-code 3622 (python-shell-completion-string-code
3236 . "';'.join(get_ipython().Completer.all_completions('''%s'''))\n") 3623 . "';'.join(get_ipython().Completer.all_completions('''%s'''))\n")
3237 (python-shell-virtualenv-path 3624 (python-shell-virtualenv-path
@@ -3269,6 +3656,11 @@ def foo(a, b, c):
3269 (python-util-forward-comment -1) 3656 (python-util-forward-comment -1)
3270 (should (= (point) (point-min))))) 3657 (should (= (point) (point-min)))))
3271 3658
3659(ert-deftest python-util-valid-regexp-p-1 ()
3660 (should (python-util-valid-regexp-p ""))
3661 (should (python-util-valid-regexp-p python-shell-prompt-regexp))
3662 (should (not (python-util-valid-regexp-p "\\("))))
3663
3272 3664
3273;;; Electricity 3665;;; Electricity
3274 3666