python-mode

jredford@lehman.com
Tue, 01 Mar 94 17:34:26 -0500

Well, to follow up what i sent... This adds special recognition of
'# END' as a block delimiter. It could be smarter about it still
though. I also mangled the bindings to overlay 'py-newline-and-indent
on just 'newline as well, since I find that much more useful. If you
dont like that part, just fix lines 157,169.

*** /opt/python/lib/elisp/python-mode.el Thu Feb 10 12:08:18 1994
--- python-mode.el Tue Mar 1 17:25:14 1994
***************
*** 157,164 ****
(mapcar (function (lambda (key)
(define-key
py-mode-map key 'py-newline-and-indent)))
! (where-is-internal 'newline-and-indent))

(mapcar (function
(lambda (x)
(define-key py-mode-map (car x) (cdr x))))
--- 157,169 ----
(mapcar (function (lambda (key)
(define-key
py-mode-map key 'py-newline-and-indent)))
! (where-is-internal 'newline-and-indent))

+ (mapcar (function (lambda (key)
+ (define-key
+ py-mode-map key 'py-newline-and-indent)))
+ (where-is-internal 'newline))
+
(mapcar (function
(lambda (x)
(define-key py-mode-map (car x) (cdr x))))
***************
*** 475,480 ****
--- 480,486 ----
base-text (py-suck-up-leading-text)
base-found-p t))
(error nil))
+ (insert "# END\n")
(delete-char 1) ; toss the dummy character
(delete-horizontal-space)
(indent-to base-indent)
***************
*** 541,547 ****
(py-goto-initial-line)
(if (py-statement-opens-block-p)
(+ (current-indentation) py-indent-offset)
! (current-indentation))))))

(defun py-guess-indent-offset (&optional global)
"Guess a good value for, and change, py-indent-offset.
--- 547,555 ----
(py-goto-initial-line)
(if (py-statement-opens-block-p)
(+ (current-indentation) py-indent-offset)
! (if (py-statement-closes-block-p)
! (- (current-indentation) py-indent-offset)
! (current-indentation)))))))

(defun py-guess-indent-offset (&optional global)
"Guess a good value for, and change, py-indent-offset.
***************
*** 1475,1480 ****
--- 1483,1510 ----
(match-beginning 0)))
(setq answer (not (nth 4 state)))))
;; search failed: couldn't find another interesting colon
+ (setq searching nil)))
+ answer)))
+
+ ;; True iff line contains "# END"
+ ;; point should be at the start of a statement
+ (defun py-statement-closes-block-p ()
+ (save-excursion
+ (let ( (start (point))
+ (finish (progn (py-goto-beyond-final-line) (1- (point))))
+ (searching t)
+ (answer nil)
+ state)
+ (goto-char start)
+ (while searching
+ ;; look for "# END"
+ (if (re-search-forward "# END$"
+ finish t)
+ (if (eq (point) finish)
+ (progn
+ (setq searching nil)
+ (setq answer t)))
+ ;; search failed
(setq searching nil)))
answer)))

--
John Redford (AKA GArrow) | 3,600 hours of tape.
jredford@lehman.com       | 5 cans of Scotchguard.