summaryrefslogtreecommitdiffstats
path: root/Misc/python-mode.el
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>1999-07-28 21:59:43 (GMT)
committerBarry Warsaw <barry@python.org>1999-07-28 21:59:43 (GMT)
commit11f215607e2c59741d21dc5957fbb7c4c89953b1 (patch)
tree2e112f9cca542d5bd41e565f262d0681ae7ea937 /Misc/python-mode.el
parent2ab455a8fa946cb8d599018c2f861f1fe909c545 (diff)
downloadcpython-11f215607e2c59741d21dc5957fbb7c4c89953b1.zip
cpython-11f215607e2c59741d21dc5957fbb7c4c89953b1.tar.gz
cpython-11f215607e2c59741d21dc5957fbb7c4c89953b1.tar.bz2
(python-mode): Set which interpreter (CPython or JPython) to use the
first time a py buffer is visited during the Emacs session. This ensures that py-which-shells is initialized and also guarantees that the mode lines reflect the correct shell. First bug found by GvR, second one has long bugged :) me. (py-toggle-shells): Programmatically, arg can also take the symbols `cpython' or `jpython', which makes it easy to call with the value of py-default-interpreter. (py-shell): Don't need to initialize py-which-* variables since these will guarantee to be initialized by python-mode when the first py buffer is visited. (py-default-interpreter): Update docstring.
Diffstat (limited to 'Misc/python-mode.el')
-rw-r--r--Misc/python-mode.el39
1 files changed, 21 insertions, 18 deletions
diff --git a/Misc/python-mode.el b/Misc/python-mode.el
index 643f2f2..130c6db 100644
--- a/Misc/python-mode.el
+++ b/Misc/python-mode.el
@@ -121,8 +121,8 @@ When the value is `jpython', the variables `py-jpython-command' and
`py-jpython-command-args' are consulted to determine the interpreter
and arguments to use.
-Note that this variable is consulted only the first time that a Python
-interpreter shell is started during an Emacs session. After that, use
+Note that this variable is consulted only the first time that a Python
+mode buffer is visited during an Emacs session. After that, use
\\[py-toggle-shells] to change the interpreter shell."
:type '(choice (const :tag "Python (a.k.a. CPython)" cpython)
(const :tag "JPython" jpython))
@@ -989,7 +989,11 @@ py-beep-if-tab-change\t\tring the bell if `tab-width' is changed"
;; have explicitly turned it off.
(if (/= tab-width py-indent-offset)
(setq indent-tabs-mode nil))
- )))
+ ))
+ ;; Set the default shell if not already set
+ (when (null py-which-shell)
+ (py-toggle-shells py-default-interpreter))
+ )
;; electric characters
@@ -1122,18 +1126,26 @@ If an exception occurred return t, otherwise return nil. BUF must exist."
(defun py-toggle-shells (arg)
"Toggles between the CPython and JPython shells.
+
With positive argument ARG (interactively \\[universal-argument]),
uses the CPython shell, with negative ARG uses the JPython shell, and
-with a zero argument, toggles the shell."
+with a zero argument, toggles the shell.
+
+Programmatically, ARG can also be one of the symbols `cpython' or
+`jpython', equivalent to positive arg and negative arg respectively."
(interactive "P")
;; default is to toggle
(if (null arg)
(setq arg 0))
- ;; toggle if zero
- (if (= arg 0)
- (if (string-equal py-which-bufname "Python")
- (setq arg -1)
- (setq arg 1)))
+ ;; preprocess arg
+ (cond
+ ((equal arg 0)
+ ;; toggle
+ (if (string-equal py-which-bufname "Python")
+ (setq arg -1)
+ (setq arg 1)))
+ ((equal arg 'cpython) (setq arg 1))
+ ((equal arg 'jpython) (setq arg -1)))
(let (msg)
(cond
((< 0 arg)
@@ -1192,15 +1204,6 @@ interaction between undo and process filters; the same problem exists in
non-Python process buffers using the default (Emacs-supplied) process
filter."
(interactive "P")
- (if (null py-which-shell)
- (cond ((eq py-default-interpreter 'cpython)
- (setq py-which-shell py-python-command
- py-which-args py-python-command-args))
- ((eq py-default-interpreter 'jpython)
- (setq py-which-shell py-jpython-command
- py-which-args py-jpython-command-args))
- (t (error "Illegal value for `py-default-interpreter': %s"
- py-default-interpreter))))
(let ((args py-which-args))
(when (and argprompt
(interactive-p)