emacs-pretest-bug
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

fixes related to delimiting defuns


From: Dave Love
Subject: fixes related to delimiting defuns
Date: Mon, 12 Jan 2004 15:15:43 +0000
User-agent: Gnus/5.1005 (Gnus v5.10.5) Emacs/21.2 (gnu/linux)

The changes in {beginning,end}-of-defun are a straight bug fix.

As far as I can tell, the mark-defun/narrow-to-defun changes don't
break anything, but allow useful extra cases to work.

2004-01-09  Dave Love  <address@hidden>

        * emacs-lisp/lisp.el (beginning-of-defun-function)
        (end-of-defun-function): Doc fix.  Pass arg to hook function.
        (mark-defun, narrow-to-defun): Change order of finding begin/end.

--- lisp.el.~1.50.~     Wed Sep  3 15:58:56 2003
+++ lisp.el     Fri Jan  9 19:30:04 2004
@@ -153,13 +153,13 @@
 (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').  Major modes can define this
-if defining `defun-prompt-regexp' is not sufficient to handle the mode's
+normal recipe (see `beginning-of-defun').  Major modes can define this if
+defining `defun-prompt-regexp' is not sufficient to handle the mode's
 needs.
 
-The function (of no args) should go to the line on which the current
-defun starts, and return non-nil, or should return nil if it can't
-find the beginning.")
+The function should go to the line on which the current defun starts,
+and return non-nil, or should return nil if it can't find the
+beginning.  It should accept `beginning-of-defun''s optional arg.")
 
 (defun beginning-of-defun (&optional arg)
   "Move backward to the beginning of a defun.
@@ -188,7 +188,7 @@
 is called as a function to find the defun's beginning."
   (interactive "p")
   (if beginning-of-defun-function
-      (funcall beginning-of-defun-function)
+      (funcall beginning-of-defun-function arg)
     (and arg (< arg 0) (not (eobp)) (forward-char 1))
     (and (re-search-backward (if defun-prompt-regexp
                                 (concat (if 
open-paren-in-column-0-is-defun-start
@@ -201,8 +201,9 @@
 (defvar end-of-defun-function nil
   "If non-nil, function for function `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').  Major modes can define this if the
-normal method is not appropriate.")
+recipe (see `end-of-defun').  It should accept `end-of-defun''s
+optional arg.  Major modes can define this if the normal method is not
+appropriate.")
 
 (defun buffer-end (arg)
   (if (> arg 0) (point-max) (point-min)))
@@ -219,7 +220,7 @@
 is called as a function to find the defun's end."
   (interactive "p")
   (if end-of-defun-function
-      (funcall end-of-defun-function)
+      (funcall end-of-defun-function arg)
     (if (or (null arg) (= arg 0)) (setq arg 1))
     (let ((first t))
       (while (and (> arg 0) (< (point) (point-max)))
@@ -267,10 +268,14 @@
            (end-of-defun)
            (point))))
        (t
+        ;; Do it in this order for the sake of languages with nested
+        ;; functions where several can end at the same place as with
+        ;; the offside rule, e.g. Python.
         (push-mark (point))
-        (end-of-defun)
-        (push-mark (point) nil t)
         (beginning-of-defun)
+        (push-mark (point) nil t)
+        (end-of-defun)
+        (exchange-point-and-mark)
         (re-search-backward "^\n" (- (point) 1) t))))
 
 (defun narrow-to-defun (&optional arg)
@@ -280,10 +285,13 @@
   (interactive)
   (save-excursion
     (widen)
-    (end-of-defun)
-    (let ((end (point)))
-      (beginning-of-defun)
-      (narrow-to-region (point) end))))
+    ;; Do it in this order for the sake of languages with nested
+    ;; functions where several can end at the same place as with the
+    ;; offside rule, e.g. Python.
+    (beginning-of-defun)
+    (let ((beg (point)))
+      (end-of-defun)
+      (narrow-to-region beg (point)))))
 
 (defun insert-parentheses (arg)
   "Enclose following ARG sexps in parentheses.  Leave point after open-paren.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]