From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Joe Corneli Newsgroups: gmane.emacs.help Subject: need double save-excursion -- why? Date: Thu, 25 Dec 2003 15:30:03 -0600 Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: References: NNTP-Posting-Host: deer.gmane.org X-Trace: sea.gmane.org 1072387904 30349 80.91.224.253 (25 Dec 2003 21:31:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 25 Dec 2003 21:31:44 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Dec 25 22:31:40 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AZd52-0005xa-00 for ; Thu, 25 Dec 2003 22:31:40 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AZe1g-00031R-VI for geh-help-gnu-emacs@m.gmane.org; Thu, 25 Dec 2003 17:32:16 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AZe1U-00031A-8H for help-gnu-emacs@gnu.org; Thu, 25 Dec 2003 17:32:04 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AZe0y-0002xs-FO for help-gnu-emacs@gnu.org; Thu, 25 Dec 2003 17:32:03 -0500 Original-Received: from [146.6.139.124] (helo=dell3.ma.utexas.edu) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AZe0y-0002xj-2W for help-gnu-emacs@gnu.org; Thu, 25 Dec 2003 17:31:32 -0500 Original-Received: from linux184.ma.utexas.edu (mail@linux184.ma.utexas.edu [146.6.139.173]) by dell3.ma.utexas.edu (8.11.0.Beta3/8.10.2) with ESMTP id hBPLU4B32031; Thu, 25 Dec 2003 15:30:04 -0600 Original-Received: from jcorneli by linux184.ma.utexas.edu with local (Exim 3.36 #1 (Debian)) id 1AZd3T-0008CG-00; Thu, 25 Dec 2003 15:30:03 -0600 Original-To: help-gnu-emacs@gnu.org In-reply-to: (help-gnu-emacs-request@gnu.org) X-all-your-base-are-belong-to-us: You are on the way to destruction. X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:15583 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:15583 When I run the function below on a file containing things like this: #################################################################### \section{{ lefschetz}} (lefschetz number of a map) \defn{ \item $X$ smooth compact manifold \item $g:X\rightarrow X$ continuous \item $G: X\rightarrow X\times X$ \item $G(x)=(x,g(x))$ \item $\#(G,\text{diagonal}(M\times M))$} (global lefschetz number of a map: see ``lefschetz number of a map'') (global lefschetz number: fact: smooth lefschetz fixed point theorem) \defn{ \item $X$ compact orientable manifold \item $f:X\rightarrow X$ smooth \item $L(f)\neq 0$ \item $f$ has a fixed point} (lefschetz fixed point) \defn{ \item $f:X\rightarrow X$ \item $f(x)=x$ \item $+1$ is not an eigenvalue of $df_x:T_x(X)\rightarrow T_x(X)$} #################################################################### I don't get good results: the outermost save-excursion is ignored, and the cursor winds up near the bottom of the document. However, if I wrap another save-excursion around the currently outermost one, the second one is heeded and point is restored properly. Can anyone tell me this is necessary? Something like this is documented in the Emacs Lisp Intro info file, but I don't understand why a double layer of save-excursions is needed here. (defun xi-grab-matching-defn-by-tagline (regexp) "Grab the defns whose taglines contain a match for this regexp." (interactive "MRegex: ") (save-excursion (beginning-of-buffer) ;; start at the beginning (while (not (eobp)) (let ((found (search-forward-regexp (concat "^(.*" regexp ".*)") nil t))) (if found (let* ((beg (save-excursion (beginning-of-line) (point))) (end (save-excursion (end-of-line) (search-forward-regexp "^$" nil t) (beginning-of-line) (point))) ; cut right before that (entry (buffer-substring beg end))) (save-excursion (set-buffer (get-buffer-create "CONCAT.tex")) (insert entry))) (end-of-buffer))))))