22
33; ; Copyright (C) 1992,1993,1994 Tim Peters
44
5- ; ; Author: 1995 Barry A. Warsaw <[email protected] > 6- ; ; 1992-1994 Tim Peters <[email protected] > 7- 5+ ; ; Author: 1995 Barry A. Warsaw
6+ ; ; 1992-1994 Tim Peters
7+ 88; ; Created: Feb 1992
9- ; ; Version: 2.19
10- ; ; Last Modified: 1995/03/20 18:32:14
9+ ; ; Version: 2.26
10+ ; ; Last Modified: 1995/07/05 23:26:15
1111; ; Keywords: python editing language major-mode
1212
1313; ; This software is provided as-is, without express or implied
5858; ; - even better support for outdenting. Guido suggests outdents of
5959; ; at least one level after a return, raise, break, or continue
6060; ; statement.
61+ ; ; - de-electrify colon inside literals (e.g. comments and strings)
6162
6263; ; If you can think of more things you'd like to see, drop me a line.
6364; ; If you want to report bugs, use py-submit-bug-report (C-c C-b).
6768; ; patches.
6869
6970; ; LCD Archive Entry:
70- ; ; python-mode|Barry A. Warsaw|[email protected] 71+ ; ; python-mode|Barry A. Warsaw|[email protected] 7172; ; |Major mode for editing Python programs
72- ; ; |1995/03/20 18:32:14 |2.19 |
73+ ; ; |1995/07/05 23:26:15 |2.26 |
7374
7475; ;; Code:
7576
@@ -162,30 +163,75 @@ equal <number>, `tab-width' is set to <number>, a message saying so is
162163displayed in the echo area, and if `py-beep-if-tab-change' is non-nil
163164the Emacs bell is also rung as a warning." )
164165
166+ ; ; These were the previous font-lock keywords, but I think I now
167+ ; ; prefer the ones from XEmacs 19.12's font-lock.el. I've merged the
168+ ; ; two into the new definition below.
169+ ; ;
170+ ; ;(defvar python-font-lock-keywords
171+ ; ; (list
172+ ; ; (cons
173+ ; ; (concat
174+ ; ; "\\ <\\ ("
175+ ; ; (mapconcat
176+ ; ; 'identity
177+ ; ; '("access" "and" "break" "continue"
178+ ; ; "del" "elif" "else" "except"
179+ ; ; "exec" "finally" "for" "from"
180+ ; ; "global" "if" "import" "in"
181+ ; ; "is" "lambda" "not" "or"
182+ ; ; "pass" "print" "raise" "return"
183+ ; ; "try" "while" "def" "class"
184+ ; ; )
185+ ; ; "\\ |")
186+ ; ; "\\ )\\ >")
187+ ; ; 1)
188+ ; ; ;; functions
189+ ; ; '("\\ bdef\\ s +\\ (\\ sw+\\ )(" 1 font-lock-function-name-face)
190+ ; ; ;; classes
191+ ; ; '("\\ bclass\\ s +\\ (\\ sw+\\ )[(:]" 1 font-lock-function-name-face)
192+ ; ; )
193+ ; ; "*Additional keywords to highlight `python-mode' buffers.")
194+
195+ ; ; These are taken from XEmacs 19.12's font-lock.el file, but have the
196+ ; ; more complete list of keywords from the previous definition in
197+ ; ; python-mode.el. There are a few other minor stylistic changes as
198+ ; ; well.
199+ ; ;
165200(defvar python-font-lock-keywords
166- (list
167- (cons
168- (concat
169- " \\ <\\ ("
170- (mapconcat
171- 'identity
172- '(" access" " and" " break" " continue"
173- " del" " elif" " else" " except"
174- " exec" " finally" " for" " from"
175- " global" " if" " import" " in"
176- " is" " lambda" " not" " or"
177- " pass" " print" " raise" " return"
178- " try" " while" " def" " class"
179- )
180- " \\ |" )
181- " \\ )\\ >" )
182- 1 )
183- ; ; functions
184- '(" \\ bdef\\ s +\\ (\\ sw+\\ )(" 1 font-lock-function-name-face )
185- ; ; classes
186- '(" \\ bclass\\ s +\\ (\\ sw+\\ )[(:]" 1 font-lock-function-name-face )
187- )
188- " *Additional keywords to highlight `python-mode' buffers." )
201+ (list
202+ (cons (concat
203+ " \\ b\\ ("
204+ (mapconcat
205+ 'identity
206+ '(" access" " and" " break" " continue"
207+ " del" " elif" " else:" " except"
208+ " except:" " exec" " finally:" " for"
209+ " from" " global" " if" " import"
210+ " in" " is" " lambda" " not"
211+ " or" " pass" " print" " raise"
212+ " return" " try:" " while"
213+ )
214+ " \\ |" )
215+ " \\ )[ \n\t (]" )
216+ 1 )
217+ ; ; classes
218+ '(" \\ bclass[ \t ]+\\ ([a-zA-Z_]+[a-zA-Z0-9_]*\\ )"
219+ 1 font-lock-type-face )
220+ ; ; functions
221+ '(" \\ bdef[ \t ]+\\ ([a-zA-Z_]+[a-zA-Z0-9_]*\\ )"
222+ 1 font-lock-function-name-face )
223+ )
224+ " *Additional expressions to highlight in Python mode." )
225+
226+ ; ; R Lindsay Todd <[email protected] > suggests these changes to the227+ ; ; original keywords, which wouldn't be necessary if we go with the
228+ ; ; XEmacs defaults, but which I agree makes sense without them.
229+ ; ;
230+ ; ; functions
231+ ; ; '("\\ bdef\\ s +\\ (\\ sw+\\ )\\ s *(" 1 font-lock-function-name-face)
232+ ; ; classes
233+ ; ; '("\\ bclass\\ s +\\ (\\ sw+\\ )\\ s *[(:]" 1 font-lock-type-face)
234+
189235
190236
191237; ; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
@@ -525,7 +571,8 @@ filter."
525571 (progn
526572 (require 'shell )
527573 (switch-to-buffer-other-window
528- (make-shell " Python" py-python-command))))
574+ (apply (if (boundp 'make-shell ) 'make-shell 'make-comint )
575+ " Python" py-python-command nil ))))
529576 (make-local-variable 'shell-prompt-pattern )
530577 (setq shell-prompt-pattern " ^>>> \\ |^\\ .\\ .\\ . " )
531578 (set-process-filter (get-buffer-process (current-buffer ))
@@ -615,6 +662,7 @@ See the `\\[py-shell]' docs for additional warnings."
615662 (set-buffer pbuf)
616663 (let* ((start (point ))
617664 (goback (< start pmark))
665+ (goend (and (not goback) (= start (point-max ))))
618666 (buffer-read-only nil ))
619667 (goto-char pmark)
620668 (insert string)
@@ -631,14 +679,18 @@ See the `\\[py-shell]' docs for additional warnings."
631679 (if py-scroll-process-buffer
632680 (let* ((pop-up-windows t )
633681 (pwin (display-buffer pbuf)))
634- (set-window-point pwin (point ))))))
635- (set-buffer curbuf)
636- (if file-finished
637- (progn
638- (py-delete-file-silently (car py-file-queue))
639- (setq py-file-queue (cdr py-file-queue))
640- (if py-file-queue
641- (py-execute-file pyproc (car py-file-queue)))))))
682+ (set-window-point pwin (point )))))
683+ (set-buffer curbuf)
684+ (if file-finished
685+ (progn
686+ (py-delete-file-silently (car py-file-queue))
687+ (setq py-file-queue (cdr py-file-queue))
688+ (if py-file-queue
689+ (py-execute-file pyproc (car py-file-queue)))))
690+ (and goend
691+ (progn (set-buffer pbuf)
692+ (goto-char (point-max ))))
693+ )))
642694
643695(defun py-execute-buffer ()
644696 " Send the contents of the buffer to a Python interpreter.
@@ -1893,10 +1945,12 @@ local bindings to py-newline-and-indent."))
18931945 (set-buffer pbuf)
18941946 (goto-char (point-max ))
18951947 (move-marker (process-mark process) (point ))
1896- (if (not py-this-is-emacs-19-p)
1948+ (if (not (or py-this-is-emacs-19-p
1949+ py-this-is-lucid-emacs-p))
18971950 (move-marker last-input-start (point ))) ; muck w/ shell-mode
18981951 (funcall (process-filter process) process string)
1899- (if (not py-this-is-emacs-19-p)
1952+ (if (not (or py-this-is-emacs-19-p
1953+ py-this-is-lucid-emacs-p))
19001954 (move-marker last-input-end (point ))) ; muck w/ shell-mode
19011955 (set-buffer cbuf))
19021956 (sit-for 0 ))
@@ -1910,9 +1964,9 @@ local bindings to py-newline-and-indent."))
19101964 (setq zmacs-region-stays t )))
19111965
19121966
1913- (defconst py-version " 2.19 "
1967+ (defconst py-version " 2.26 "
19141968 " `python-mode' version number." )
1915- (
defconst py-help-address " [email protected] " 1969+ (
defconst py-help-address " [email protected] " 19161970 " Address accepting submission of bug reports." )
19171971
19181972(defun py-version ()
0 commit comments