[OS X Emacs] Re: reftex configuration problem?

David Reitter david.reitter at gmail.com
Tue Jul 21 12:48:10 EDT 2009


Thank you, I understand now.

The problem is that in `reftex-query-index-phrase', the call to `read- 
char-exclusive'  destroys the match-string, resulting in the wrong  
region being modified.

This seems to occur in read_filtered_event(), but I don't know why and  
where.

Wrapping the call to read-char-exclusive in `save-match-string'  
prevents the bug (see below), but of course if would be interesting to  
see why the match string gets destroyed in the first place.  I haven't  
found anything obvious in Aquamacs (use of "search-forward"), so it's  
got to be some form of configuration that we're using.

FWIW It's almost certainly a bug in the underlying Emacs.


--
http://aquamacs.org -- Aquamacs: Emacs on Mac OS X
http://aquamacs.org/donate -- Could we help you? Return the favor and  
support the Aquamacs Project!


(defun reftex-query-index-phrase (phrase macro-fmt &optional
                                          index-key repeat as-words)
   "Search through buffer for PHRASE, and offer to replace it with an  
indexed
version.  The index version is derived by applying `format' with MACRO- 
FMT
to INDEX-KEY or PHRASE.  When REPEAT is non-nil, the PHRASE is inserted
again after the macro.
AS-WORDS means, the search for PHRASE should require word boundaries at
both ends."
   (let* ((re (reftex-index-make-phrase-regexp phrase as-words 'allow- 
newline))
          (case-fold-search reftex-index-phrases-case-fold-search)
          (index-keys (split-string
                       (or index-key phrase)
                       reftex-index-phrases-logical-or-regexp))
          (nkeys (length index-keys))
          (ckey (nth 0 index-keys))
          (all-yes nil)
          match rpl char (beg (make-marker)) (end (make-marker)) mathp)
     (move-marker beg 1)
     (move-marker end 1)
     (unwind-protect
         (while (re-search-forward re nil t)
           (catch 'next-match
             (if (reftex-in-comment)
                 (throw 'next-match nil))
             (if (and (fboundp reftex-index-verify-function)
                      (not (funcall reftex-index-verify-function)))
                 (throw 'next-match nil))
             (setq match (match-string 0))
             (setq mathp
                   (save-match-data
                     (condition-case nil (texmathp) (error nil))))
             (setq beg (move-marker beg (match-beginning 0))
                   end (move-marker end (match-end 0)))
             (if (and reftex-index-phrases-skip-indexed-matches
                      (save-match-data
                        (reftex-index-phrase-match-is-indexed beg
                                                              end)))
                 (throw 'next-match nil))
             (reftex-highlight 0 (match-beginning 0) (match-end 0))
             (setq rpl
                   (save-match-data
                     (reftex-index-make-replace-string
                      macro-fmt (match-string 0) ckey repeat mathp)))
             (while
                 (not
                  (catch 'loop
                    (message "REPLACE: %s?   (yn!qoe%s?)"
                             rpl
                             (if (> nkeys 1)
                                 (concat "1-" (int-to-string nkeys))
                               ""))
		   (setq char (if all-yes ?y
				(save-match-data (read-char-exclusive))))
                    (cond ((member char '(?y ?Y ?\ ))
                           ;; Yes!
                           (replace-match rpl t t)
                           (incf replace-count)
                           ;; See if we should insert newlines to  
shorten lines
                           (and reftex-index-phrases-wrap-long-lines
                                (reftex-index-phrases-fixup-line beg  
end))
                           (throw 'loop t))
                          ((member char '(?n ?N ?\C-h ?\C-?));; FIXME:  
DEL
                           ;; No
                           (throw 'loop t))
                          ((equal char ?!)
                           ;; Yes for all in this buffer
                           (setq all-yes t))
                          ((equal char ?q)
                           ;; Stop this one in this file
                           (goto-char (point-max))
                           (throw 'loop t))
                          ((equal char ?Q)
                           ;; Stop this one
                           (throw 'no-more-files t))
                          ((equal char ?s)
                           (save-buffer))
                          ((equal char ?S)
                           (reftex-save-all-document-buffers))
                          ((equal char ?\C-g)
                           (keyboard-quit))
                          ((member char '(?o ?O))
                           ;; Select a differnt macro
                           (let* ((nc (reftex-index-select-phrases- 
macro 2))
                                  (macro-data
                                   (cdr (assoc nc reftex-index-phrases- 
macro-data)))
                                  (macro-fmt (car macro-data))
                                  (repeat (nth 1 macro-data)))
                             (if macro-data
                                 (setq rpl (save-match-data
                                             (reftex-index-make- 
replace-string
                                              macro-fmt match
                                              ckey repeat mathp)))
                               (ding))))
                          ((equal char ?\?)
                           ;; Help
                           (with-output-to-temp-buffer "*Help*"
                             (princ reftex-index-phrases-help)))
                          ((equal char ?\C-r)
                           ;; Recursive edit
                           (save-match-data
                             (save-excursion
                               (message "%s"
                                (substitute-command-keys
                                 "Recursive edit.  Resume with \\[exit-recursive-edit] 
"))
                               (recursive-edit))))
                          ((equal char ?e)
                           (setq rpl (read-string "Edit: " rpl)))
                          ((equal char ?0)
                           (setq ckey (or index-key phrase)
                                 rpl (save-match-data
                                       (reftex-index-make-replace-string
                                        macro-fmt match ckey repeat  
mathp))))
                          ((and (> char ?0)
                                (<= char (+ ?0 nkeys)))
                           (setq ckey (nth (1- (- char ?0)) index-keys)
                                 rpl (save-match-data
                                       (reftex-index-make-replace-string
                                        macro-fmt match ckey repeat  
mathp))))
                          (t (ding)))
                    nil)))))
       (message "")
       (move-marker beg nil)
       (move-marker end nil)
       (setq all-yes nil)
       (reftex-unhighlight 0))))





On Jul 21, 2009, at 4:21 PM, Thomas S. Dye wrote:

> In the example, reftex is supposed to take the string "text" from  
> the *.rip file and replace all instances of the string in a  
> document's *.tex file(s) with some sort of indexing markup,  
> indicated by the possibilities listed at the top of the *.rip file  
> and indexed by the letter at the start of the line that contains  
> "text" in the *.rip file.  Reftex summarizes what it intends to do  
> when given the Ctrl-x, Ctrl-i command; in this example it says it  
> will replace one instance of "text" with "\index{text}text".  What  
> happens, only in Aquamacs and not in Carbon Emacs on the Mac or in  
> emacs running on Gnu/Linux, is that more than one "replacement" is  
> made, with the additional, spurious "replacements" made near the top  
> of the file.  In the instance I reported below, there is one  
> spurious replacement; this number is variable, however, and I have  
> had up to three or four spurious replacements in Aquamacs, one  
> following the other near the top of the file, as in the example below.
>
> If this is not some kind of configuration problem (I agree with you  
> that it probably is not), then the mechanism that reftex uses to  
> keep track of replacement targets either relies on emacs behavior  
> that Aquamacs changes, or the mechanism itself, perhaps a list of  
> file names and offsets, gets hosed somewhere between reporting what  
> it is going to do and actually doing it.  If this is what happens,  
> then my tests and Ralf Angeli's report indicate that it is Aquamacs  
> doing the hosing, rather than the underlying emacs.
>
> I'm afraid I can't suggest anything in the way of a fix.  I read a  
> couple of Paul Graham's Lisp books shortly after they were published  
> when I was programming in a dialect, now defunct, called Lisp-Stat,  
> but my efforts there were fairly crude, far short of the skill level  
> needed to contribute to efforts along the lines of emacs, reftex,  
> and Aquamacs, which are all terrific (and complex) pieces of software.
>
> All the best,
> Tom
>
> Thomas S. Dye, Ph.D.
> T. S. Dye & Colleagues, Archaeologists, Inc.
> Phone: (808) 529-0866 Fax: (808) 529-0884
> http://www.tsdye.com
>
>
> On Jul 20, 2009, at 8:05 PM, David Reitter wrote:
>
>> I don't use reftex much and can't tell from your message what the  
>> desired result would be, i.e. what the bug is.  All you are saying  
>> is "Note the "replacement" in the top line of the file.".
>>
>> I don't think there is much in the way of configuration for reftex  
>> that Aquamacs provides.  What kind of configuration do you suggest?
>>
>>
>> --
>> http://aquamacs.org -- Aquamacs: Emacs on Mac OS X
>> http://aquamacs.org/donate -- Could we help you? Return the favor  
>> and support the Aquamacs Project!
>>
>>
>> On Jul 21, 2009, at 3:31 AM, Thomas S. Dye wrote:
>>
>>> Aloha all,
>>>
>>> I installed Carbon Emacs and verified that the reftex behavior I  
>>> reported below does not occur there.
>>> It appears to be related to Aquamacs.
>>>
>>> All the best
>>>
>>> Tom
>>>
>>> Thomas S. Dye, Ph.D.
>>> T. S. Dye & Colleagues, Archaeologists, Inc.
>>> Phone: (808) 529-0866 Fax: (808) 529-0884
>>> http://www.tsdye.com
>>>
>>>
>>> Begin forwarded message:
>>>
>>>> From: "Thomas S. Dye" <tsd at tsdye.com>
>>>> Date: July 19, 2009 10:21:20 AM HST
>>>> To: Emacs on Mac OS X Mailing List <macosx-emacs at email.esm.psu.edu>
>>>> Subject: reftex configuration problem?
>>>>
>>>> Aloha all,
>>>>
>>>> reftex index phrases doesn't behave as I expect.
>>>>
>>>> \documentclass{article}
>>>>
>>>> \begin{document}
>>>> Some text.
>>>> \end{document}
>>>>
>>>> Ctrl-C \ on "text."  Mark entry as i.
>>>>
>>>> % -*- mode: reftex-index-phrases; TeX-master: "test_reftex.tex" -*-
>>>> %                              Key      Macro Format             
>>>> Repeat
>>>> %---------------------------------------------------------------------
>>>> INDEX_MACRO_DEFINITION:	i	\index{%s}          	t
>>>> INDEX_MACRO_DEFINITION:	g	\glossary{%s}       	t
>>>> %---------------------------------------------------------------------
>>>>
>>>>
>>>> i	text
>>>>
>>>> Ctrl-C Ctrl-i indicates one match in one file.
>>>> Ctrl-C Ctrl-a ! replaces two occurrences
>>>>
>>>> \documentc\index{text}text{article}
>>>>
>>>> \begin{document}
>>>> Some \index{text}text.
>>>> \end{document}
>>>>
>>>> Note the "replacement" in the top line of the file.
>>>>
>>>> I posted this message to gnu.emacs.help and Ralf Angeli responded:
>>>>
>>>> I cannot reproduce this issue with Emacs on GNU/Linux.  Does it  
>>>> work in
>>>> your case if you use Emacs (perhaps started with -Q) instead of
>>>> Aquamacs?
>>>>
>>>> I launched Aquamacs like this:
>>>>
>>>> "/Applications/Aquamacs Emacs.app/Contents/MacOS/Aquamacs Emacs" -q
>>>>
>>>> and got the same results.
>>>>
>>>> Perhaps reftex isn't configured properly in Aquamacs?
>>>>
>>>> All the best,
>>>> Tom
>>
>> _____________________________________________________________
>> MacOSX-Emacs mailing list
>> MacOSX-Emacs at email.esm.psu.edu
>> http://email.esm.psu.edu/mailman/listinfo/macosx-emacs
>> List Archives: http://dir.gmane.org/gmane.emacs.macintosh.osx
>
> _____________________________________________________________
> MacOSX-Emacs mailing list
> MacOSX-Emacs at email.esm.psu.edu
> http://email.esm.psu.edu/mailman/listinfo/macosx-emacs
> List Archives: http://dir.gmane.org/gmane.emacs.macintosh.osx

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2193 bytes
Desc: not available
URL: <http://email.esm.psu.edu/pipermail/macosx-emacs/attachments/20090721/bf5b6abd/attachment.p7s>


More information about the MacOSX-Emacs mailing list