Hi Barry,
`beginning-of-defun-raw' in GNU Emacs has a nice
feature, enabling functions instead of regexps to
determine beginning and end of defun, i.e. function or form.
In python-mode.el I see you solved this by binding the
beginning- and end-of-defun keys seperatly.
(Maybe, because XEmacs lacks this feature?)
However, this lets commands like M-x beginning-of-defun
empty.
My suggestion is to follow GNU conventions here, by
introducing the missing forms in XEmacs lisp.el and
python-mode.el alike.
Herewith a patch against latest python-mode.el, which I
enjoy, thanks BTW.
Also a patch against latest XEmacs lisp.el.
Best wishes
Andreas Röhler
diff -u -b python-mode.el python-mode.el
--- python-mode.el 2008-11-29 17:29:45.000000000 +0100
+++ python-mode.el 2008-11-29 17:37:18.000000000 +0100
@@ -2652,6 +2652,22 @@
(goto-char start)
(error "Enclosing block not found"))))
+
+;; credits to python.el, defining derived mode
+;; (set (make-local-variable 'beginning-of-defun-function)
+;; 'python-beginning-of-defun)
+;; (set (make-local-variable 'end-of-defun-function) 'python-end-of-defun)
+
+(defun py-beg-of-defun-function ()
+ (set (make-local-variable 'beginning-of-defun-function)
+ 'py-beginning-of-def-or-class))
+
+(defun py-end-of-defun-function ()
+ (set (make-local-variable 'end-of-defun-function) 'py-end-of-def-or-class))
+
+(add-hook 'python-mode-hook 'py-beg-of-defun-function)
+(add-hook 'python-mode-hook 'py-end-of-defun-function)
+
(defun py-beginning-of-def-or-class (&optional class count)
"Move point to start of `def' or `class'.
Diff finished. Sat Nov 29 17:37:44 2008
diff -u lisp.el lisp.el
--- lisp.el 2008-11-29 17:00:18.000000000 +0100
+++ lisp.el 2008-11-29 17:00:18.000000000 +0100
@@ -155,6 +155,21 @@
(interactive "p")
(kill-sexp (- (or arg 1))))
+
+;; derived stuff from GNU Emacs
+(defvar beginning-of-defun-function nil
+ "If non-nil, function for `beginning-of-defun-raw' to call.
+This is used to find the beginning of the defun instead of using the
+normal recipe (see `beginning-of-defun'). Modes can define this
+if defining `defun-prompt-regexp' is not sufficient to handle the mode's
+needs.")
+
+(defvar end-of-defun-function nil
+ "If non-nil, function for `end-of-defun' to call.
+This is used to find the end of the defun instead of using the normal
+recipe (see `end-of-defun'). Modes can define this if the
+normal method is not appropriate.")
+
(defun beginning-of-defun (&optional arg)
"Move backward to the beginning of a defun.
With argument, do it that many times. Negative arg -N
@@ -175,13 +190,19 @@
This is identical to beginning-of-defun, except that point does not move
to the beginning of the line when `defun-prompt-regexp' is non-nil."
(interactive "p")
- (and arg (< arg 0) (not (eobp)) (forward-char 1))
- (and (re-search-backward (if defun-prompt-regexp
- (concat "^\\s(\\|"
- "\\(" defun-prompt-regexp "\\)\\s(")
- "^\\s(")
- nil 'move (or arg 1))
- (progn (goto-char (1- (match-end 0)))) t))
+ ;; (and arg (< arg 0) (not (eobp)) (forward-char 1))
+ (unless arg (setq arg 1))
+ (cond
+ (beginning-of-defun-function
+ (if (> arg 0)
+ (dotimes (i arg)
+ (funcall beginning-of-defun-function))))
+ (t (re-search-backward (if defun-prompt-regexp
+ (concat "^\\s(\\|"
+ "\\(" defun-prompt-regexp "\\)\\s(")
+ "^\\s(")
+ nil 'move (or arg 1))
+ (progn (goto-char (1- (match-end 0)))) t)))
;; XEmacs change (optional buffer parameter)
(defun buffer-end (arg &optional buffer)
@@ -198,6 +219,10 @@
;; XEmacs change (for zmacs regions)
(interactive "_p")
(if (or (null arg) (= arg 0)) (setq arg 1))
+ (if end-of-defun-function
+ (if (> arg 0)
+ (dotimes (i arg)
+ (funcall end-of-defun-function)))
(let ((first t))
(while (and (> arg 0) (< (point) (point-max)))
(let ((pos (point))) ; XEmacs -- remove unused npos.
@@ -229,7 +254,7 @@
(if (looking-at "\\s<\\|\n")
(forward-line 1)))
(goto-char (point-min)))))
- (setq arg (1+ arg)))))
+ (setq arg (1+ arg))))))
(defun mark-defun ()
"Put mark at end of this defun, point at beginning.
_______________________________________________
Python-mode mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-mode