;;; python.el --- silly walks for Python -*- coding: iso-8859-1 -*-
-;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009
+;; Free Software Foundation, Inc.
;; Author: Dave Love <fx@gnu.org>
;; Maintainer: FSF
;; Major mode for editing Python, with support for inferior processes.
-;; There is another Python mode, python-mode.el, used by XEmacs and
-;; maintained with Python. That isn't covered by an FSF copyright
-;; assignment, unlike this code, and seems not to be well-maintained
-;; for Emacs (though I've submitted fixes). This mode is rather
-;; simpler and is better in other ways. In particular, using the
-;; syntax functions with text properties maintained by font-lock makes
-;; it more correct with arbitrary string and comment contents.
+;; There is another Python mode, python-mode.el:
+;; http://launchpad.net/python-mode
+;; used by XEmacs, and originally maintained with Python.
+;; That isn't covered by an FSF copyright assignment (?), unlike this
+;; code, and seems not to be well-maintained for Emacs (though I've
+;; submitted fixes). This mode is rather simpler and is better in
+;; other ways. In particular, using the syntax functions with text
+;; properties maintained by font-lock makes it more correct with
+;; arbitrary string and comment contents.
;; This doesn't implement all the facilities of python-mode.el. Some
;; just need doing, e.g. catching exceptions in the inferior Python
;; invoked. Would support multiple processes better.
(when (or new (not (comint-check-proc python-buffer)))
(with-current-buffer
- (let* ((cmdlist (append (python-args-to-list cmd) '("-i")))
+ (let* ((cmdlist
+ (append (python-args-to-list cmd)
+ '("-i" "-c" "import sys; sys.path.remove('')")))
(path (getenv "PYTHONPATH"))
(process-environment ; to import emacs.py
(cons (concat "PYTHONPATH="
current line. The region shifted includes the lines in which START and
END lie. It is an error if any lines in the region are indented less than
COUNT columns."
- (interactive (if mark-active
- (list (region-beginning) (region-end) current-prefix-arg)
- (list (point) (point) current-prefix-arg)))
+ (interactive
+ (if mark-active
+ (list (region-beginning) (region-end) current-prefix-arg)
+ (list (line-beginning-position) (line-end-position) current-prefix-arg)))
(if count
(setq count (prefix-numeric-value count))
(setq count python-indent))
COUNT defaults to `python-indent'. If region isn't active, just shift
current line. The region shifted includes the lines in which START and
END lie."
- (interactive (if mark-active
- (list (region-beginning) (region-end) current-prefix-arg)
- (list (point) (point) current-prefix-arg)))
+ (interactive
+ (if mark-active
+ (list (region-beginning) (region-end) current-prefix-arg)
+ (list (line-beginning-position) (line-end-position) current-prefix-arg)))
(if count
(setq count (prefix-numeric-value count))
(setq count python-indent))
\f
;;;; Skeletons
+(defcustom python-use-skeletons nil
+ "Non-nil means template skeletons will be automagically inserted.
+This happens when pressing \"if<SPACE>\", for example, to prompt for
+the if condition."
+ :type 'boolean
+ :group 'python)
+
(define-abbrev-table 'python-mode-abbrev-table ()
"Abbrev table for Python mode."
:case-fixed t
`(progn
;; Usual technique for inserting a skeleton, but expand
;; to the original abbrev instead if in a comment or string.
- (define-abbrev python-mode-abbrev-table ,name ""
- ',function
- nil t) ; system abbrev
+ (when python-use-skeletons
+ (define-abbrev python-mode-abbrev-table ,name ""
+ ',function
+ nil t)) ; system abbrev
(define-skeleton ,function
,(format "Insert Python \"%s\" template." name)
,@elements)))))
'((< '(backward-delete-char-untabify (min python-indent
(current-column))))
(^ '(- (1+ (current-indentation))))))
- (if (featurep 'hippie-exp)
- (set (make-local-variable 'hippie-expand-try-functions-list)
- (cons 'symbol-completion-try-complete
- hippie-expand-try-functions-list)))
+ ;; Let's not mess with hippie-expand. Symbol-completion should rather be
+ ;; bound to another key, since it has different performance requirements.
+ ;; (if (featurep 'hippie-exp)
+ ;; (set (make-local-variable 'hippie-expand-try-functions-list)
+ ;; (cons 'symbol-completion-try-complete
+ ;; hippie-expand-try-functions-list)))
;; Python defines TABs as being 8-char wide.
(set (make-local-variable 'tab-width) 8)
(unless font-lock-mode (font-lock-mode 1))