(add-to-list 'interpreter-mode-alist (cons (purecopy "python") 'python-mode))
;;;###autoload
(add-to-list 'auto-mode-alist (cons (purecopy "\\.py\\'") 'python-mode))
-(add-to-list 'same-window-buffer-names (purecopy "*Python*"))
\f
;;;; Font lock
"import" "in" "is" "lambda" "not" "or" "pass" "print"
"raise" "return" "try" "while" "with" "yield"
;; Not real keywords, but close enough to be fontified as such
- "self" "True" "False")
+ "self" "True" "False"
+ ;; Python 3
+ "nonlocal")
symbol-end)
(,(rx symbol-start "None" symbol-end) ; see ยง Keywords in 2.7 manual
. font-lock-constant-face)
(1 font-lock-type-face))
;; Built-ins. (The next three blocks are from
;; `__builtin__.__dict__.keys()' in Python 2.7) These patterns
- ;; are debateable, but they at least help to spot possible
+ ;; are debatable, but they at least help to spot possible
;; shadowing of builtins.
(,(rx symbol-start (or
;; exceptions
:filter (lambda (&rest junk)
(abbrev-table-menu python-mode-abbrev-table)))
"-"
- ["Start interpreter" python-shell
+ ["Start interpreter" run-python
:help "Run `inferior' Python in separate buffer"]
["Import/reload file" python-load-file
:help "Load into inferior Python session"]
;; eric has items including: (un)indent, (un)comment, restart script,
;; run script, debug script; also things for profiling, unit testing.
-(defvar python-shell-map
- (let ((map (copy-keymap comint-mode-map)))
- (define-key map [tab] 'tab-to-tab-stop)
- (define-key map "\C-c-" 'py-up-exception)
- (define-key map "\C-c=" 'py-down-exception)
- map)
- "Keymap used in *Python* shell buffers.")
-
(defvar python-mode-syntax-table
(let ((table (make-syntax-table)))
;; Give punctuation syntax to ASCII that normally has symbol
"^> \\(.*\\)(\\([0-9]+\\))\\([?a-zA-Z0-9_<>]+\\)()"
"Regular expression pdbtrack uses to find a stack trace entry.")
-(defconst python-pdbtrack-input-prompt "\n[(<]*[Pp]db[>)]+ "
+(defconst python-pdbtrack-input-prompt "\n[(<]*[Ii]?[Pp]db[>)]+ "
"Regular expression pdbtrack uses to recognize a pdb prompt.")
(defconst python-pdbtrack-track-range 10000
"Go to start of current statement.
Accounts for continuation lines, multi-line strings, and
multi-line bracketed expressions."
- (beginning-of-line)
- (python-beginning-of-string)
- (let (point)
- (while (and (python-continuation-line-p)
- (if point
- (< (point) point)
- t))
- (beginning-of-line)
+ (while
(if (python-backslash-continuation-line-p)
- (progn
- (forward-line -1)
- (while (python-backslash-continuation-line-p)
- (forward-line -1)))
- (python-beginning-of-string)
- (python-skip-out))
- (setq point (point))))
+ (progn (forward-line -1) t)
+ (beginning-of-line)
+ (or (python-beginning-of-string)
+ (python-skip-out))))
(back-to-indentation))
(defun python-skip-out (&optional forward syntax)
Skip forward if FORWARD is non-nil, else backward.
If SYNTAX is non-nil it is the state returned by `syntax-ppss' at point.
Return non-nil if and only if skipping was done."
+ ;; FIXME: Use syntax-ppss-toplevel-pos.
(let ((depth (syntax-ppss-depth (or syntax (syntax-ppss))))
(forward (if forward -1 1)))
(unless (zerop depth)
\f
;;;; Imenu.
-;; For possibily speeding this up, here's the top of the ELP profile
+;; For possibly speeding this up, here's the top of the ELP profile
;; for rescanning pydoc.py (2.2k lines, 90kb):
;; Function Name Call Count Elapsed Time Average Time
;; ==================================== ========== ============= ============
(define-key map "\C-c\C-l" 'python-load-file)
(define-key map "\C-c\C-v" 'python-check)
;; Note that we _can_ still use these commands which send to the
- ;; Python process even at the prompt iff we have a normal prompt,
+ ;; Python process even at the prompt if we have a normal prompt,
;; i.e. '>>> ' and not '... '. See the comment before
;; python-send-region. Fixme: uncomment these if we address that.
(if path (concat path path-separator))
data-directory)
process-environment))
- ;; If we use a pipe, unicode characters are not printed
+ ;; If we use a pipe, Unicode characters are not printed
;; correctly (Bug#5794) and IPython does not work at
;; all (Bug#5390).
(process-connection-type t))
(declare-function info-lookup-maybe-add-help "info-look" (&rest arg))
+;;;###autoload
(defun python-after-info-look ()
"Set up info-look for Python.
Used with `eval-after-load'."
(autoload 'pymacs-load "pymacs" nil t)
(autoload 'brm-init "bikemacs")
+(defvar brm-menu)
;; I'm not sure how useful BRM really is, and it's certainly dangerous
;; the way it modifies files outside Emacs... Also note that the
(features (cons 'python-mode features))) ; and requires this
(brm-init) ; second line of normal recipe
(remove-hook 'python-mode-hook ; undo this from `brm-init'
- '(lambda () (easy-menu-add brm-menu)))
+ (lambda () (easy-menu-add brm-menu)))
(easy-menu-define
python-brm-menu python-mode-map
"Bicycle Repair Man"
(defvar python-mode-running) ;Dynamically scoped var.
;;;###autoload
-(define-derived-mode python-mode fundamental-mode "Python"
+(define-derived-mode python-mode prog-mode "Python"
"Major mode for editing Python files.
Turns on Font Lock mode unconditionally since it is currently required
for correct parsing of the source.
most recently visited python-mode buffer which either has the
name of the current function or class, or which defines the
function or class. This is to provide for scripts not in the
-local filesytem (e.g., Zope's 'Script \(Python)', but it's not
+local file system (e.g., Zope's 'Script \(Python)', but it's not
Zope specific). If you put a copy of the script in a buffer
named for the script and activate python-mode, then pdbtrack will
find it."
(if (not (string-match (concat python-pdbtrack-input-prompt "$") block))
(python-pdbtrack-overlay-arrow nil)
+ (setq block (ansi-color-filter-apply block))
(setq target (python-pdbtrack-get-source-buffer block))
(if (stringp target)
(defun python-sentinel (_proc _msg)
(setq overlay-arrow-position nil))
+(defun python-unload-function ()
+ "Unload the Python library."
+ (remove-hook 'comint-output-filter-functions 'python-pdbtrack-track-stack-file)
+ (setq minor-mode-alist (assq-delete-all 'python-pdbtrack-is-tracking-p
+ minor-mode-alist))
+ (dolist (error '("^No symbol" "^Can't shift all lines enough"))
+ (setq debug-ignored-errors (delete error debug-ignored-errors)))
+ ;; continue standard unloading
+ nil)
+
(provide 'python)
(provide 'python-21)