help-gnu-emacs
[Top][All Lists]
Advanced

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

need double save-excursion -- why?


From: Joe Corneli
Subject: need double save-excursion -- why?
Date: Thu, 25 Dec 2003 15:30:03 -0600

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))))))




reply via email to

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