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

Re: XEmacs - how to automate mark-search-cut



On 2007-05-26, Tyler Smith <tyler.smith@mail.mcgill.ca> wrote:
> On 2007-05-26, Russell L. Harris <rlharris@oplink.net> wrote:
>> I need to extract footnotes from a very long LaTeX document.  I would
>> like to start with a copy of the document, then delete from the copy
>> all text which is not a footnote.
>>
>
> The easy way:
>
> You can use occur to extract all your footnotes to a separate buffer:
>
> M-x occur
> \\footnote{[^}]*
>

Hi,

As you may have realised, if you've tried my easy solution, it is
easily fooled when your footnotes contain other expressions that
contain curly-braces. I've worked out a more robust solution that
is harder to fool. What it does is copy all your footnotes to a
separate buffer called *FOOTNOTES*. The original document is not
altered, and point remains where you left it - you won't see any
change at all until you switch buffers. You can invoke this function
with 'M-x extract-footnotes'. 

To install the function put the following code in your .emacs, or I
suppose that would be .xemacs for you. It will be loaded automatically
the next time you open xemacs, or you can load it immediately by
placing the cursor just after the last parenthesis and hitting C-x C-e
One note - I had to turn off transient-mark-mode to get this to
work. I don't know why. If you like to use transient mark mode you'll
have to turn it back on afterwards.

Here's the code, hope it helps!

Tyler

(defun extract-footnotes ()
  "Copy all footnotes to a separate *FOOTNOTES* buffer"
  (interactive)
  (let ((active-buffer (current-buffer)))
    (save-excursion
      (if (memq (get-buffer "*FOOTNOTES*") (buffer-list))
	  (kill-buffer "*FOOTNOTES*"))
      (transient-mark-mode -1)
      (goto-char (point-min))
      (while (search-forward "\\footnote" nil t)
	(goto-char (match-beginning 0))
	(push-mark)
	(search-forward "e" nil t)
	(forward-list)
	(append-to-buffer (get-buffer-create "*FOOTNOTES*") 
			  (mark) (point))
	(set-buffer "*FOOTNOTES*")
	(goto-char (point-max))
	(insert "\n")
	(set-buffer active-buffer)))))



Reply to: