comparison lisp/progmodes/python.el @ 111752:3776ded7f730

Make the sys.path remove in Python mode customizable (Bug#7454). * progmodes/python.el (run-python): Doc fix. (python-keep-current-directory-in-path): New var (Bug#7454).
author Chong Yidong <cyd@stupidchicken.com>
date Sun, 21 Nov 2010 11:52:05 -0500
parents 372e746a38d7
children f84b2c2c0b1b
comparison
equal deleted inserted replaced
111751:26fa428c5896 111752:3776ded7f730
1424 "Input matching this regexp is not saved on the history list. 1424 "Input matching this regexp is not saved on the history list.
1425 Default ignores all inputs of 0, 1, or 2 non-blank characters." 1425 Default ignores all inputs of 0, 1, or 2 non-blank characters."
1426 :type 'regexp 1426 :type 'regexp
1427 :group 'python) 1427 :group 'python)
1428 1428
1429 (defcustom python-remove-cwd-from-path t
1430 "Whether to allow loading of Python modules from the current directory.
1431 If this is non-nil, Emacs removes '' from sys.path when starting
1432 an inferior Python process. This is the default, for security
1433 reasons, as it is easy for the Python process to be started
1434 without the user's realization (e.g. to perform completion)."
1435 :type 'boolean
1436 :group 'python
1437 :version "23.3")
1438
1429 (defun python-input-filter (str) 1439 (defun python-input-filter (str)
1430 "`comint-input-filter' function for inferior Python. 1440 "`comint-input-filter' function for inferior Python.
1431 Don't save anything for STR matching `inferior-python-filter-regexp'." 1441 Don't save anything for STR matching `inferior-python-filter-regexp'."
1432 (not (string-match inferior-python-filter-regexp str))) 1442 (not (string-match inferior-python-filter-regexp str)))
1433 1443
1521 (setq python-version-checked t))) 1531 (setq python-version-checked t)))
1522 1532
1523 ;;;###autoload 1533 ;;;###autoload
1524 (defun run-python (&optional cmd noshow new) 1534 (defun run-python (&optional cmd noshow new)
1525 "Run an inferior Python process, input and output via buffer *Python*. 1535 "Run an inferior Python process, input and output via buffer *Python*.
1526 CMD is the Python command to run. NOSHOW non-nil means don't show the 1536 CMD is the Python command to run. NOSHOW non-nil means don't
1527 buffer automatically. 1537 show the buffer automatically.
1528 1538
1529 Normally, if there is a process already running in `python-buffer', 1539 Interactively, a prefix arg means to prompt for the initial
1530 switch to that buffer. Interactively, a prefix arg allows you to edit 1540 Python command line (default is `python-command').
1531 the initial command line (default is `python-command'); `-i' etc. args 1541
1532 will be added to this as appropriate. A new process is started if: 1542 A new process is started if one isn't running attached to
1533 one isn't running attached to `python-buffer', or interactively the 1543 `python-buffer', or if called from Lisp with non-nil arg NEW.
1534 default `python-command', or argument NEW is non-nil. See also the 1544 Otherwise, if a process is already running in `python-buffer',
1535 documentation for `python-buffer'. 1545 switch to that buffer.
1536 1546
1537 Runs the hook `inferior-python-mode-hook' \(after the 1547 This command runs the hook `inferior-python-mode-hook' after
1538 `comint-mode-hook' is run). \(Type \\[describe-mode] in the process 1548 running `comint-mode-hook'. Type \\[describe-mode] in the
1539 buffer for a list of commands.)" 1549 process buffer for a list of commands.
1550
1551 By default, Emacs inhibits the loading of Python modules from the
1552 current working directory, for security reasons. To disable this
1553 behavior, change `python-remove-cwd-from-path' to nil."
1540 (interactive (if current-prefix-arg 1554 (interactive (if current-prefix-arg
1541 (list (read-string "Run Python: " python-command) nil t) 1555 (list (read-string "Run Python: " python-command) nil t)
1542 (list python-command))) 1556 (list python-command)))
1543 (unless cmd (setq cmd python-command)) 1557 (unless cmd (setq cmd python-command))
1544 (python-check-version cmd) 1558 (python-check-version cmd)
1547 ;; (not a name) in Python buffers from which `run-python' &c is 1561 ;; (not a name) in Python buffers from which `run-python' &c is
1548 ;; invoked. Would support multiple processes better. 1562 ;; invoked. Would support multiple processes better.
1549 (when (or new (not (comint-check-proc python-buffer))) 1563 (when (or new (not (comint-check-proc python-buffer)))
1550 (with-current-buffer 1564 (with-current-buffer
1551 (let* ((cmdlist 1565 (let* ((cmdlist
1552 (append (python-args-to-list cmd) 1566 (append (python-args-to-list cmd) '("-i")
1553 ;; See http://lists.gnu.org/archive/html/emacs-devel/2008-09/msg00215.html 1567 (if python-remove-cwd-from-path
1554 '("-i" "-c" "import sys; sys.path.remove('')"))) 1568 '("-c" "import sys; sys.path.remove('')"))))
1555 (path (getenv "PYTHONPATH")) 1569 (path (getenv "PYTHONPATH"))
1556 (process-environment ; to import emacs.py 1570 (process-environment ; to import emacs.py
1557 (cons (concat "PYTHONPATH=" 1571 (cons (concat "PYTHONPATH="
1558 (if path (concat path path-separator)) 1572 (if path (concat path path-separator))
1559 data-directory) 1573 data-directory)