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

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

Re: fixes related to delimiting defuns


From: Dave Love
Subject: Re: fixes related to delimiting defuns
Date: Fri, 16 Jan 2004 00:25:22 +0000
User-agent: Gnus/5.1005 (Gnus v5.10.5) Emacs/21.2 (gnu/linux)

Richard Stallman <address@hidden> writes:

> Instead of the incompatible change in beginning-of-defun-function, how
> about making beginning-of-defun call beginning-of-defun-function in a
> dotimes loop?

Yes, it's a silly mistake ignoring the incompatibility in stuff I did
offline.

After finding various subtleties in this, I'm not _sure_ just
repeating it need be equivalent to maintaining state in the hook about
where you are at each iteration.  However, it's clear compatibility
trumps that.  I don't know if I cocked this up originally or if the
function around it changed.

Here's a revised patch.

--- lisp.el.~1.50.~     Wed Sep  3 15:58:56 2003
+++ lisp.el     Wed Jan 14 19:32:32 2004
@@ -188,7 +188,8 @@
 is called as a function to find the defun's beginning."
   (interactive "p")
   (if beginning-of-defun-function
-      (funcall beginning-of-defun-function)
+      (dotimes (i (or arg 1))
+       (funcall beginning-of-defun-function))
     (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
@@ -219,7 +220,8 @@
 is called as a function to find the defun's end."
   (interactive "p")
   (if end-of-defun-function
-      (funcall end-of-defun-function)
+      (dotimes (i (or arg 1))
+       (funcall end-of-defun-function))
     (if (or (null arg) (= arg 0)) (setq arg 1))
     (let ((first t))
       (while (and (> arg 0) (< (point) (point-max)))
@@ -267,10 +269,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 +286,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]