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

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

Re: narrow-to-defun has changed since 21.3


From: Richard Stallman
Subject: Re: narrow-to-defun has changed since 21.3
Date: Sun, 16 May 2004 09:20:55 -0400

Does this definition work right?

(defun mark-defun ()
  "Put mark at end of this defun, point at beginning.
The defun marked is the one that contains point or follows point.
If this command is repeated, marks more defuns after the ones
already marked."
  (interactive)
  (cond ((and (eq last-command this-command) (mark t))
         (set-mark
          (save-excursion
            (goto-char (mark))
            (end-of-defun)
            (point))))
        (t
         (let ((opoint (point))
               beg end)
           (push-mark opoint)
           ;; Try first 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)
           (setq beg (point))
           (end-of-defun)
           (setq end (point))
           (while (looking-at "^\n")
             (forward-line 1))
           (if (> (point) opoint)
               (progn
                 ;; We got the right defun.
                 (push-mark beg nil t)
                 (goto-char end)
                 (exchange-point-and-mark))
             ;; beginning-of-defun moved back one defun
             ;; so we got the wrong one.
             (goto-char opoint)
             (end-of-defun)
             (push-mark (point) nil t)
             (beginning-of-defun))
           (re-search-backward "^\n" (- (point) 1) t)))))




reply via email to

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