Merge lp:~logan/ubuntu/raring/auctex/debian-merge into lp:ubuntu/raring/auctex

Proposed by Logan Rosen
Status: Merged
Merged at revision: 15
Proposed branch: lp:~logan/ubuntu/raring/auctex/debian-merge
Merge into: lp:ubuntu/raring/auctex
Diff against target: 20037 lines (+3440/-14776)
122 files modified
.pc/0001-Rationalize-HTML-documentation-targets-in-doc-Makefi.patch/doc/Makefile.in (+0/-199)
.pc/0002-Change-pdf-viewer-default-from-Evince-to-xpdf.patch/tex.el (+0/-5598)
.pc/0003-Fix-TeX-engine-alist-builtin-defvar.patch/tex.el (+0/-5598)
.pc/applied-patches (+8/-3)
.pc/use-firefox.patch/tex.el (+3/-3)
.pc/use-xdg-open.patch/tex.el (+3/-3)
context.el (+1/-1)
debian/+NOTE (+0/-6)
debian/+checks (+0/-1)
debian/=TODO (+0/-102)
debian/=TODO.org (+77/-0)
debian/COPYRIGHT (+18/-18)
debian/auctex.NEWS (+80/-0)
debian/auctex.README.Debian.eperl (+118/-0)
debian/auctex.bug-presubj.eperl (+29/-0)
debian/auctex.bug-script.eperl (+90/-0)
debian/auctex.config.eperl (+32/-0)
debian/auctex.dirs (+1/-0)
debian/auctex.doc-base.eperl (+55/-0)
debian/auctex.doc-base.preview-latex.eperl (+28/-0)
debian/auctex.docs (+7/-0)
debian/auctex.emacsen-install.eperl (+127/-0)
debian/auctex.emacsen-remove.eperl (+66/-0)
debian/auctex.emacsen-startup.eperl (+41/-0)
debian/auctex.info (+2/-0)
debian/auctex.install (+2/-0)
debian/auctex.links.eperl (+3/-0)
debian/auctex.lintian-overrides.eperl (+15/-0)
debian/auctex.manpages (+1/-0)
debian/auctex.postinst.eperl (+144/-0)
debian/auctex.postrm.eperl (+36/-0)
debian/auctex.preinst.eperl (+38/-0)
debian/auctex.templates (+21/-0)
debian/auctex.templates.eperl (+47/-0)
debian/auctex.triggers (+4/-0)
debian/auctex/NEWS (+0/-66)
debian/auctex/README.in (+0/-88)
debian/auctex/bug.presubj.in (+0/-27)
debian/auctex/bug.script.in (+0/-88)
debian/auctex/conffiles.in (+0/-10)
debian/auctex/config.in (+0/-51)
debian/auctex/cron.in (+0/-20)
debian/auctex/docbase.auctex.in (+0/-55)
debian/auctex/docbase.preview.in (+0/-28)
debian/auctex/install.in (+0/-132)
debian/auctex/lintian.in (+0/-20)
debian/auctex/lisp-startup.el.in (+0/-35)
debian/auctex/postinst.in (+0/-52)
debian/auctex/postrm.in (+0/-31)
debian/auctex/prerm.in (+0/-31)
debian/auctex/remove.in (+0/-61)
debian/auctex/templates (+0/-36)
debian/auctex/templates.in (+0/-56)
debian/auctex/update-auctex-elisp.8.in (+0/-68)
debian/auctex/update-auctex-elisp.in (+0/-32)
debian/auctex/update-auctex-install.8.in (+0/-69)
debian/auctex/update-auctex-install.in (+0/-29)
debian/changelog (+158/-0)
debian/compat (+1/-0)
debian/control (+8/-8)
debian/copyright (+51/-0)
debian/copyright.eperl (+42/-0)
debian/copyright.in (+0/-58)
debian/elcc.eperl (+54/-0)
debian/patches/0001-Rationalize-HTML-documentation-targets-in-doc-Makefi.patch (+0/-79)
debian/patches/0001-doc-Makefile.in-Rationalize-HTML-documentation-targe.patch (+79/-0)
debian/patches/0002-Change-pdf-viewer-default-from-Evince-to-xpdf.patch (+0/-25)
debian/patches/0002-doc-Makefile.in-Rationalize-dist-target.patch (+23/-0)
debian/patches/0003-Fix-TeX-engine-alist-builtin-defvar.patch (+0/-28)
debian/patches/0003-preview-latex-Makefile.in-Also-clean-PDF-docs.patch (+25/-0)
debian/patches/0004-Fix-ConTeXt-expand-options-defun.patch (+28/-0)
debian/patches/0005-Fix-preview-with-latest-ghostscript.patch (+54/-0)
debian/patches/0006-TeX-view-program-selection-Customize-for-Debian.patch (+33/-0)
debian/patches/0007-TeX-auto-global-Customize-for-Debian.patch (+23/-0)
debian/patches/0008-preview-image-type-Customize-for-Debian.patch (+27/-0)
debian/patches/series (+8/-3)
debian/po/POTFILES.in (+1/-1)
debian/po/cs.po (+42/-61)
debian/po/da.po (+112/-0)
debian/po/de.po (+48/-69)
debian/po/es.po (+72/-71)
debian/po/eu.po (+45/-61)
debian/po/fi.po (+44/-60)
debian/po/fr.po (+48/-70)
debian/po/gl.po (+44/-60)
debian/po/it.po (+44/-68)
debian/po/ja.po (+47/-53)
debian/po/ko.po (+129/-0)
debian/po/nl.po (+54/-127)
debian/po/pl.po (+95/-0)
debian/po/pt.po (+48/-69)
debian/po/pt_BR.po (+35/-57)
debian/po/ru.po (+47/-69)
debian/po/sk.po (+87/-0)
debian/po/sv.po (+49/-67)
debian/po/templates.pot (+13/-49)
debian/po/vi.po (+47/-53)
debian/preview-latex-style.README.Debian.eperl (+16/-0)
debian/preview-latex-style.bug-presubj.eperl (+29/-0)
debian/preview-latex-style.doc-base.eperl (+29/-0)
debian/preview-latex-style.docs (+2/-0)
debian/preview-latex-style.install (+1/-0)
debian/preview-latex-style.links (+1/-0)
debian/preview-latex-style/README.in (+0/-16)
debian/preview-latex-style/bug.presubj.in (+0/-28)
debian/preview-latex-style/docbase.in (+0/-29)
debian/preview-latex-style/lintian.in (+0/-10)
debian/preview-latex-style/postinst.in (+0/-29)
debian/preview-latex-style/postrm.in (+0/-29)
debian/preview-latex-style/prerm.in (+0/-26)
debian/rules (+98/-274)
debian/rules.eperl (+159/-0)
debian/rules.in (+0/-358)
debian/update-auctex-elisp.8.eperl (+78/-0)
debian/update-auctex-elisp.eperl (+139/-0)
debian/variables (+0/-77)
debian/watch (+2/-0)
doc/Makefile.in (+3/-3)
preview/latex/Makefile.in (+1/-1)
preview/preview.el (+15/-8)
tex-site.el.in (+1/-1)
tex.el (+4/-4)
To merge this branch: bzr merge lp:~logan/ubuntu/raring/auctex/debian-merge
Reviewer Review Type Date Requested Status
Daniel Holbach (community) Approve
Ubuntu branches Pending
Review via email: mp+135813@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Holbach (dholbach) wrote :

Good work.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== removed directory '.pc/0001-Rationalize-HTML-documentation-targets-in-doc-Makefi.patch'
2=== removed directory '.pc/0001-Rationalize-HTML-documentation-targets-in-doc-Makefi.patch/doc'
3=== removed file '.pc/0001-Rationalize-HTML-documentation-targets-in-doc-Makefi.patch/doc/Makefile.in'
4--- .pc/0001-Rationalize-HTML-documentation-targets-in-doc-Makefi.patch/doc/Makefile.in 2010-08-27 17:06:08 +0000
5+++ .pc/0001-Rationalize-HTML-documentation-targets-in-doc-Makefi.patch/doc/Makefile.in 1970-01-01 00:00:00 +0000
6@@ -1,199 +0,0 @@
7-# Makefile for AUCTeX
8-
9-# Maintainer: auctex-devel@gnu.org
10-
11-# Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.
12-
13-# This file is part of AUCTeX.
14-
15-# AUCTeX is free software; you can redistribute it and/or modify it
16-# under the terms of the GNU General Public License as published by
17-# the Free Software Foundation; either version 3, or (at your option)
18-# any later version.
19-
20-# AUCTeX is distributed in the hope that it will be useful, but
21-# WITHOUT ANY WARRANTY; without even the implied warranty of
22-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23-# General Public License for more details.
24-
25-# You should have received a copy of the GNU General Public License
26-# along with AUCTeX; see the file COPYING. If not, write to the Free
27-# Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28-# MA 02110-1301, USA.
29-
30-prefix=@prefix@$(null)
31-datarootdir=@datarootdir@$(null)
32-datadir=@datadir@$(null)
33-packagedir=@packagedir@$(null)
34-infodir=@infodir@$(null)
35-docdir=@docdir@$(null)
36-TEX=@TEX@
37-PDFTEX=@PDFTEX@
38-MAKEINFO=@MAKEINFO@
39-MAKEINFO_PLAIN=-D rawfile --no-headers
40-INSTALL_INFO=@INSTALL_INFO@
41-INSTALL=@INSTALL@
42-INSTALL_DATA=@INSTALL_DATA@
43-DESTDIR=
44-TEXI2HTML=@TEXI2HTML@
45-TEXI2DVI=@TEXI2DVI@
46-TEXI2PDF=@TEXI2PDF@
47-MKINSTALLDIRS = ../mkinstalldirs
48-DVIPS=@DVIPS@
49-PERL=@PERL@
50-AUCTEXDATE=@AUCTEXDATE@
51-AUCTEXVERSION=@AUCTEXVERSION@
52-PACKAGE_TARNAME=@PACKAGE_TARNAME@
53-
54-AUCTEXTEXIFILES = auctex.texi install.texi wininstall.texi intro.texi \
55- changes.texi todo.texi faq.texi macros.texi quickstart.texi \
56- fdl.texi version.texi
57-PREVIEWTEXIFILES = copying.texi preview-faq.texi macros.texi \
58- preview-dtxdoc.texi preview-latex.texi preview-problems.texi \
59- preview-readme.texi preview-todo.texi version.texi
60-DISTTEXTS = ../README ../INSTALL ../TODO ../INSTALL.windows ../FAQ ../CHANGES
61-
62-all: dist
63-
64-info: auctex.info preview-latex.info
65-
66-dvi: auctex.dvi tex-ref.dvi preview-latex.dvi
67-
68-install: install-auctex install-preview
69-
70-install-man:
71- test x$(packagedir) != xno && \
72- { $(MKINSTALLDIRS) $(DESTDIR)$(packagedir)/man/auctex ; \
73- for i in $(AUCTEXTEXIFILES) $(PREVIEWTEXIFILES) tex-ref.tex ; \
74- do echo $(INSTALL_DATA) $$i $(DESTDIR)$(packagedir)/man/auctex; \
75- $(INSTALL_DATA) $$i $(DESTDIR)$(packagedir)/man/auctex; \
76- done ; \
77- }
78-
79-dist: $(DISTTEXTS) preview-latex.info auctex.info tex-ref.pdf
80-
81-extradist: html/auctex_toc.html auctex.ps auctex.pdf tex-ref.ps tex-ref.pdf
82-
83-.PHONY: all info dvi dist install-auctex disttexts clean distclean \
84- maintainer-clean install-preview install-man html-docs extradist
85-
86-# AUCTeX
87-
88-html/auctex_toc.html: auctex.texi
89- rm -rf html
90- mkdir html
91- cd html && $(TEXI2HTML) -split_node -I .. ../auctex.texi && \
92- test ! -d auctex || { mv auctex/* . && rm -rf auctex ; }
93-
94-tex-ref.dvi: tex-ref.tex
95- $(TEX) tex-ref
96-
97-tex-ref.ps: tex-ref.dvi
98- $(DVIPS) tex-ref.dvi -Ppdf -o tex-ref.ps
99-
100-tex-ref.pdf: tex-ref.tex
101- $(PDFTEX) tex-ref.tex
102-
103-version.texi: ../ChangeLog
104- echo @set VERSION $(AUCTEXVERSION) >version.texi
105- echo @set UPDATED $(AUCTEXDATE) >>version.texi
106-
107-auctex.dvi: $(AUCTEXTEXIFILES)
108- $(TEXI2DVI) auctex.texi
109-
110-auctex.pdf: $(AUCTEXTEXIFILES)
111- $(TEXI2PDF) auctex.texi
112-
113-auctex.ps: auctex.dvi
114- $(DVIPS) auctex.dvi -Ppdf -o auctex.ps
115-
116-auctex.info: $(AUCTEXTEXIFILES)
117- $(MAKEINFO) auctex.texi
118-
119-install-auctex: auctex.info tex-ref.pdf
120- -$(MKINSTALLDIRS) $(DESTDIR)$(infodir)
121- rm -f $(DESTDIR)$(infodir)/auctex $(DESTDIR)$(infodir)/auctex-*
122- $(INSTALL_DATA) auctex.info $(DESTDIR)$(infodir)
123- for x in auctex.info-*; do \
124- if [ -r $$x ]; then \
125- $(INSTALL_DATA) $$x $(DESTDIR)$(infodir) ; \
126- fi; \
127- done
128- -$(INSTALL_INFO) --info-dir=$(DESTDIR)$(infodir) auctex.info
129- test X$(packagedir) != Xno || { \
130- $(MKINSTALLDIRS) $(DESTDIR)$(docdir); \
131- rm -f $(DESTDIR)$(docdir)/tex-ref.pdf; \
132- $(INSTALL_DATA) tex-ref.pdf $(DESTDIR)$(docdir); \
133- }
134-
135-# preview
136-
137-preview-latex/index.html: $(PREVIEWTEXIFILES)
138- rm -f preview-latex/*
139- $(TEXI2HTML) preview-latex.texi
140-
141-html-docs: preview-latex/index.html
142-
143-preview-dtxdoc.texi: ../preview/latex/preview.dtx preview-dtxdoc.pl
144- -$(PERL) preview-dtxdoc.pl ../preview/latex/preview.dtx \
145- preview-dtxdoc.texi
146-
147-preview-latex.dvi: $(PREVIEWTEXIFILES)
148- $(TEXI2DVI) preview-latex.texi
149-
150-preview-latex.ps: preview-latex.dvi
151- $(DVIPS) preview-latex.dvi -Ppdf -o preview-latex.ps
152-
153-preview-latex.pdf: $(PREVIEWTEXIFILES)
154- $(TEXI2PDF) preview-latex.texi
155-
156-preview-latex.info: $(PREVIEWTEXIFILES)
157- $(MAKEINFO) preview-latex.texi
158-
159-install-preview: preview-latex.info
160- -$(MKINSTALLDIRS) $(DESTDIR)$(infodir)
161- for x in preview-latex.info* ; do \
162- $(INSTALL_DATA) $$x $(DESTDIR)$(infodir) ; \
163- done
164- -$(INSTALL_INFO) --info-dir=$(DESTDIR)$(infodir) preview-latex.info
165-
166-# disttexts
167-
168-../INSTALL: install.texi macros.texi
169- $(MAKEINFO) $(MAKEINFO_PLAIN) install.texi --output $@
170-
171-../INSTALL.windows: wininstall.texi macros.texi
172- $(MAKEINFO) $(MAKEINFO_PLAIN) wininstall.texi --output $@
173-
174-../README: intro.texi preview-readme.texi macros.texi
175- $(MAKEINFO) $(MAKEINFO_PLAIN) intro.texi --output $@
176- $(MAKEINFO) $(MAKEINFO_PLAIN) preview-readme.texi --output - >> $@
177-
178-../CHANGES: changes.texi macros.texi
179- $(MAKEINFO) $(MAKEINFO_PLAIN) changes.texi --output $@
180-
181-../TODO: todo.texi preview-todo.texi macros.texi
182- $(MAKEINFO) $(MAKEINFO_PLAIN) todo.texi --output $@
183- $(MAKEINFO) $(MAKEINFO_PLAIN) preview-todo.texi --output - >> $@
184-
185-../FAQ: faq.texi preview-faq.texi macros.texi
186- $(MAKEINFO) $(MAKEINFO_PLAIN) faq.texi --output $@
187- $(MAKEINFO) $(MAKEINFO_PLAIN) --number-sections preview-faq.texi --output - >> $@
188-
189-../PROBLEMS: preview-problems.texi macros.texi
190- $(MAKEINFO) $(MAKEINFO_PLAIN) --number-sections preview-problems.texi --output $@
191-
192-# clean
193-
194-clean:
195- rm -f *.dvi *.ps *.pdf *.aux *.cp *.fn *.ky *.log *~ \#*\# \
196- *.tp *.vr *.pg *.toc *.tp *.bak *.cps *.kys *.tps \
197- *.fns *.vrs *.pgs *.tmp *.html
198- rm -rf html preview-latex
199-
200-distclean: clean
201- rm -f Makefile
202-
203-maintainer-clean: distclean
204- rm -f INSTALL.windows README CHANGES HISTORY TODO FAQ \
205- preview-dtxdoc.texi version.texi $(DISTTEXTS) *.info *.info-*
206
207=== removed directory '.pc/0002-Change-pdf-viewer-default-from-Evince-to-xpdf.patch'
208=== removed file '.pc/0002-Change-pdf-viewer-default-from-Evince-to-xpdf.patch/tex.el'
209--- .pc/0002-Change-pdf-viewer-default-from-Evince-to-xpdf.patch/tex.el 2010-08-27 17:06:08 +0000
210+++ .pc/0002-Change-pdf-viewer-default-from-Evince-to-xpdf.patch/tex.el 1970-01-01 00:00:00 +0000
211@@ -1,5598 +0,0 @@
212-;;; tex.el --- Support for TeX documents.
213-
214-;; Copyright (C) 1985, 1986, 1987, 1991, 1993, 1994, 1996, 1997, 1999,
215-;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
216-;; Free Software Foundation, Inc.
217-
218-;; Maintainer: auctex-devel@gnu.org
219-;; Keywords: tex
220-
221-;; This file is part of AUCTeX.
222-
223-;; AUCTeX is free software; you can redistribute it and/or modify it
224-;; under the terms of the GNU General Public License as published by
225-;; the Free Software Foundation; either version 3, or (at your option)
226-;; any later version.
227-
228-;; AUCTeX is distributed in the hope that it will be useful, but
229-;; WITHOUT ANY WARRANTY; without even the implied warranty of
230-;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
231-;; General Public License for more details.
232-
233-;; You should have received a copy of the GNU General Public License
234-;; along with AUCTeX; see the file COPYING. If not, write to the Free
235-;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
236-;; 02110-1301, USA.
237-
238-;;; Commentary:
239-
240-;; This file provides AUCTeX support for plain TeX as well as basic
241-;; functions used by other AUCTeX modes (e.g. for LaTeX, Texinfo and
242-;; ConTeXt).
243-
244-;;; Code:
245-
246-(when (< emacs-major-version 21)
247- (error "AUCTeX requires Emacs 21 or later"))
248-
249-(require 'custom)
250-(require 'tex-site)
251-(eval-when-compile
252- (require 'cl))
253-
254-(defgroup TeX-file nil
255- "Files used by AUCTeX."
256- :group 'AUCTeX)
257-
258-(defgroup TeX-command nil
259- "Calling external commands from AUCTeX."
260- :group 'AUCTeX)
261-
262-(defgroup LaTeX nil
263- "LaTeX support in AUCTeX."
264- :tag "LaTeX"
265- :group 'AUCTeX
266- :prefix "LaTeX-")
267-
268-(defgroup TeX-misc nil
269- "Various AUCTeX settings."
270- :group 'AUCTeX)
271-
272-;;; Site Customization
273-;;
274-;; The following variables are likely to need to be changed for your
275-;; site. You should do this with customize. Here is the beef: If you
276-;; want to print, TeX-print-command must be non-nil (if it is nil,
277-;; you'll get a complaint when using the print menu). If you want to
278-;; view the queue, TeX-queue-command needs to be non-nil (if it is
279-;; nil, it won't get mentioned in the menu). If TeX-printer-list is
280-;; nil, nothing else gets asked: the menu entries lead directly to the
281-;; respective commands. If those commands contain %p, the value of
282-;; TeX-printer-default gets inserted there, no questions asked. Now
283-;; if TeX-printer-list is non-nil, you'll always get asked which
284-;; printer you want to use. You can enter a configured printer from
285-;; TeX-printer-list, or an unknown one. The respective menus will
286-;; show all configured printers. Since you can enter unknown
287-;; printers, the printer name _must_ be set with %p in
288-;; TeX-print-command.
289-
290-;; How to print.
291-
292-(defcustom TeX-print-command "%(o?)dvips -P%p %r %s"
293- "*Command used to print a file.
294-
295-First `%p' is expanded to the printer name, then ordinary expansion is
296-performed as specified in `TeX-expand-list'. If it is nil,
297-then customization is requested."
298- :group 'TeX-command
299- :type '(choice (string :tag "Print command")
300- (const :tag "No print command customized" nil)))
301-
302-(defcustom TeX-command "tex"
303- "Command to run plain TeX."
304- :group 'TeX-command
305- :type 'string)
306-
307-(defcustom TeX-Omega-command "omega"
308- "Command to run plain TeX on Omega."
309- :group 'TeX-command
310- :type 'string)
311-
312-(defcustom LaTeX-command "latex"
313- "Command to run LaTeX."
314- :group 'TeX-command
315- :type 'string)
316-
317-(defcustom LaTeX-Omega-command "lambda"
318- "Command to run LaTeX on Omega."
319- :group 'TeX-command
320- :type 'string)
321-
322-(defcustom ConTeXt-engine nil
323- "Engine to use for --engine in the texexec command.
324-If nil, none is specified."
325- :group 'TeX-command
326- :type '(choice (const :tag "Unspecified" nil)
327- string))
328-
329-(defcustom ConTeXt-Omega-engine TeX-Omega-command
330- "Engine to use for --engine in the texexec command in Omega mode.
331-If nil, none is specified."
332- :group 'TeX-command
333- :type '(choice (const :tag "Unspecified" nil)
334- string))
335-;; At least in TeXLive 2009 ConTeXt does not support an omega option anymore.
336-(make-obsolete-variable 'ConTeXt-Omega-engine 'TeX-engine-alist)
337-
338-(defcustom TeX-queue-command "lpq -P%p"
339- "*Command used to show the status of a printer queue.
340-
341-First `%p' is expanded to the printer name, then ordinary expansion is
342-performed as specified in `TeX-expand-list'. If this is nil,
343-the printer has no corresponding command."
344- :group 'TeX-command
345- :type '(choice (string :tag "Queue check command")
346- (const :tag "No such command" nil)))
347-
348-(defcustom TeX-mode-hook nil
349- "A hook run in TeX mode buffers."
350- :type 'hook
351- :group 'TeX-misc)
352-
353-(defcustom AmS-TeX-mode-hook nil
354- "A hook run in AmS-TeX mode buffers."
355- :type 'hook
356- :group 'TeX-misc)
357-
358-;; This is the major configuration variable. Most sites will only
359-;; need to change the second string in each entry, which is the name
360-;; of a command to send to the shell. If you use other formatters
361-;; like AMSLaTeX or AMSTeX, you can add those to the list. See
362-;; TeX-expand-list for a description of the % escapes
363-
364-(defcustom TeX-command-list
365- `(("TeX" "%(PDF)%(tex) %`%S%(PDFout)%(mode)%' %t"
366- TeX-run-TeX nil
367- (plain-tex-mode ams-tex-mode texinfo-mode) :help "Run plain TeX")
368- ("LaTeX" "%`%l%(mode)%' %t"
369- TeX-run-TeX nil
370- (latex-mode doctex-mode) :help "Run LaTeX")
371- ;; Not part of standard TeX.
372- ("Makeinfo" "makeinfo %t" TeX-run-compile nil
373- (texinfo-mode) :help "Run Makeinfo with Info output")
374- ("Makeinfo HTML" "makeinfo --html %t" TeX-run-compile nil
375- (texinfo-mode) :help "Run Makeinfo with HTML output")
376- ("AmSTeX" "%(PDF)amstex %`%S%(PDFout)%(mode)%' %t"
377- TeX-run-TeX nil (ams-tex-mode) :help "Run AMSTeX")
378- ;; support for ConTeXt --pg
379- ;; first version of ConTeXt to support nonstopmode: 2003.2.10
380- ("ConTeXt" "texexec --once --texutil %(execopts)%t"
381- TeX-run-TeX nil (context-mode) :help "Run ConTeXt once")
382- ("ConTeXt Full" "texexec %(execopts)%t"
383- TeX-run-TeX nil
384- (context-mode) :help "Run ConTeXt until completion")
385- ("BibTeX" "bibtex %s" TeX-run-BibTeX nil t :help "Run BibTeX")
386- ,(if (or window-system (getenv "DISPLAY"))
387- '("View" "%V" TeX-run-discard-or-function t t :help "Run Viewer")
388- '("View" "dvi2tty -q -w 132 %s" TeX-run-command t t
389- :help "Run Text viewer"))
390- ("Print" "%p" TeX-run-command t t :help "Print the file")
391- ("Queue" "%q" TeX-run-background nil t :help "View the printer queue"
392- :visible TeX-queue-command)
393- ("File" "%(o?)dvips %d -o %f " TeX-run-command t t
394- :help "Generate PostScript file")
395- ("Index" "makeindex %s" TeX-run-command nil t :help "Create index file")
396- ("Check" "lacheck %s" TeX-run-compile nil (latex-mode)
397- :help "Check LaTeX file for correctness")
398- ("Spell" "(TeX-ispell-document \"\")" TeX-run-function nil t
399- :help "Spell-check the document")
400- ("Clean" "TeX-clean" TeX-run-function nil t
401- :help "Delete generated intermediate files")
402- ("Clean All" "(TeX-clean t)" TeX-run-function nil t
403- :help "Delete generated intermediate and output files")
404- ("Other" "" TeX-run-command t t :help "Run an arbitrary command"))
405- "List of commands to execute on the current document.
406-
407-Each element is a list, whose first element is the name of the command
408-as it will be presented to the user.
409-
410-The second element is the string handed to the shell after being
411-expanded. The expansion is done using the information found in
412-`TeX-expand-list'.
413-
414-The third element is the function which actually start the process.
415-Several such hooks has been defined:
416-
417-TeX-run-command: Start up the process and show the output in a
418-separate buffer. Check that there is not two commands running for the
419-same file. Return the process object.
420-
421-TeX-run-format: As `TeX-run-command', but assume the output is created
422-by a TeX macro package. Return the process object.
423-
424-TeX-run-TeX: For TeX output.
425-
426-TeX-run-interactive: Run TeX or LaTeX interactively.
427-
428-TeX-run-BibTeX: For BibTeX output.
429-
430-TeX-run-compile: Use `compile' to run the process.
431-
432-TeX-run-shell: Use `shell-command' to run the process.
433-
434-TeX-run-discard: Start the process in the background, discarding its
435-output.
436-
437-TeX-run-background: Start the process in the background, show output
438-in other window.
439-
440-TeX-run-silent: Start the process in the background.
441-
442-TeX-run-discard-foreground: Start the process in the foreground,
443-discarding its output.
444-
445-TeX-run-function: Execute the Lisp function or function call
446-specified by the string in the second element. Consequently,
447-this hook does not start a process.
448-
449-TeX-run-discard-or-function: If the command is a Lisp function,
450-execute it as such, otherwise start the command as a process,
451-discarding its output.
452-
453-To create your own hook, define a function taking three arguments: The
454-name of the command, the command string, and the name of the file to
455-process. It might be useful to use `TeX-run-command' in order to
456-create an asynchronous process.
457-
458-If the fourth element is non-nil, the user will get a chance to
459-modify the expanded string.
460-
461-The fifth element indicates in which mode(s) the command should be
462-present in the Command menu. Use t if it should be active in any
463-mode. If it should only be present in some modes, specify a list with
464-the respective mode names.
465-
466-Any additional elements get just transferred to the respective menu entries."
467- :group 'TeX-command
468- :type '(repeat (group :value ("" "" TeX-run-command nil t)
469- (string :tag "Name")
470- (string :tag "Command")
471- (choice :tag "How"
472- :value TeX-run-command
473- (function-item TeX-run-command)
474- (function-item TeX-run-format)
475- (function-item TeX-run-TeX)
476- (function-item TeX-run-interactive)
477- (function-item TeX-run-BibTeX)
478- (function-item TeX-run-compile)
479- (function-item TeX-run-shell)
480- (function-item TeX-run-discard)
481- (function-item TeX-run-background)
482- (function-item TeX-run-silent)
483- (function-item TeX-run-discard-foreground)
484- (function-item TeX-run-function)
485- (function-item TeX-run-discard-or-function)
486- (function :tag "Other"))
487- (boolean :tag "Prompt")
488- (choice :tag "Modes"
489- (const :tag "All" t)
490- (set (const :tag "Plain TeX" plain-tex-mode)
491- (const :tag "LaTeX" latex-mode)
492- (const :tag "DocTeX" doctex-mode)
493- (const :tag "ConTeXt" context-mode)
494- (const :tag "Texinfo" texinfo-mode)
495- (const :tag "AmSTeX" ams-tex-mode)))
496- (repeat :tag "Menu elements" :inline t sexp))))
497-
498-(defcustom TeX-command-output-list
499- '(
500-; Add the following line if you want to use htlatex (tex4ht)
501-; ("\\`htlatex" ("html"))
502- )
503- "List of regexps and file extensions.
504-
505-Each element is a list, whose first element is a regular expression to
506-match against the name of the command that will be used to process the TeX
507-file.
508-
509-The second element is either a string or a list with a string as element.
510-If it is a string this is the default file extension that will be expected
511-for output files that are produced by commands that match the first
512-element. The real file extension will be obtained from the logging output
513-if possible, defaulting to the given string.
514-If it is a list, the element of the list will be the fixed extension used
515-without looking at the logging output.
516-
517-If this list does not yield an extension, the default is either \"dvi\"
518-or \"pdf\", depending on the setting of `TeX-PDF-mode'.
519-Extensions must be given without the \".\"."
520-
521- :group 'TeX-command
522- :type '(repeat (group (regexp :tag "Command Regexp")
523- (choice (string :tag "Default Extension")
524- (group (string :tag "Fixed Extension"))))))
525-
526-;; You may want to change the default LaTeX version for your site.
527-(defcustom LaTeX-version "2e"
528- "Default LaTeX version. Currently recognized is \"2\" and \"2e\"."
529- :group 'LaTeX
530- :type '(radio (const :format "%v\n%h"
531- :doc "\
532-The executable `latex' is LaTeX version 2."
533- "2")
534- (const :format "%v\n%h"
535- :doc "\
536-The executable `latex' is LaTeX version 2e."
537- "2e")
538- (string :tag "Other")))
539-
540-
541-;; Use different compilation commands depending on style.
542-;; Only works if parsing is enabled.
543-
544-(defcustom LaTeX-command-style
545- ;; They have all been combined in LaTeX 2e.
546- '(("" "%(PDF)%(latex) %S%(PDFout)"))
547-"List of style options and LaTeX commands.
548-
549-If the first element (a regular expression) matches the name of one of
550-the style files, any occurrence of the string `%l' in a command in
551-`TeX-command-list' will be replaced with the second element. The first
552-match is used, if no match is found the `%l' is replaced with the empty
553-string."
554- :group 'TeX-command
555- :type '(repeat (group :value ("" "")
556- regexp (string :tag "Style"))))
557-
558-;; Enter the names of the printers available at your site, or nil if
559-;; you only have one printer.
560-
561-(defcustom TeX-printer-list
562- '(("Default" "%(o?)dvips -f %s | lpr" "lpq"))
563- "List of available printers.
564-
565-The first element of each entry is the printer name.
566-
567-The second element is the command used to print to this
568-printer. It defaults to the value of `TeX-print-command' when nil.
569-
570-The third element is the command used to examine the print queue for
571-this printer. It defaults to the value of `TeX-queue-command' similarly.
572-
573-Any occurrence of `%p' in the second or third element is expanded to
574-the printer name given in the first element, then ordinary expansion
575-is performed as specified in `TeX-expand-list'.
576-
577-If this list is empty, only `TeX-print-command' and `TeX-queue-command'
578-get consulted."
579- :group 'TeX-command
580- :type '(repeat (group (string :tag "Name")
581- (option (group :inline t
582- :extra-offset -4
583- (choice :tag "Print"
584- (const :tag "default")
585- (string :format "%v"))
586- (option (choice :tag "Queue"
587- (const :tag "default")
588- (string
589- :format "%v"))))))))
590-
591-;; The name of the most used printer.
592-
593-(defcustom TeX-printer-default (or (getenv "PRINTER")
594- (and TeX-printer-list
595- (car (car TeX-printer-list)))
596- "lp")
597- "*Default printer to use with `TeX-command'."
598- :group 'TeX-command
599- :type 'string)
600-
601-(defcustom TeX-print-style '(("^landscape$" "-t landscape"))
602- "List of style options and print options.
603-
604-If the first element (a regular expression) matches the name of one of
605-the style files, any occurrence of the string `%r' in a command in
606-`TeX-command-list' will be replaced with the second element. The first
607-match is used, if no match is found the `%r' is replaced with the empty
608-string."
609- :group 'TeX-command
610- :type '(repeat (group regexp (string :tag "Command"))))
611-
612-;; This is the list of expansion for the commands in
613-;; TeX-command-list. Not likely to be changed, but you may e.g. want
614-;; to handle .ps files.
615-
616-(defcustom TeX-expand-list
617- '(("%p" TeX-printer-query) ;%p must be the first entry
618- ("%q" (lambda ()
619- (TeX-printer-query t)))
620- ("%V" (lambda ()
621- (TeX-source-correlate-start-server-maybe)
622- (TeX-view-command-raw)))
623- ("%vv" (lambda ()
624- (TeX-source-correlate-start-server-maybe)
625- (TeX-output-style-check TeX-output-view-style)))
626- ("%v" (lambda ()
627- (TeX-source-correlate-start-server-maybe)
628- (TeX-style-check TeX-view-style)))
629- ("%r" (lambda ()
630- (TeX-style-check TeX-print-style)))
631- ("%l" (lambda ()
632- (TeX-style-check LaTeX-command-style)))
633- ("%(PDF)" (lambda ()
634- (if (and (eq TeX-engine 'default)
635- (or TeX-PDF-mode
636- TeX-DVI-via-PDFTeX))
637- "pdf"
638- "")))
639- ("%(PDFout)" (lambda ()
640- (cond ((and (eq TeX-engine 'xetex)
641- (not TeX-PDF-mode))
642- " -no-pdf")
643- ((and (eq TeX-engine 'luatex)
644- (not TeX-PDF-mode))
645- " --output-format=dvi")
646- ((and (eq TeX-engine 'default)
647- (not TeX-PDF-mode)
648- TeX-DVI-via-PDFTeX)
649- " \"\\pdfoutput=0 \"")
650- (t ""))))
651- ("%(mode)" (lambda ()
652- (if TeX-interactive-mode
653- ""
654- " -interaction=nonstopmode")))
655- ("%(o?)" (lambda () (if (eq TeX-engine 'omega) "o" "")))
656- ("%(tex)" (lambda () (eval (nth 2 (assq TeX-engine (TeX-engine-alist))))))
657- ("%(latex)" (lambda () (eval (nth 3 (assq TeX-engine (TeX-engine-alist))))))
658- ("%(execopts)" ConTeXt-expand-options)
659- ("%S" TeX-source-correlate-expand-options)
660- ("%dS" TeX-source-specials-view-expand-options)
661- ("%cS" TeX-source-specials-view-expand-client)
662- ("%(outpage)" (lambda ()
663- (if TeX-source-correlate-output-page-function
664- (funcall TeX-source-correlate-output-page-function)
665- "1")))
666- ;; `file' means to call `TeX-master-file' or `TeX-region-file'
667- ("%s" file nil t)
668- ("%t" file t t)
669- ("%`" (lambda nil
670- (setq TeX-command-pos t TeX-command-text "")))
671- (" \"\\" (lambda nil
672- (if (eq TeX-command-pos t)
673- (setq TeX-command-pos pos
674- pos (+ 3 pos))
675- (setq pos (1+ pos)))))
676- ("\"" (lambda nil (if (numberp TeX-command-pos)
677- (setq TeX-command-text
678- (concat
679- TeX-command-text
680- (substring command
681- TeX-command-pos
682- (1+ pos)))
683- command
684- (concat
685- (substring command
686- 0
687- TeX-command-pos)
688- (substring command
689- (1+ pos)))
690- pos TeX-command-pos
691- TeX-command-pos t)
692- (setq pos (1+ pos)))))
693- ("%'" (lambda nil
694- (prog1
695- (if (stringp TeX-command-text)
696- (progn
697- (setq pos (+ (length TeX-command-text) 9)
698- TeX-command-pos
699- (and (string-match " "
700- (funcall file t t))
701- "\""))
702- (concat TeX-command-text " \"\\input\""))
703- (setq TeX-command-pos nil)
704- "")
705- (setq TeX-command-text nil))))
706- ("%n" TeX-current-line)
707- ("%d" file "dvi" t)
708- ("%f" file "ps" t)
709- ("%o" (lambda nil (funcall file (TeX-output-extension) t)))
710- ;; for source specials the file name generated for the xdvi
711- ;; command needs to be relative to the master file, just in
712- ;; case the file is in a different subdirectory
713- ("%b" TeX-current-file-name-master-relative)
714- ;; the following is for preview-latex.
715- ("%m" preview-create-subdirectory))
716- "List of expansion strings for TeX command names.
717-
718-Each entry is a list with two or more elements. The first element is
719-the string to be expanded. The second element is the name of a
720-function returning the expanded string when called with the remaining
721-elements as arguments. The special value `file' will be expanded to
722-the name of the file being processed, with an optional extension."
723- :group 'TeX-command
724- :type '(repeat (group (string :tag "Key")
725- (sexp :tag "Expander")
726- (repeat :inline t
727- :tag "Arguments"
728- (sexp :format "%v")))))
729-
730-
731-;; The following dependencies are not done with autoload cookies since
732-;; they are only useful when tex.el is loaded, anyway. tex-buf.el
733-;; should remain unloaded as long as one is only editing files, so
734-;; requiring it here would be wrong.
735-
736-(autoload 'TeX-region-create "tex-buf" nil nil)
737-(autoload 'TeX-save-document "tex-buf" nil t)
738-(autoload 'TeX-home-buffer "tex-buf" nil t)
739-(autoload 'TeX-pin-region "tex-buf" nil t)
740-(autoload 'TeX-command-region "tex-buf" nil t)
741-(autoload 'TeX-command-buffer "tex-buf" nil t)
742-(autoload 'TeX-command-master "tex-buf" nil t)
743-(autoload 'TeX-command "tex-buf" nil nil)
744-(autoload 'TeX-kill-job "tex-buf" nil t)
745-(autoload 'TeX-recenter-output-buffer "tex-buf" nil t)
746-(autoload 'TeX-next-error "tex-buf" nil t)
747-(autoload 'TeX-region-file "tex-buf" nil nil)
748-(autoload 'TeX-current-offset "tex-buf" nil nil)
749-(autoload 'TeX-process-set-variable "tex-buf" nil nil)
750-(autoload 'TeX-view "tex-buf" nil t)
751-
752-;;; Portability.
753-
754-(require 'easymenu)
755-
756-(eval-and-compile
757- (if (featurep 'xemacs)
758- (defun TeX-maybe-remove-help (menu)
759- "Removes :help entries from menus, since XEmacs does not like them.
760-Also does other stuff."
761- (cond ((consp menu)
762- (cond ((eq (car menu) :help)
763- (TeX-maybe-remove-help (cddr menu)))
764- ((eq (car menu) :visible)
765- (cons :included
766- (cons (cadr menu)
767- (TeX-maybe-remove-help (cddr menu)))))
768- (t (cons (TeX-maybe-remove-help (car menu))
769- (TeX-maybe-remove-help (cdr menu))))))
770- ((vectorp menu)
771- (vconcat (TeX-maybe-remove-help (append menu nil))))
772- (t menu)))
773- (defun TeX-maybe-remove-help (menu)
774- "Compatibility function that would remove :help entries if on XEmacs,
775-but does nothing in Emacs."
776- menu))
777- (defmacro TeX-menu-with-help (menu)
778- "Compatibility macro that removes :help entries if on XEmacs.
779-Also does other stuff."
780- (TeX-maybe-remove-help menu)))
781-
782-
783-;;; Documentation for Info-goto-emacs-command-node and similar
784-
785-(eval-after-load 'info '(dolist (elt '("TeX" "LaTeX" "ConTeXt" "Texinfo"
786- "docTeX"))
787- (add-to-list 'Info-file-list-for-emacs
788- (cons elt "AUCTeX"))))
789-
790-(defadvice hack-one-local-variable (after TeX-hack-one-local-variable-after
791- activate)
792- "Call minor mode function if minor mode variable is found."
793- (let ((var (ad-get-arg 0))
794- (val (ad-get-arg 1)))
795- ;; Instead of checking for each mode explicitely `minor-mode-list'
796- ;; could be used. But this may make the byte compiler pop up.
797- (when (memq var '(TeX-PDF-mode
798- TeX-source-correlate-mode TeX-interactive-mode
799- TeX-fold-mode LaTeX-math-mode))
800- (if (symbol-value val) (funcall var 1) (funcall var 0)))))
801-
802-(defvar TeX-overlay-priority-step 16
803- "Numerical difference of priorities between nested overlays.
804-The step should be big enough to allow setting a priority for new
805-overlays between two existing ones.")
806-
807-
808-;;; Special support for XEmacs
809-
810-(when (featurep 'xemacs)
811-
812- (defun TeX-read-string
813- (prompt &optional initial-input history default-value)
814- (condition-case nil
815- (read-string prompt initial-input history default-value t)
816- (wrong-number-of-arguments
817- (read-string prompt initial-input history default-value))))
818-
819- (defun TeX-mark-active ()
820- ;; In Lucid (mark) returns nil when not active.
821- (if zmacs-regions
822- (mark)
823- (mark t)))
824-
825- (defun TeX-active-mark ()
826- (and zmacs-regions (mark)))
827-
828- (fset 'TeX-activate-region (symbol-function 'zmacs-activate-region))
829-
830- ;; I am aware that this counteracts coding conventions but I am sick
831- ;; of it.
832- (unless (fboundp 'line-beginning-position)
833- (defalias 'line-beginning-position 'point-at-bol))
834- (unless (fboundp 'line-end-position)
835- (defalias 'line-end-position 'point-at-eol))
836-
837- (defun TeX-overlay-prioritize (start end)
838- "Calculate a priority for an overlay extending from START to END.
839-The calculated priority is lower than the minimum of priorities
840-of surrounding overlays and higher than the maximum of enclosed
841-overlays."
842- (let (inner-priority outer-priority
843- (prios (cons nil nil)))
844- (map-extents
845- #'(lambda (ov prios)
846- (and
847- (or (eq (extent-property ov 'category) 'TeX-fold)
848- (extent-property ov 'preview-state))
849- (setcar prios
850- (max (or (car prios) 0)
851- (extent-property ov 'priority))))
852- nil)
853- nil start end prios 'start-and-end-in-region 'priority)
854- (map-extents
855- #'(lambda (ov prios)
856- (and
857- (or (eq (extent-property ov 'category) 'TeX-fold)
858- (extent-property ov 'preview-state))
859- (setcdr prios
860- (min (or (cdr prios) most-positive-fixnum)
861- (extent-property ov 'priority))))
862- nil)
863- nil start end prios
864- '(start-and-end-in-region negate-in-region) 'priority)
865- (setq inner-priority (car prios) outer-priority (cdr prios))
866- (cond ((and inner-priority (not outer-priority))
867- (+ inner-priority TeX-overlay-priority-step))
868- ((and (not inner-priority) outer-priority)
869- (/ outer-priority 2))
870- ((and inner-priority outer-priority)
871- (+ (/ (- outer-priority inner-priority) 2) inner-priority))
872- (t TeX-overlay-priority-step)))) )
873-
874-
875-(if (fboundp 'completing-read-multiple)
876- (defalias 'TeX-completing-read-multiple 'completing-read-multiple)
877- (defun TeX-completing-read-multiple
878- (prompt table &optional predicate require-match initial-input
879- hist def inherit-input-method)
880- "Poor mans implementation of Emacs' `completing-read-multiple' for XEmacs.
881-The XEmacs package edit-utils-2.32 includes `crm.el'."
882- (multi-prompt "," nil prompt table predicate require-match initial-input
883- hist)))
884-
885-(if (fboundp 'line-number-at-pos)
886- (defalias 'TeX-line-number-at-pos 'line-number-at-pos)
887- ;; `line-number-at-pos' from `simple.el' in Emacs CVS (2006-06-07)
888- (defun TeX-line-number-at-pos (&optional pos)
889- "Return (narrowed) buffer line number at position POS.
890-If POS is nil, use current buffer location."
891- (let ((opoint (or pos (point))) start)
892- (save-excursion
893- (goto-char (point-min))
894- (setq start (point))
895- (goto-char opoint)
896- (forward-line 0)
897- (1+ (count-lines start (point)))))))
898-
899-;;; Special support for GNU Emacs
900-
901-(unless (featurep 'xemacs)
902-
903- (defun TeX-read-string (prompt &optional initial-input history default-value)
904- (read-string prompt initial-input history default-value t))
905-
906- (defun TeX-mark-active ()
907- ;; In FSF 19 mark-active indicates if mark is active.
908- mark-active)
909-
910- (defun TeX-active-mark ()
911- (and transient-mark-mode mark-active))
912-
913- (defun TeX-activate-region ()
914- nil)
915-
916- (defun TeX-overlay-prioritize (start end)
917- "Calculate a priority for an overlay extending from START to END.
918-The calculated priority is lower than the minimum of priorities
919-of surrounding overlays and higher than the maximum of enclosed
920-overlays."
921- (let (outer-priority inner-priority ov-priority)
922- (dolist (ov (overlays-in start end))
923- (when (or (eq (overlay-get ov 'category) 'TeX-fold)
924- (overlay-get ov 'preview-state))
925- (setq ov-priority (overlay-get ov 'priority))
926- (if (>= (overlay-start ov) start)
927- (setq inner-priority (max ov-priority (or inner-priority
928- ov-priority)))
929- (setq outer-priority (min ov-priority (or outer-priority
930- ov-priority))))))
931- (cond ((and inner-priority (not outer-priority))
932- (+ inner-priority TeX-overlay-priority-step))
933- ((and (not inner-priority) outer-priority)
934- (/ outer-priority 2))
935- ((and inner-priority outer-priority)
936- (+ (/ (- outer-priority inner-priority) 2) inner-priority))
937- (t TeX-overlay-priority-step)))) )
938-
939-(defun TeX-delete-dups-by-car (alist &optional keep-list)
940- "Return a list of all elements in ALIST, but each car only once.
941-Elements of KEEP-LIST are not removed even if duplicate."
942- ;; Copy of `reftex-uniquify-by-car' (written by David Kastrup).
943- (setq keep-list (sort (copy-sequence keep-list) #'string<))
944- (setq alist (sort (copy-sequence alist)
945- (lambda (a b)
946- (string< (car a) (car b)))))
947- (let ((new alist) elt)
948- (while new
949- (setq elt (caar new))
950- (while (and keep-list (string< (car keep-list) elt))
951- (setq keep-list (cdr keep-list)))
952- (unless (and keep-list (string= elt (car keep-list)))
953- (while (string= elt (car (cadr new)))
954- (setcdr new (cddr new))))
955- (setq new (cdr new))))
956- alist)
957-
958-(defun TeX-delete-duplicate-strings (list)
959- "Return a list of all strings in LIST, but each only once."
960- (setq list (TeX-sort-strings list))
961- (let ((new list) elt)
962- (while new
963- (setq elt (car new))
964- (while (string= elt (cadr new))
965- (setcdr new (cddr new)))
966- (setq new (cdr new))))
967- list)
968-
969-(defun TeX-sort-strings (list)
970- "Return sorted list of all strings in LIST."
971- (sort (copy-sequence list) #'string<))
972-
973-;;; Buffer
974-
975-(defgroup TeX-output nil
976- "Parsing TeX output."
977- :prefix "TeX-"
978- :group 'AUCTeX)
979-
980-(defcustom TeX-display-help t
981- "Control type of help display when stepping through errors with \\[TeX-next-error].
982-If t display help buffer. If nil display message about error in
983-echo area. If `expert' display output buffer with raw processor output."
984- :group 'TeX-output
985- :type '(choice (const :tag "Help buffer" t)
986- (const :tag "Echo area" nil)
987- (const :tag "Output buffer" expert)))
988-
989-(defcustom TeX-debug-bad-boxes nil
990- "Non-nil means also find overfull/underfull box warnings with \\[TeX-next-error]."
991- :group 'TeX-output
992- :type 'boolean)
993-
994-(defcustom TeX-debug-warnings nil
995- "Non-nil means also find LaTeX or package warnings with \\[TeX-next-error]."
996- :group 'TeX-output
997- :type 'boolean)
998-
999-(defun TeX-toggle-debug-bad-boxes ()
1000- "Toggle if the debugger should display \"bad boxes\" too."
1001- (interactive)
1002- (setq TeX-debug-bad-boxes (not TeX-debug-bad-boxes))
1003- (message (concat "TeX-debug-bad-boxes: "
1004- (if TeX-debug-bad-boxes "on" "off"))))
1005-
1006-(defun TeX-toggle-debug-warnings ()
1007- "Toggle if the debugger should display warnings too."
1008- (interactive)
1009- (setq TeX-debug-warnings (not TeX-debug-warnings))
1010- (message (concat "TeX-debug-warnings: "
1011- (if TeX-debug-warnings "on" "off"))))
1012-
1013-;;; Mode names.
1014-
1015-(defvar TeX-base-mode-name nil
1016- "Base name of mode.")
1017-(make-variable-buffer-local 'TeX-base-mode-name)
1018-
1019-(defun TeX-set-mode-name (&optional changed local reset)
1020- "Build and set the mode name.
1021-The base mode name will be concatenated with indicators for
1022-helper modes where appropriate.
1023-
1024-If CHANGED is non-nil, it indicates which global mode
1025-may have changed so that all corresponding buffers
1026-without a local value might get their name updated.
1027-A value of t will thus update all buffer names.
1028-
1029-If LOCAL is non-nil and CHANGED is buffer-local, only
1030-a local change has been performed and only the local
1031-name is to be updated.
1032-
1033-If RESET is non-nil, `TeX-command-next' is reset to
1034-`TeX-command-default' in updated buffers."
1035- (if (and changed
1036- (not (and local (local-variable-p changed (current-buffer)))))
1037- (dolist (buffer (buffer-list))
1038- (and (local-variable-p 'TeX-mode-p buffer)
1039- (not (local-variable-p changed buffer))
1040- (with-current-buffer buffer (TeX-set-mode-name nil nil reset))))
1041- (if TeX-mode-p
1042- (let ((trailing-flags
1043- (concat
1044- (and (boundp 'TeX-fold-mode) TeX-fold-mode "F")
1045- (and (boundp 'LaTeX-math-mode) LaTeX-math-mode "M")
1046- (and TeX-PDF-mode "P")
1047- (and TeX-interactive-mode "I")
1048- (and TeX-source-correlate-mode "S"))))
1049- (setq mode-name (concat TeX-base-mode-name
1050- (when (> (length trailing-flags) 0)
1051- (concat "/" trailing-flags))))
1052- (when reset
1053- (TeX-process-set-variable (TeX-master-file)
1054- 'TeX-command-next TeX-command-default)
1055- (TeX-process-set-variable (TeX-region-file)
1056- 'TeX-command-next TeX-command-default))
1057- (set-buffer-modified-p (buffer-modified-p))))))
1058-
1059-(defun TeX-mode-prefix ()
1060- "Return the prefix of the current mode as string."
1061- (cdr (assoc major-mode '((plain-tex-mode . "plain-TeX")
1062- (latex-mode . "LaTeX")
1063- (doctex-mode . "docTeX")
1064- (texinfo-mode . "Texinfo")
1065- (context-mode . "ConTeXt")))))
1066-
1067-;;; Viewing
1068-
1069-(defgroup TeX-view nil
1070- "Calling viewers from AUCTeX."
1071- :group 'TeX-command)
1072-
1073-(defcustom TeX-view-style
1074- `((,(concat
1075- "^" (regexp-opt '("a4paper" "a4dutch" "a4wide" "sem-a4")) "$")
1076- "%(o?)xdvi %dS -paper a4 %d")
1077- (,(concat "^" (regexp-opt '("a5paper" "a5comb")) "$")
1078- "%(o?)xdvi %dS -paper a5 %d")
1079- ("^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
1080- ("^letterpaper$" "%(o?)xdvi %dS -paper us %d")
1081- ("^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
1082- ("^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
1083- ("^landscape$" "%(o?)xdvi %dS -paper a4r -s 0 %d")
1084- ;; The latest xdvi can show embedded postscript. If you don't
1085- ;; have that, uncomment next line.
1086- ;; ("^epsf$" "ghostview %f")
1087- ("." "%(o?)xdvi %dS %d"))
1088- "List of style options and view options.
1089-
1090-If the first element (a regular expression) matches the name of
1091-one of the style files, any occurrence of the string `%v' in a
1092-command in `TeX-command-list' will be replaced with the second
1093-element. The first match is used, if no match is found the `%v'
1094-is replaced with the empty string.
1095-
1096-As a default, the \"View\" command in `TeX-command-list' is set
1097-to `%V'. This means that `TeX-output-view-style' will be
1098-consulted before `TeX-view-style'. Only if no match is found in
1099-`TeX-output-view-style' the settings in `TeX-view-style' will be
1100-considered. If you want to bypass `TeX-output-view-style', which
1101-is not recommended because it is more powerful than
1102-`TeX-view-style', use `%v' in the \"View\" command."
1103- :group 'TeX-view
1104- :type '(repeat (group regexp (string :tag "Command"))))
1105-
1106-(defcustom TeX-output-view-style
1107- `(("^dvi$" ("^landscape$" "^pstricks$\\|^pst-\\|^psfrag$")
1108- "%(o?)dvips -t landscape %d -o && gv %f")
1109- ("^dvi$" "^pstricks$\\|^pst-\\|^psfrag$" "%(o?)dvips %d -o && gv %f")
1110- ("^dvi$" (,(concat
1111- "^" (regexp-opt '("a4paper" "a4dutch" "a4wide" "sem-a4")) "$")
1112- "^landscape$")
1113- "%(o?)xdvi %dS -paper a4r -s 0 %d")
1114- ("^dvi$" ,(concat
1115- "^" (regexp-opt '("a4paper" "a4dutch" "a4wide" "sem-a4")) "$")
1116- "%(o?)xdvi %dS -paper a4 %d")
1117- ("^dvi$" (,(concat "^" (regexp-opt '("a5paper" "a5comb")) "$")
1118- "^landscape$")
1119- "%(o?)xdvi %dS -paper a5r -s 0 %d")
1120- ("^dvi$" ,(concat "^" (regexp-opt '("a5paper" "a5comb")) "$")
1121- "%(o?)xdvi %dS -paper a5 %d")
1122- ("^dvi$" "^b5paper$" "%(o?)xdvi %dS -paper b5 %d")
1123- ("^dvi$" "^letterpaper$" "%(o?)xdvi %dS -paper us %d")
1124- ("^dvi$" "^legalpaper$" "%(o?)xdvi %dS -paper legal %d")
1125- ("^dvi$" "^executivepaper$" "%(o?)xdvi %dS -paper 7.25x10.5in %d")
1126- ("^dvi$" "." "%(o?)xdvi %dS %d")
1127- ("^pdf$" "." "xpdf -remote %s -raise %o %(outpage)")
1128- ("^html?$" "." "netscape %o"))
1129- "List of output file extensions and view options.
1130-
1131-If the first element (a regular expression) matches the output
1132-file extension, and the second element (a regular expression)
1133-matches the name of one of the style options, any occurrence of
1134-the string `%V' in a command in `TeX-command-list' will be
1135-replaced with the third element. The first match is used; if no
1136-match is found the `%V' is replaced with `%v'. The outcome of `%v'
1137-is determined by the settings in `TeX-view-style' which therefore
1138-serves as a fallback for `TeX-output-view-style'. The second
1139-element may also be a list of regular expressions, in which case
1140-all the regular expressions must match for the element to apply."
1141- :group 'TeX-view
1142- :type '(repeat (group
1143- (regexp :tag "Extension")
1144- (choice regexp (repeat :tag "List" regexp))
1145- (string :tag "Command"))))
1146-
1147-;;; Viewing (new implementation)
1148-
1149-(defvar TeX-view-predicate-list-builtin
1150- '((output-dvi
1151- (string-match "dvi" (TeX-output-extension)))
1152- (output-pdf
1153- (string-match "pdf" (TeX-output-extension)))
1154- (output-html
1155- (string-match "html" (TeX-output-extension)))
1156- (style-pstricks
1157- (TeX-match-style "^pstricks$\\|^pst-\\|^psfrag$"))
1158- (engine-omega
1159- (eq TeX-engine 'omega))
1160- (engine-xetex
1161- (eq TeX-engine 'xetex))
1162- (mode-io-correlate
1163- TeX-source-correlate-mode)
1164- (paper-landscape
1165- (TeX-match-style "\\`landscape\\'"))
1166- (paper-portrait
1167- (not (TeX-match-style "\\`landscape\\'")))
1168- (paper-a4
1169- (TeX-match-style "\\`a4paper\\|a4dutch\\|a4wide\\|sem-a4\\'"))
1170- (paper-a5
1171- (TeX-match-style "\\`a5paper\\|a5comb\\'"))
1172- (paper-b5
1173- (TeX-match-style "\\`b5paper\\'"))
1174- (paper-letter
1175- (TeX-match-style "\\`letterpaper\\'"))
1176- (paper-legal
1177- (TeX-match-style "\\`legalpaper\\'"))
1178- (paper-executive
1179- (TeX-match-style "\\`executivepaper\\'")))
1180- "Alist of built-in predicates for viewer selection and invocation.
1181-See the doc string of `TeX-view-predicate-list' for a short
1182-description of each predicate.")
1183-
1184-(defcustom TeX-view-predicate-list nil
1185- "Alist of predicates for viewer selection and invocation.
1186-The key of each list item is a symbol and the value a Lisp form
1187-to be evaluated. The form should return nil if the predicate is
1188-not fulfilled.
1189-
1190-Built-in predicates provided in `TeX-view-predicate-list-builtin'
1191-can be overwritten by defining predicates with the same symbol.
1192-
1193-The following built-in predicates are available:
1194- `output-dvi': The output is a DVI file.
1195- `output-pdf': The output is a PDF file.
1196- `output-html': The output is an HTML file.
1197- `style-pstricks': The document loads a PSTricks package.
1198- `engine-omega': The Omega engine is used for typesetting.
1199- `engine-xetex': The XeTeX engine is used for typesetting.
1200- `mode-io-correlate': TeX Source Correlate mode is active.
1201- `paper-landscape': The document is typeset in landscape orientation.
1202- `paper-portrait': The document is not typeset in landscape orientation.
1203- `paper-a4': The paper format is A4.
1204- `paper-a5': The paper format is A5.
1205- `paper-b5': The paper format is B5.
1206- `paper-letter': The paper format is letter.
1207- `paper-legal': The paper format is legal.
1208- `paper-executive': The paper format is executive."
1209- :group 'TeX-view
1210- :type '(alist :key-type symbol :value-type (group sexp)))
1211-
1212-(defvar TeX-view-program-list-builtin
1213- (cond
1214- ((eq system-type 'windows-nt)
1215- '(("Yap" ("yap -1" (mode-io-correlate " -s %n%b") " %o"))
1216- ("dvips and start" "dvips %d -o && start \"\" %f")
1217- ("start" "start \"\" %o")))
1218-;; XXX: We need the advice of a Mac OS X user to configure this
1219-;; correctly and test it.
1220-;; ((eq system-type 'darwin)
1221-;; '(("Preview.app" "open -a Preview.app %o")
1222-;; ("Skim" "open -a Skim.app %o")
1223-;; ("displayline" "displayline %n %o %b")
1224-;; ("open" "open %o")))
1225- (t
1226- '(("xdvi" ("%(o?)xdvi"
1227- (mode-io-correlate " -sourceposition \"%n %b\" -editor \"%cS\"")
1228- ((paper-a4 paper-portrait) " -paper a4")
1229- ((paper-a4 paper-landscape) " -paper a4r")
1230- ((paper-a5 paper-portrait) " -paper a5")
1231- ((paper-a5 paper-landscape) " -paper a5r")
1232- (paper-b5 " -paper b5")
1233- (paper-letter " -paper us")
1234- (paper-legal " -paper legal")
1235- (paper-executive " -paper 7.25x10.5in")
1236- " %d"))
1237- ("dvips and gv" "%(o?)dvips %d -o && gv %f")
1238- ("gv" "gv %o")
1239- ("xpdf" ("xpdf -remote %s -raise %o" (mode-io-correlate " %(outpage)")))
1240- ("Evince" ("evince" (mode-io-correlate " -p %(outpage)") " %o"))
1241- ("xdg-open" "xdg-open %o"))))
1242- "Alist of built-in viewer specifications.
1243-This variable should not be changed by the user who can use
1244-`TeX-view-program-list' to add new viewers or overwrite the
1245-definition of built-in ones. The latter variable also contains a
1246-description of the data format.")
1247-
1248-(defcustom TeX-view-program-list nil
1249- "Alist of viewer specifications.
1250-This variable can be used to specify how a viewer is to be
1251-invoked and thereby add new viewers on top of the built-in list
1252-of viewers defined in `TeX-view-program-list-builtin' or override
1253-entries in the latter.
1254-
1255-The car of each item is a string with a user-readable name. The
1256-second element can be a command line to be run as a process or a
1257-Lisp function to be executed. The command line can either be
1258-specified as a single string or a list of strings and two-part
1259-lists. The first element of the two-part lists is a symbol or a
1260-list of symbols referring to one or more of the predicates in
1261-`TeX-view-predicate-list' or `TeX-view-predicate-list-builtin'.
1262-The second part of the two-part lists is a command line part.
1263-The command line for the viewer is constructed by concatenating
1264-the command line parts. Parts with a predicate are only
1265-considered if the predicate was evaluated with a positive result.
1266-Note that the command line can contain placeholders as defined in
1267-`TeX-expand-list' which are expanded before the viewer is called.
1268-
1269-The use of a function as the second element only works if the
1270-View command in `TeX-command-list' makes use of the hook
1271-`TeX-run-discard-or-function'.
1272-
1273-Note: Predicates defined in the current Emacs session will only
1274-show up in the customization interface for this variable after
1275-restarting Emacs."
1276- :group 'TeX-view
1277- :type
1278- `(alist
1279- :key-type (string :tag "Name")
1280- :value-type
1281- (choice
1282- (group :tag "Command" (string :tag "Command"))
1283- (group :tag "Command parts"
1284- (repeat
1285- :tag "Command parts"
1286- (choice
1287- (string :tag "Command part")
1288- (list :tag "Predicate and command part"
1289- ,(let (list)
1290- ;; Build the list of available predicates.
1291- (mapc (lambda (spec)
1292- (add-to-list 'list `(const ,(car spec))))
1293- (append TeX-view-predicate-list
1294- TeX-view-predicate-list-builtin))
1295- ;; Sort the list alphabetically.
1296- (setq list (sort list
1297- (lambda (a b)
1298- (string<
1299- (downcase (symbol-name (cadr a)))
1300- (downcase (symbol-name (cadr b)))))))
1301- `(choice
1302- (choice :tag "Predicate" ,@list)
1303- (repeat :tag "List of predicates"
1304- (choice :tag "Predicate" ,@list))))
1305- (string :tag "Command part")))))
1306- (group :tag "Function" function))))
1307-
1308-;; XXX: Regarding a possibility to (manually) run an update command,
1309-;; one could support this through `TeX-view' by letting it temporarily
1310-;; set a variable which is checked with a predicate in the viewer
1311-;; selection. If the check is positive, the update command is run
1312-;; instead of the normal viewer command. Direct support through the
1313-;; View command would require a predicate which knows when an update
1314-;; has to be done.
1315-(defcustom TeX-view-program-selection
1316- (cond
1317- ((eq system-type 'windows-nt)
1318- '(((output-dvi style-pstricks) "dvips and start")
1319- (output-dvi "Yap")
1320- (output-pdf "start")
1321- (output-html "start")))
1322-;; XXX: We need the advice of a Mac OS X user to configure this
1323-;; correctly and test it.
1324-;; ((eq system-type 'darwin)
1325-;; '((output-dvi "open")
1326-;; (output-pdf "open")
1327-;; (output-html "open")))
1328- (t
1329- '(((output-dvi style-pstricks) "dvips and gv")
1330- (output-dvi "xdvi")
1331- (output-pdf "Evince")
1332- (output-html "xdg-open"))))
1333- "Alist of predicates and viewers.
1334-Each entry consists of a list with two elements. The first
1335-element is a symbol or list of symbols referring to predicates as
1336-defined in `TeX-view-predicate-list' or
1337-`TeX-view-predicate-list-builtin'. The second element is a
1338-string referring to the name of a viewer as defined in
1339-`TeX-view-program-list' or `TeX-view-program-list-builtin'.
1340-
1341-When a viewer is called for, the entries are evaluated in turn
1342-and the viewer related to the first entry all predicates of which
1343-are evaluated positively is chosen."
1344- :group 'TeX-view
1345- :type `(alist :key-type
1346- ;; Offer list of defined predicates.
1347- ,(let (list)
1348- (mapc (lambda (spec)
1349- (add-to-list 'list `(const ,(car spec))))
1350- (append TeX-view-predicate-list
1351- TeX-view-predicate-list-builtin))
1352- (setq list (sort list
1353- (lambda (a b)
1354- (string<
1355- (downcase (symbol-name (cadr a)))
1356- (downcase (symbol-name (cadr b)))))))
1357- `(choice (choice :tag "Single predicate" ,@list)
1358- (repeat :tag "Multiple predicates"
1359- (choice ,@list))))
1360- :value-type
1361- ;; Offer list of defined viewers.
1362- (group (choice :tag "Viewer"
1363- ,@(let (list)
1364- (mapc (lambda (spec)
1365- (add-to-list 'list
1366- `(const ,(car spec))))
1367- (append TeX-view-program-list
1368- TeX-view-program-list-builtin))
1369- (sort list
1370- (lambda (a b)
1371- (string< (downcase (cadr a))
1372- (downcase (cadr b))))))))))
1373-
1374-(defun TeX-match-style (regexp)
1375- "Check if a style matching REGEXP is active."
1376- (TeX-member regexp (TeX-style-list) 'string-match))
1377-
1378-(defun TeX-view-match-predicate (predicate)
1379- "Check if PREDICATE is true.
1380-PREDICATE can be a symbol or a list of symbols defined in
1381-`TeX-view-predicate-list-builtin' or `TeX-view-predicate-list'.
1382-In case of a single symbol, return t if the predicate is true,
1383-nil otherwise. In case of a list of symbols, return t if all
1384-predicates are true, nil otherwise."
1385- (let ((pred-symbols (if (listp predicate) predicate (list predicate)))
1386- (pred-defs (append TeX-view-predicate-list
1387- TeX-view-predicate-list-builtin))
1388- (result t)
1389- elt)
1390- (while (and (setq elt (pop pred-symbols)) result)
1391- (unless (eval (cadr (assq elt pred-defs)))
1392- (setq result nil)))
1393- result))
1394-
1395-(defun TeX-view-command-raw ()
1396- "Choose a viewer and return its unexpanded command string."
1397- (let ((selection TeX-view-program-selection)
1398- entry viewer spec command)
1399- ;; Find the appropriate viewer.
1400- (while (and (setq entry (pop selection)) (not viewer))
1401- (when (TeX-view-match-predicate (car entry))
1402- (setq viewer (cadr entry))))
1403- (unless viewer
1404- (error "No matching viewer found"))
1405- ;; Get the command line or function spec.
1406- (setq spec (cadr (assoc viewer (append TeX-view-program-list
1407- TeX-view-program-list-builtin))))
1408- (cond ((functionp spec)
1409- ;; Converting the function call to a string is ugly, but
1410- ;; the backend currently only supports strings.
1411- (prin1-to-string spec))
1412- ((stringp spec)
1413- spec)
1414- (t
1415- ;; Build the unexpanded command line. Pieces with predicates are
1416- ;; only added if the predicate is evaluated positively.
1417- (dolist (elt spec)
1418- (cond ((stringp elt)
1419- (setq command (concat command elt)))
1420- ((listp elt)
1421- (when (TeX-view-match-predicate (car elt))
1422- (setq command (concat command (cadr elt)))))))
1423- command))))
1424-
1425-;;; Engine
1426-
1427-(defvar TeX-engine-alist-builtin
1428- '((default "Default" TeX-command LaTeX-command ConTeXt-engine)
1429- (xetex "XeTeX" "xetex" "xelatex" "xetex")
1430- (luatex "LuaTeX" "luatex" "lualatex" "luatex")
1431- (omega "Omega" TeX-Omega-command LaTeX-Omega-command ConTeXt-Omega-engine))
1432- "Alist of built-in TeX engines and associated commands.
1433-For a description of the format see `TeX-engine-alist'.")
1434-
1435-(defcustom TeX-engine-alist nil
1436- "Alist of TeX engines and associated commands.
1437-Each entry is a list with a maximum of five elements. The first
1438-element is a symbol used to identify the engine. The second is a
1439-string describing the engine. The third is the command to be
1440-used for plain TeX. The fourth is the command to be used for
1441-LaTeX. The fifth is the command to be used for the --engine
1442-parameter of ConTeXt's texexec program. Each command can either
1443-be a variable or a string. An empty string or nil means there is
1444-no command available.
1445-
1446-You can override a built-in engine defined in the variable
1447-`TeX-engine-alist-builtin' by adding an entry beginning with the
1448-same symbol as the built-in entry to `TeX-engine-alist'."
1449- :group 'TeX-command
1450- :type '(repeat (group symbol
1451- (string :tag "Name")
1452- (choice :tag "Plain TeX command" string variable)
1453- (choice :tag "LaTeX command" string variable)
1454- (choice :tag "ConTeXt command" string variable))))
1455-
1456-(defun TeX-engine-alist ()
1457- "Return an alist of TeX engines.
1458-The function appends the built-in engine specs from
1459-`TeX-engine-alist-builtin' and the user-defined engines from
1460-`TeX-engine-alist' and deletes any entries from the built-in part
1461-where an entry with the same car exists in the user-defined part."
1462- (TeX-delete-dups-by-car (append TeX-engine-alist TeX-engine-alist-builtin)))
1463-
1464-(defcustom TeX-engine 'default
1465- (concat "Type of TeX engine to use.
1466-It should be one of the following symbols:\n\n"
1467- (mapconcat (lambda (x) (format "* `%s'" (car x)))
1468- (TeX-engine-alist) "\n"))
1469- :group 'TeX-command
1470- :type `(choice ,@(mapcar (lambda (x)
1471- `(const :tag ,(nth 1 x) ,(car x)))
1472- (TeX-engine-alist))))
1473-(make-variable-buffer-local 'TeX-engine)
1474-(put 'TeX-engine 'safe-local-variable
1475- (lambda (arg) (memq arg (mapcar 'car TeX-engine-alist-builtin))))
1476-
1477-(defun TeX-engine-set (type)
1478- (concat "Set TeX engine to TYPE.
1479-TYPE can be one of the following symbols:\n"
1480- (mapconcat (lambda (x) (format "* `%s'" (car x)))
1481- (TeX-engine-alist) "\n"))
1482- (interactive (list (completing-read "Engine: "
1483- (mapcar (lambda (x)
1484- (symbol-name (car x)))
1485- (TeX-engine-alist))
1486- nil t)))
1487- (when (stringp type)
1488- (setq type (intern type)))
1489- (setq TeX-engine type)
1490- ;; Automatically enable or disable TeX PDF mode as a convenience
1491- (cond ((eq type 'xetex) (TeX-PDF-mode 1))
1492- ((eq type 'omega) (TeX-PDF-mode 0))))
1493-
1494-(define-minor-mode TeX-Omega-mode
1495- "Minor mode for using the Omega engine."
1496- nil nil nil
1497- :group 'TeX-command
1498- (TeX-engine-set (if TeX-Omega-mode 'omega 'default)))
1499-(defalias 'tex-omega-mode 'TeX-Omega-mode)
1500-(make-obsolete 'TeX-Omega-mode 'TeX-engine-set)
1501-(make-obsolete-variable 'TeX-Omega-mode 'TeX-engine)
1502-
1503-;;; Forward and inverse search
1504-
1505-(defcustom TeX-source-correlate-method 'auto
1506- "Method to use for enabling forward and inverse search.
1507-This can be `source-specials' if source specials should be used,
1508-`synctex' if SyncTeX should be used, or`auto' if AUCTeX should
1509-decide.
1510-
1511-Setting this variable does not take effect if TeX Source
1512-Correlate mode has already been active. Restart Emacs in this
1513-case."
1514- :type '(choice (const auto) (const synctex) (const source-specials))
1515- :group 'TeX-view)
1516-
1517-(defvar TeX-source-correlate-method-active nil
1518- "Method actually used for forward and inverse search.")
1519-
1520-(defvar TeX-source-correlate-output-page-function nil
1521- "Symbol of function returning an output page relating to buffer position.
1522-The function should take no arguments and return the page numer
1523-as a string.")
1524-(make-variable-buffer-local 'TeX-source-correlate-output-page-function)
1525-
1526-(defcustom TeX-source-correlate-start-server 'ask
1527- "Control if server should be started for inverse search."
1528- :type '(choice (const :tag "Always" t)
1529- (const :tag "Never" nil)
1530- (const :tag "Ask" ask))
1531- :group 'TeX-view)
1532-(when (fboundp 'defvaralias)
1533- (defvaralias 'TeX-source-specials-view-start-server
1534- 'TeX-source-correlate-start-server))
1535-
1536-(defvar TeX-source-correlate-start-server-asked nil
1537- "Keep track if question about server start search was asked.")
1538-
1539-(defvar TeX-source-correlate-start-server-flag nil
1540- "If non-nil, `TeX-source-correlate-start-server-maybe' will start a server.
1541-Code related to features requiring a server, e.g. for inverse
1542-search, can set the variable.")
1543-
1544-(defun TeX-source-correlate-gnuserv-p ()
1545- "Guess whether to use gnuserv when a server is requested."
1546- (cond ((and (boundp 'gnuserv-process)
1547- (processp gnuserv-process)))
1548- ((and (boundp 'server-process)
1549- (processp server-process))
1550- nil)
1551- ((featurep 'xemacs))))
1552-
1553-(defun TeX-source-correlate-server-enabled-p ()
1554- "Return non-nil if Emacs server or gnuserv is enabled."
1555- (let* ((gnuserv-p (TeX-source-correlate-gnuserv-p))
1556- (process (if gnuserv-p 'gnuserv-process 'server-process)))
1557- (and (boundp process) (processp (symbol-value process)))))
1558-
1559-(defun TeX-source-correlate-start-server-maybe ()
1560- "Start Emacs server or gnuserv if a feature using it is enabled.
1561-This is the case if `TeX-source-correlate-start-server-flag' is non-nil."
1562- (when (and TeX-source-correlate-start-server-flag
1563- (not (TeX-source-correlate-server-enabled-p)))
1564- (let* ((gnuserv-p (TeX-source-correlate-gnuserv-p))
1565- (start (if gnuserv-p 'gnuserv-start 'server-start)))
1566- (cond
1567- ;; Server should be started unconditionally
1568- ((eq TeX-source-correlate-start-server t)
1569- (funcall start))
1570- ;; Ask user if server is to be started
1571- ((and (eq TeX-source-correlate-start-server 'ask)
1572- (not TeX-source-correlate-start-server-asked)
1573- (prog1
1574- (y-or-n-p (format "Start %s for inverse search in viewer? "
1575- (if gnuserv-p
1576- "gnuserv"
1577- "Emacs server")))
1578- (setq TeX-source-correlate-start-server-asked t)))
1579- (funcall start))))))
1580-
1581-(defun TeX-source-correlate-determine-method ()
1582- "Determine which method is available for forward and inverse search."
1583- (let ((help (condition-case nil
1584- (with-output-to-string
1585- (call-process LaTeX-command
1586- nil (list standard-output nil) nil "--help"))
1587- (error ""))))
1588- (if (string-match "^[ ]*-synctex" help)
1589- 'synctex
1590- 'source-specials)))
1591-
1592-(defun TeX-source-correlate-expand-options ()
1593- "Return TeX engine command line option for forward search facilities.
1594-The return value depends on the value of `TeX-source-correlate-mode'.
1595-If this is nil, an empty string will be returned."
1596- (if TeX-source-correlate-mode
1597- (if (eq TeX-source-correlate-method-active 'source-specials)
1598- (concat TeX-source-specials-tex-flags
1599- (if TeX-source-specials-places
1600- ;; -src-specials=WHERE: insert source specials
1601- ;; in certain places of the DVI file. WHERE is a
1602- ;; comma-separated value list: cr display hbox
1603- ;; math par parend vbox
1604- (concat "=" (mapconcat 'identity
1605- TeX-source-specials-places ","))))
1606- TeX-synctex-tex-flags)
1607- ""))
1608-
1609-(defvar TeX-source-correlate-map
1610- (let ((map (make-sparse-keymap)))
1611- ;; (if (featurep 'xemacs)
1612- ;; (define-key map [(control button1)] #'TeX-view-mouse)
1613- ;; (define-key map [C-down-mouse-1] #'TeX-view-mouse))
1614- map)
1615- "Keymap for `TeX-source-correlate-mode'.
1616-You could use this for unusual mouse bindings.")
1617-
1618-(define-minor-mode TeX-source-correlate-mode
1619- "Minor mode for forward and inverse search.
1620-
1621-If enabled, the viewer can be advised to show the output page
1622-corresponding to the point in the source and vice versa.
1623-
1624-The method to be used can be controlled with the variable
1625-`TeX-source-correlate-method'. Currently source specials or
1626-SyncTeX are recognized."
1627- :group 'TeX-view
1628- ;; Since this is a global minor mode and we don't want to require
1629- ;; tex.el when the mode variable is set, the mode function is called
1630- ;; explicitely (if necessary) in `VirTeX-common-initialization'. We
1631- ;; do it there because otherwise `kill-all-local-variables' would
1632- ;; reset `TeX-source-correlate-output-page-function' which is
1633- ;; buffer-local.
1634- :global t
1635- (set-keymap-parent TeX-mode-map (and TeX-source-correlate-mode
1636- TeX-source-correlate-map))
1637- (TeX-set-mode-name 'TeX-source-correlate-mode t t)
1638- (setq TeX-source-correlate-start-server-flag TeX-source-correlate-mode)
1639- (unless TeX-source-correlate-method-active
1640- (setq TeX-source-correlate-method-active
1641- (if (eq TeX-source-correlate-method 'auto)
1642- (TeX-source-correlate-determine-method)
1643- TeX-source-correlate-method)))
1644- (when (eq TeX-source-correlate-method-active 'synctex)
1645- (setq TeX-source-correlate-output-page-function
1646- (when TeX-source-correlate-mode
1647- 'TeX-synctex-output-page))))
1648-(defalias 'TeX-source-specials-mode 'TeX-source-correlate-mode)
1649-(make-obsolete 'TeX-source-specials-mode 'TeX-source-correlate-mode)
1650-(defalias 'tex-source-correlate-mode 'TeX-source-correlate-mode)
1651-(put 'TeX-source-correlate-mode 'safe-local-variable 'TeX-booleanp)
1652-;; We do not want the custom variable to require tex.el. This is only
1653-;; necessary if AUCTeX was compiled with Emacs 21.
1654-(put 'TeX-source-correlate-mode 'custom-requests nil)
1655-(setq minor-mode-map-alist
1656- (delq (assq 'TeX-source-correlate-mode minor-mode-map-alist)
1657- minor-mode-map-alist))
1658-
1659-
1660-;;; Source Specials
1661-
1662-(defcustom TeX-source-specials-tex-flags "-src-specials"
1663- "Extra flags to pass to TeX commands to generate source specials."
1664- :group 'TeX-view
1665- :type 'string)
1666-
1667-(defcustom TeX-source-specials-places nil
1668- "List of places where to insert source specials into the DVI file.
1669-If nil, use (La)TeX's defaults."
1670- :group 'TeX-view
1671- :type '(list (set :inline t
1672- ;; :tag "Options known to work"
1673- ;; cr display hbox math par parend vbox
1674- (const "cr")
1675- (const "display")
1676- (const "hbox")
1677- (const "math")
1678- (const "par")
1679- (const "parend")
1680- (const "vbox"))
1681- (repeat :inline t
1682- :tag "Other options"
1683- (string))))
1684-
1685-(defcustom TeX-source-specials-view-position-flags
1686- "-sourceposition \"%n %b\""
1687- "Flags to pass to the DVI viewer commands for the position in the source."
1688- :group 'TeX-view
1689- :type 'string)
1690-
1691-(defcustom TeX-source-specials-view-editor-flags
1692- "-editor \"%cS\""
1693- "Flags to pass to DVI viewer commands for inverse search."
1694- :group 'TeX-view
1695- :type 'string)
1696-
1697-(defcustom TeX-source-specials-view-gnuclient-flags
1698- "-q +%%l %%f"
1699- "Flags to pass to gnuclient for inverse search."
1700- :group 'TeX-view
1701- :type 'string)
1702-
1703-(defcustom TeX-source-specials-view-emacsclient-flags
1704- "--no-wait +%%l %%f"
1705- "Flags to emacsclient for inverse search."
1706- :group 'TeX-view
1707- :type 'string)
1708-
1709-;; FIXME: Make client binaries configurable.
1710-(defun TeX-source-specials-view-expand-client ()
1711- "Return gnuclient or emacslient executable with options.
1712-Return the full path to the executable if possible."
1713- (let* ((gnuserv-p (TeX-source-correlate-gnuserv-p))
1714- (client-base (if gnuserv-p
1715- "gnuclient"
1716- "emacsclient"))
1717- (client-full (and invocation-directory
1718- (expand-file-name client-base
1719- invocation-directory)))
1720- (options (if gnuserv-p
1721- TeX-source-specials-view-gnuclient-flags
1722- TeX-source-specials-view-emacsclient-flags)))
1723- (if (and client-full (file-executable-p client-full))
1724- (concat client-full " " options)
1725- (concat client-base " " options))))
1726-
1727-(defun TeX-source-specials-view-expand-options (&optional viewer)
1728- "Return source specials command line option for viewer command.
1729-The return value depends on the values of
1730-`TeX-source-correlate-mode' and
1731-`TeX-source-correlate-method-active'. If those are nil or not
1732-`source-specials' respectively, an empty string will be
1733-returned."
1734- (if (and TeX-source-correlate-mode
1735- (eq TeX-source-correlate-method-active 'source-specials))
1736- (concat TeX-source-specials-view-position-flags
1737- (when (TeX-source-correlate-server-enabled-p)
1738- (concat " " TeX-source-specials-view-editor-flags)))
1739- ""))
1740-
1741-;;; SyncTeX
1742-
1743-(defvar TeX-synctex-tex-flags "--synctex=1"
1744- "Extra flags to pass to TeX commands to enable SyncTeX.")
1745-
1746-(defun TeX-synctex-output-page ()
1747- "Return the page corresponding to the current source position.
1748-This method assumes that the document was compiled with SyncTeX
1749-enabled and the `synctex' binary is available."
1750- (let ((synctex-output
1751- (with-output-to-string
1752- (call-process "synctex" nil (list standard-output nil) nil "view"
1753- "-i" (format "%s:%s:%s" (line-number-at-pos)
1754- (current-column)
1755- ;; The file name relative to the
1756- ;; directory of the master file.
1757- (file-relative-name
1758- (buffer-file-name)
1759- (file-name-directory
1760- (TeX-active-master))))
1761- "-o" (TeX-active-master (TeX-output-extension))))))
1762- (when (string-match "Page:\\([0-9]+\\)" synctex-output)
1763- (match-string 1 synctex-output))))
1764-
1765-;;; Miscellaneous minor modes
1766-
1767-(defvar TeX-mode-p nil
1768- "This indicates a TeX mode being active.")
1769-(make-variable-buffer-local 'TeX-mode-p)
1770-
1771-(defun TeX-mode-set (var value)
1772- (set-default var value)
1773- (TeX-set-mode-name var nil t))
1774-
1775-(defcustom TeX-PDF-mode nil nil
1776- :group 'TeX-command
1777- :set 'TeX-mode-set
1778- :type 'boolean)
1779-(put 'TeX-PDF-mode 'safe-local-variable 'TeX-booleanp)
1780-
1781-(define-minor-mode TeX-PDF-mode
1782- "Minor mode for using PDFTeX.
1783-
1784-If enabled, PDFTeX will be used as an executable by default.
1785-You can customize an initial value, and you can use the
1786-function `TeX-global-PDF-mode' for toggling this value."
1787- :group 'TeX-command
1788- (when (eq TeX-engine 'omega)
1789- (setq TeX-PDF-mode nil))
1790- (setq TeX-PDF-mode-parsed nil)
1791- (TeX-set-mode-name nil nil t)
1792- (setq TeX-output-extension
1793- (if TeX-PDF-mode "pdf" "dvi")))
1794-(add-to-list 'minor-mode-alist '(TeX-PDF-mode ""))
1795-
1796-(defun TeX-global-PDF-mode (&optional arg)
1797- "Toggle default for `TeX-PDF-mode'."
1798- (interactive "P")
1799- (prog1
1800- (setq-default TeX-PDF-mode
1801- (if arg (> (prefix-numeric-value arg) 0)
1802- (not (default-value 'TeX-PDF-mode))))
1803- (TeX-set-mode-name 'TeX-PDF-mode nil t)))
1804-
1805-(defalias 'tex-pdf-mode 'TeX-PDF-mode)
1806-
1807-(defvar TeX-PDF-mode-parsed nil
1808- "Set if `TeX-PDF-mode' has come about by parsing.")
1809-
1810-(make-variable-buffer-local 'TeX-PDF-mode-parsed)
1811-
1812-(defun TeX-PDF-mode-parsed (arg)
1813- "Change `TeX-PDF-mode' to ARG based on parsing.
1814-If this conflicts with previous parsed settings,
1815-just use the default. If an explicit setting is
1816-already established, don't do anything."
1817-
1818-;; Basically we have the following situations:
1819-;; TeX-PDF-mode-parsed (local-variable-p 'TeX-PDF-mode):
1820-;; nil nil : virgin state
1821-;; nil t : stably set state (possibly because of conflicting parse info)
1822-;; t t : non-conflicting parsed info
1823-
1824- (if TeX-PDF-mode-parsed
1825- (unless (eq TeX-PDF-mode arg)
1826- (TeX-PDF-mode (if (default-value 'TeX-PDF-mode) 1 0)))
1827- (unless (local-variable-p 'TeX-PDF-mode (current-buffer))
1828- (TeX-PDF-mode (if arg 1 0))
1829- (setq TeX-PDF-mode-parsed t))))
1830-
1831-(defun TeX-PDF-mode-on ()
1832- "Use only from parsing routines."
1833- (TeX-PDF-mode-parsed t))
1834-
1835-(defun TeX-PDF-mode-off ()
1836- "Use only from parsing routines."
1837- (TeX-PDF-mode-parsed nil))
1838-
1839-(defcustom TeX-DVI-via-PDFTeX nil
1840- "Whether to use PDFTeX also for producing DVI files."
1841- :group 'TeX-command
1842- :type 'boolean)
1843-
1844-(define-minor-mode TeX-interactive-mode
1845- "Minor mode for interactive runs of TeX."
1846- nil nil nil
1847- :group 'TeX-command
1848- (TeX-set-mode-name 'TeX-interactive-mode t t))
1849-(defalias 'tex-interactive-mode 'TeX-interactive-mode)
1850-(add-to-list 'minor-mode-alist '(TeX-interactive-mode ""))
1851-
1852-;;; Commands
1853-
1854-(defgroup TeX-command-name nil
1855- "Names for external commands in AUCTeX."
1856- :group 'TeX-command)
1857-
1858-(defcustom TeX-command-BibTeX "BibTeX"
1859- "*The name of the BibTeX entry in `TeX-command-list'."
1860- :group 'TeX-command-name
1861- :type 'string)
1862- (make-variable-buffer-local 'TeX-command-BibTeX)
1863-
1864-(defcustom TeX-command-Show "View"
1865- "*The default command to show (view or print) a TeX file.
1866-Must be the car of an entry in `TeX-command-list'."
1867- :group 'TeX-command-name
1868- :type 'string)
1869- (make-variable-buffer-local 'TeX-command-Show)
1870-
1871-(defcustom TeX-command-Print "Print"
1872- "The name of the Print entry in `TeX-command-Print'."
1873- :group 'TeX-command-name
1874- :type 'string)
1875-
1876-(defcustom TeX-command-Queue "Queue"
1877- "The name of the Queue entry in `TeX-command-Queue'."
1878- :group 'TeX-command-name
1879- :type 'string)
1880-
1881-(defvar TeX-trailer-start nil
1882- "Regular expression delimiting start of trailer in a TeX file.")
1883-
1884- (make-variable-buffer-local 'TeX-trailer-start)
1885-
1886-(defvar TeX-header-end nil
1887- "Regular expression delimiting end of header in a TeX file.")
1888-
1889- (make-variable-buffer-local 'TeX-header-end)
1890-
1891-(defvar TeX-command-default nil
1892- "The default command for `TeX-command' in the current major mode.")
1893-
1894- (make-variable-buffer-local 'TeX-command-default)
1895-
1896-(put 'TeX-command-default 'safe-local-variable 'stringp)
1897-
1898-(defvar TeX-clean-default-intermediate-suffixes
1899- '("\\.aux" "\\.bbl" "\\.blg" "\\.brf" "\\.fot"
1900- "\\.glo" "\\.gls" "\\.idx" "\\.ilg" "\\.ind"
1901- "\\.lof" "\\.log" "\\.lot" "\\.nav" "\\.out"
1902- "\\.snm" "\\.toc" "\\.url" "\\.synctex\\.gz")
1903- "List of regexps matching suffixes of files to be cleaned.
1904-Used as a default in TeX, LaTeX and docTeX mode.")
1905-
1906-(defvar TeX-clean-default-output-suffixes
1907- '("\\.dvi" "\\.pdf" "\\.ps" "\\.xdv")
1908- "List of regexps matching suffixes of files to be cleaned.
1909-Used as a default in TeX, LaTeX and docTeX mode.")
1910-
1911-(defcustom TeX-clean-confirm t
1912- "If non-nil, ask before deleting files."
1913- :type 'boolean
1914- :group 'TeX-command)
1915-
1916-(autoload 'dired-mark-pop-up "dired")
1917-
1918-(defun TeX-clean (&optional arg)
1919- "Delete generated files associated with current master and region files.
1920-If prefix ARG is non-nil, not only remove intermediate but also
1921-output files."
1922- (interactive "P")
1923- (let* ((mode-prefix (TeX-mode-prefix))
1924- (suffixes (append (symbol-value
1925- (intern (concat mode-prefix
1926- "-clean-intermediate-suffixes")))
1927- (when arg
1928- (symbol-value
1929- (intern (concat mode-prefix
1930- "-clean-output-suffixes"))))))
1931- (master (TeX-active-master))
1932- (master-dir (file-name-directory master))
1933- (regexp (concat "\\("
1934- (file-name-nondirectory master) "\\|"
1935- (TeX-region-file nil t)
1936- "\\)"
1937- "\\("
1938- (mapconcat 'identity suffixes "\\|")
1939- "\\)\\'"
1940- "\\|" (TeX-region-file t t)))
1941- (files (when regexp
1942- (directory-files (or master-dir ".") nil regexp))))
1943- (if files
1944- (when (or (not TeX-clean-confirm)
1945- (condition-case nil
1946- (dired-mark-pop-up " *Deletions*" 'delete
1947- (if (> (length files) 1)
1948- files
1949- (cons t files))
1950- 'y-or-n-p "Delete files? ")
1951- (wrong-type-argument ; e.g. with Emacs 21
1952- (y-or-n-p (format "Delete %S? " (car files))))))
1953- (dolist (file files)
1954- (delete-file (concat master-dir file))))
1955- (message "No files to be deleted"))))
1956-
1957-
1958-;;; Master File
1959-
1960-(defcustom TeX-master t
1961- "*The master file associated with the current buffer.
1962-If the file being edited is actually included from another file, you
1963-can tell AUCTeX the name of the master file by setting this variable.
1964-If there are multiple levels of nesting, specify the top level file.
1965-
1966-If this variable is nil, AUCTeX will query you for the name.
1967-
1968-If the variable is t, AUCTeX will assume the file is a master file
1969-itself.
1970-
1971-If the variable is 'shared, AUCTeX will query for the name, but not
1972-change the file.
1973-
1974-If the variable is 'dwim, AUCTeX will try to avoid querying by
1975-attempting to `do what I mean'; and then change the file.
1976-
1977-It is suggested that you use the File Variables (see the info node in
1978-the Emacs manual) to set this variable permanently for each file."
1979- :group 'TeX-command
1980- :group 'TeX-parse
1981- :type '(choice (const :tag "Query" nil)
1982- (const :tag "This file" t)
1983- (const :tag "Shared" shared)
1984- (const :tag "Dwim" dwim)
1985- (string :format "%v")))
1986-(make-variable-buffer-local 'TeX-master)
1987-(put 'TeX-master 'safe-local-variable
1988- '(lambda (x)
1989- (or (stringp x)
1990- (member x (quote (t nil shared dwim))))))
1991-
1992-(defcustom TeX-one-master "\\.\\(texi?\\|dtx\\)$"
1993- "*Regular expression matching ordinary TeX files.
1994-
1995-You should set this variable to match the name of all files, where
1996-automatically adding a file variable with the name of the master file
1997-is a good idea. When AUCTeX adds the name of the master file as a
1998-file variable, it does not need to ask next time you edit the file.
1999-
2000-If you dislike AUCTeX automatically modifying your files, you can set
2001-this variable to \"<none>\"."
2002- :group 'TeX-command
2003- :type 'regexp)
2004-
2005-(defvar TeX-convert-master t
2006- "*If not nil, automatically convert ``Master:'' lines to file variables.
2007-This will be done when AUCTeX first try to use the master file.")
2008-
2009-;; Can be let-bound temporarily in order to inhibit the master file question
2010-;; by using its value instead in case `TeX-master' is nil or 'shared.
2011-(defvar TeX-transient-master nil)
2012-
2013-(defun TeX-dwim-master ()
2014- "Find a likely `TeX-master'."
2015- (let ((dir default-directory))
2016- (dolist (buf (buffer-list))
2017- (when (with-current-buffer buf
2018- (and (equal dir default-directory)
2019- (stringp TeX-master)))
2020- (return (with-current-buffer buf TeX-master))))))
2021-
2022-(defun TeX-master-file-ask ()
2023- "Ask for master file, set `TeX-master' and add local variables."
2024- (interactive)
2025- (if (TeX-local-master-p)
2026- (error "Master file already set")
2027- (let* ((default (TeX-dwim-master))
2028- (name (or (and (eq 'dwim TeX-master) default)
2029- (condition-case nil
2030- (read-file-name (format "Master file: (default %s) "
2031- (or default "this file"))
2032- nil default)
2033- (quit "<quit>")))))
2034- (cond ((string= name "<quit>")
2035- (setq TeX-master t))
2036- ((string= name default)
2037- (setq TeX-master default)
2038- (TeX-add-local-master))
2039- ((or
2040- ;; Default `read-file-name' proposes and buffer visits a file.
2041- (string= (expand-file-name name) (buffer-file-name))
2042- ;; Default of `read-file-name' and buffer does not visit a file.
2043- (string= name default-directory)
2044- ;; User typed <RET> in an empty minibuffer.
2045- (string= name ""))
2046- (setq TeX-master t)
2047- (TeX-add-local-master))
2048- (t
2049- (setq TeX-master (TeX-strip-extension (file-relative-name name)
2050- (list TeX-default-extension)
2051- 'path))
2052- (TeX-add-local-master))))))
2053-
2054-(defun TeX-master-file (&optional extension nondirectory ask)
2055- "Set and return the name of the master file for the current document.
2056-
2057-If optional argument EXTENSION is non-nil, add that file extension to
2058-the name. Special value t means use `TeX-default-extension'.
2059-
2060-If optional second argument NONDIRECTORY is non-nil, do not include
2061-the directory.
2062-
2063-If optional third argument ASK is non-nil, ask the user for the
2064-name of master file if it cannot be determined otherwise.
2065-
2066-Currently it will check for the presence of a ``Master:'' line in
2067-the beginning of the file, but that feature will be phased out."
2068- (interactive)
2069- (if (eq extension t)
2070- (setq extension TeX-default-extension))
2071- (let ((my-name (if (buffer-file-name)
2072- (TeX-strip-extension nil (list TeX-default-extension) t)
2073- "<none>")))
2074- (save-excursion
2075- (save-restriction
2076- (widen)
2077- (goto-char (point-min))
2078- (cond
2079- ((and TeX-transient-master
2080- (or (not TeX-master) (eq TeX-master 'shared)))
2081- (setq TeX-master TeX-transient-master))
2082- ;; Special value 't means it is own master (a free file).
2083- ((equal TeX-master my-name)
2084- (setq TeX-master t))
2085-
2086- ;; For files shared between many documents.
2087- ((and (eq 'shared TeX-master) ask)
2088- (setq TeX-master
2089- (let* ((default (TeX-dwim-master))
2090- (name (read-file-name
2091- (format "Master file: (default %s) "
2092- (or default "this file"))
2093- nil default)))
2094- (cond ((string= name default)
2095- default)
2096- ((or
2097- ;; Default `read-file-name' proposes and
2098- ;; buffer visits a file.
2099- (string= (expand-file-name name)
2100- (buffer-file-name))
2101- ;; Default of `read-file-name' and
2102- ;; buffer does not visit a file.
2103- (string= name default-directory)
2104- ;; User typed <RET> in an empty minibuffer.
2105- (string= name ""))
2106- t)
2107- (t
2108- (TeX-strip-extension
2109- name (list TeX-default-extension) 'path))))))
2110-
2111- ;; We might already know the name.
2112- ((or (eq TeX-master t) (stringp TeX-master)) TeX-master)
2113-
2114- ;; Support the ``Master:'' line (under protest!)
2115- ((re-search-forward
2116- "^%% *[Mm]aster:?[ \t]*\\([^ \t\n]+\\)" 500 t)
2117- (setq TeX-master
2118- (TeX-strip-extension (TeX-match-buffer 1)
2119- (list TeX-default-extension)))
2120- (if TeX-convert-master
2121- (progn
2122- (beginning-of-line)
2123- (kill-line 1)
2124- (TeX-add-local-master))))
2125-
2126- ;; Ask the user (but add it as a local variable).
2127- (ask (TeX-master-file-ask)))))
2128-
2129- (let ((name (if (stringp TeX-master)
2130- TeX-master
2131- my-name)))
2132-
2133- (if (TeX-match-extension name)
2134- ;; If it already has an extension...
2135- (if (equal extension TeX-default-extension)
2136- ;; Use instead of the default extension
2137- (setq extension nil)
2138- ;; Otherwise drop it.
2139- (setq name (TeX-strip-extension name))))
2140-
2141- ;; Remove directory if needed.
2142- (if nondirectory
2143- (setq name (file-name-nondirectory name)))
2144-
2145- (if extension
2146- (concat name "." extension)
2147- name))))
2148-
2149-(defun TeX-master-directory ()
2150- "Directory of master file."
2151- (file-name-as-directory
2152- (abbreviate-file-name
2153- (substitute-in-file-name
2154- (expand-file-name
2155- (let ((dir (file-name-directory (TeX-master-file))))
2156- (if dir (directory-file-name dir) "."))
2157- (and buffer-file-name
2158- (file-name-directory buffer-file-name)))))))
2159-
2160-(defun TeX-add-local-master ()
2161- "Add local variable for `TeX-master'."
2162- (when (and (buffer-file-name)
2163- (string-match TeX-one-master
2164- (file-name-nondirectory (buffer-file-name)))
2165- (not buffer-read-only))
2166- (goto-char (point-max))
2167- (if (re-search-backward (concat "^\\([^\n]+\\)Local " "Variables:")
2168- (- (point-max) 3000) t)
2169- (let ((prefix (TeX-match-buffer 1)))
2170- (re-search-forward (regexp-quote (concat prefix
2171- "End:")))
2172- (beginning-of-line 1)
2173- (insert prefix "TeX-master: " (prin1-to-string TeX-master) "\n"))
2174- (let ((comment-prefix (cond ((eq major-mode 'texinfo-mode) "@c ")
2175- ((eq major-mode 'doctex-mode) "% ")
2176- (t "%%% ")))
2177- (mode (concat (and (boundp 'japanese-TeX-mode) japanese-TeX-mode
2178- "japanese-")
2179- (substring (symbol-name major-mode) 0 -5))))
2180- (newline)
2181- (when (eq major-mode 'doctex-mode)
2182- (insert comment-prefix TeX-esc "endinput\n"))
2183- (insert
2184- comment-prefix "Local " "Variables: \n"
2185- comment-prefix "mode: " mode "\n"
2186- comment-prefix "TeX-master: " (prin1-to-string TeX-master) "\n"
2187- comment-prefix "End: \n")))))
2188-
2189-(defun TeX-local-master-p ()
2190- "Return non-nil if there is a `TeX-master' entry in local variables spec.
2191-Return nil otherwise."
2192- (save-excursion
2193- ;; XXX: Checking -*- line necessary as well?
2194- (goto-char (point-max))
2195- (search-backward "\n\^L" (max (- (point-max) 3000) (point-min)) 'move)
2196- (re-search-forward "^%+ *TeX-master:" nil t)))
2197-
2198-;;; Style Paths
2199-
2200-(defcustom TeX-style-global (expand-file-name "style" TeX-data-directory)
2201- "*Directory containing hand generated TeX information.
2202-
2203-These correspond to TeX macros shared by all users of a site."
2204- :group 'TeX-file
2205- :type 'directory)
2206-
2207-(defcustom TeX-auto-local "auto"
2208- "*Directory containing automatically generated TeX information.
2209-
2210-This correspond to TeX macros found in the current directory, and must
2211-be relative to that."
2212- :group 'TeX-file
2213- :type 'string)
2214-
2215-(defcustom TeX-style-local "style"
2216- "*Directory containing hand generated TeX information.
2217-
2218-These correspond to TeX macros found in the current directory, and must
2219-be relative to that."
2220- :group 'TeX-file
2221- :type 'string)
2222-
2223-(defun TeX-split-string (regexp string)
2224- "Return a list of strings.
2225-Given REGEXP the STRING is split into sections which in string was
2226-seperated by REGEXP.
2227-
2228-Examples:
2229-
2230- (TeX-split-string \"\:\" \"abc:def:ghi\")
2231- -> (\"abc\" \"def\" \"ghi\")
2232-
2233- (TeX-split-string \" +\" \"dvips -Plw -p3 -c4 testfile.dvi\")
2234-
2235- -> (\"dvips\" \"-Plw\" \"-p3\" \"-c4\" \"testfile.dvi\")
2236-
2237-If REGEXP is nil, or \"\", an error will occur."
2238-
2239- (let ((start 0) result match)
2240- (while (setq match (string-match regexp string start))
2241- (push (substring string start match) result)
2242- (setq start (match-end 0)))
2243- (push (substring string start) result)
2244- (nreverse result)))
2245-
2246-(defun TeX-parse-path (env)
2247- "Return a list if private TeX directories found in environment variable ENV."
2248- (let* ((value (getenv env))
2249- (entries (and value
2250- (TeX-split-string
2251- (if (string-match ";" value) ";" ":")
2252- value)))
2253- entry
2254- answers)
2255- (while entries
2256- (setq entry (car entries))
2257- (setq entries (cdr entries))
2258- (setq entry (file-name-as-directory
2259- (if (string-match "/?/?\\'" entry)
2260- (substring entry 0 (match-beginning 0))
2261- entry)))
2262- (or (not (file-name-absolute-p entry))
2263- (member entry (append '("/" "\\") TeX-macro-global))
2264- (setq answers (cons entry answers))))
2265- answers))
2266-
2267-(defun TeX-macro-global ()
2268- "Return directories containing the site's TeX macro and style files."
2269- (or (TeX-tree-expand '("$SYSTEXMF" "$TEXMFLOCAL" "$TEXMFMAIN" "$TEXMFDIST")
2270- "latex" '("/tex/" "/bibtex/bst/"))
2271- '("/usr/share/texmf/tex/" "/usr/share/texmf/bibtex/bst/")))
2272-
2273-(defun TeX-macro-private ()
2274- "Return directories containing the user's TeX macro and style files."
2275- (TeX-tree-expand '("$TEXMFHOME") "latex" '("/tex/" "/bibtex/bst/")))
2276-
2277-(defun TeX-tree-expand (trees program subdirs)
2278- "Return directories corresponding to the TeX trees TREES.
2279-This is done calling `kpsewhich' where PROGRAM is passed as the
2280-parameter for --progname. SUBDIRS are subdirectories which are
2281-appended to the directories of the TeX trees."
2282- (let (path-list path exit-status input-dir-list)
2283- (condition-case nil
2284- (catch 'success
2285- (dotimes (i (safe-length trees))
2286- (setq path (with-output-to-string
2287- (setq exit-status
2288- (call-process
2289- "kpsewhich" nil
2290- (list standard-output nil) nil
2291- "--progname" program
2292- "--expand-braces" (nth i trees)))))
2293- (if (zerop exit-status)
2294- (progn (add-to-list 'path-list path)
2295- (when (zerop i) (throw 'success nil)))
2296- (setq path (with-output-to-string
2297- (setq exit-status
2298- (call-process
2299- "kpsewhich" nil
2300- (list standard-output nil) nil
2301- "--progname" program
2302- "--expand-path" (nth i trees)))))
2303- (when (zerop exit-status) (add-to-list 'path-list path)))))
2304- (error nil))
2305- (dolist (elt path-list)
2306- (let ((separators (if (string-match "^[A-Za-z]:" elt)
2307- "[\n\r;]"
2308- "[\n\r:]")))
2309- (dolist (item (condition-case nil
2310- (split-string elt separators t)
2311- ;; COMPATIBILITY for XEmacs <= 21.4.15
2312- (error (delete "" (split-string elt separators)))))
2313- (when (string-match "^!+" item)
2314- (setq item (substring item (match-end 0) (length item))))
2315- (when (string-match "/+$" item)
2316- (setq item (substring item 0 (match-beginning 0))))
2317- (dolist (subdir subdirs)
2318- (when (file-exists-p (file-name-as-directory (concat item subdir)))
2319- (add-to-list 'input-dir-list (concat item subdir)))))))
2320- input-dir-list))
2321-
2322-(defcustom TeX-macro-global (TeX-macro-global)
2323- "Directories containing the site's TeX macro and style files."
2324- :group 'TeX-file
2325- :type '(repeat (directory :format "%v")))
2326-
2327-(defcustom TeX-macro-private (or (append (TeX-parse-path "TEXINPUTS")
2328- (TeX-parse-path "BIBINPUTS"))
2329- (TeX-macro-private))
2330- "Directories where you store your personal TeX macros."
2331- :group 'TeX-file
2332- :type '(repeat (file :format "%v")))
2333-
2334-(defcustom TeX-auto-private
2335- (list (expand-file-name TeX-auto-local
2336- (or (and (boundp 'user-emacs-directory)
2337- (concat user-emacs-directory "auctex/"))
2338- "~/.emacs.d/auctex/")))
2339- "List of directories containing automatically generated AUCTeX style files.
2340-
2341-These correspond to the personal TeX macros."
2342- :group 'TeX-file
2343- :type '(repeat (file :format "%v")))
2344-
2345-(if (stringp TeX-auto-private) ;Backward compatibility
2346- (setq TeX-auto-private (list TeX-auto-private)))
2347-
2348-(defcustom TeX-style-private
2349- (list (expand-file-name TeX-style-local
2350- (or (and (boundp 'user-emacs-directory)
2351- (concat user-emacs-directory "auctex/"))
2352- "~/.emacs.d/auctex/")))
2353- "List of directories containing hand-generated AUCTeX style files.
2354-
2355-These correspond to the personal TeX macros."
2356- :group 'TeX-file
2357- :type '(repeat (file :format "%v")))
2358-
2359-(if (stringp TeX-style-private) ;Backward compatibility
2360- (setq TeX-style-private (list TeX-style-private)))
2361-
2362-(defcustom TeX-style-path
2363- (let ((path))
2364- ;; Put directories in an order where the more local files can
2365- ;; override the more global ones.
2366- (mapcar (lambda (file) (when file (add-to-list 'path file t)))
2367- (append (list TeX-auto-global TeX-style-global)
2368- TeX-auto-private TeX-style-private
2369- (list TeX-auto-local TeX-style-local)))
2370- path)
2371- "List of directories to search for AUCTeX style files.
2372-Per default the list is built from the values of the variables
2373-`TeX-auto-global', `TeX-style-global', `TeX-auto-private',
2374-`TeX-style-private', `TeX-auto-local', and `TeX-style-local'."
2375- :group 'TeX-file
2376- :type '(repeat (file :format "%v")))
2377-
2378-(defcustom TeX-check-path
2379- (append (list ".") TeX-macro-private TeX-macro-global)
2380- "Directory path to search for dependencies.
2381-
2382-If nil, just check the current file.
2383-Used when checking if any files have changed."
2384- :group 'TeX-file
2385- :type '(repeat (file :format "%v")))
2386-
2387-;;; Style Files
2388-
2389-(defvar TeX-style-hook-list nil
2390- "List of TeX style hooks currently loaded.
2391-
2392-Each entry is a list where the first element is the name of the style,
2393-and the remaining elements are hooks to be run when that style is
2394-active.")
2395-
2396-(defcustom TeX-byte-compile nil
2397- "*Not nil means try to byte compile auto files before loading."
2398- :group 'TeX-parse
2399- :type 'boolean)
2400-
2401-(defun TeX-load-style (style)
2402- "Search for and load each definition for STYLE in `TeX-style-path'."
2403- (cond ((assoc style TeX-style-hook-list)) ; We already found it
2404- ((string-match "\\`\\(.+[/\\]\\)\\([^/\\]*\\)\\'" style) ;Complex path
2405- (let* ((dir (substring style (match-beginning 1) (match-end 1)))
2406- (style (substring style (match-beginning 2) (match-end 2)))
2407- (master-dir (if (stringp TeX-master)
2408- (file-name-directory
2409- (file-relative-name TeX-master))
2410- "./"))
2411- (TeX-style-path (append (list (expand-file-name
2412- TeX-auto-local dir)
2413- (expand-file-name
2414- TeX-auto-local master-dir)
2415- (expand-file-name
2416- TeX-style-local dir)
2417- (expand-file-name
2418- TeX-style-local master-dir))
2419- TeX-style-path)))
2420- (TeX-load-style style)))
2421- (t ;Relative path
2422- ;; Insert empty list to mark the fact that we have searched.
2423- (setq TeX-style-hook-list (cons (list style) TeX-style-hook-list))
2424- ;; Now check each element of the path
2425- (dolist (name TeX-style-path)
2426- (TeX-load-style-file (expand-file-name style name))))))
2427-
2428-(defun TeX-load-style-file (file)
2429- "Load FILE checking for a Lisp extensions."
2430- (let ((el (concat file ".el"))
2431- (elc (concat file ".elc")))
2432- (cond ((file-newer-than-file-p el elc)
2433- (if (file-readable-p el)
2434- (if (and TeX-byte-compile
2435- (file-writable-p elc)
2436- (save-excursion
2437- ;; `byte-compile-file' switches buffer in Emacs 20.3.
2438- (byte-compile-file el))
2439- (file-readable-p elc))
2440- (load-file elc)
2441- (load-file el))))
2442- ((file-readable-p elc)
2443- (load-file elc))
2444- ((file-readable-p el)
2445- (load-file el)))))
2446-
2447-(defun TeX-add-style-hook (style hook)
2448- "Give STYLE yet another HOOK to run."
2449- (let ((entry (assoc style TeX-style-hook-list)))
2450- (cond ((null entry)
2451- ;; New style, add entry.
2452- (setq TeX-style-hook-list (cons (list style hook)
2453- TeX-style-hook-list)))
2454- ((member hook entry)
2455- ;; Old style, hook already there, do nothing.
2456- nil)
2457- (t
2458- ;; Old style, new hook.
2459- (setcdr entry (cons hook (cdr entry)))))))
2460-
2461-(defun TeX-unload-style (style)
2462- "Forget that we once loaded STYLE."
2463- (cond ((null (assoc style TeX-style-hook-list)))
2464- ((equal (car (car TeX-style-hook-list)) style)
2465- (setq TeX-style-hook-list (cdr TeX-style-hook-list)))
2466- (t
2467- (let ((entry TeX-style-hook-list))
2468- (while (not (equal (car (car (cdr entry))) style))
2469- (setq entry (cdr entry)))
2470- (setcdr entry (cdr (cdr entry)))))))
2471-
2472-(defcustom TeX-virgin-style (if (and TeX-auto-global
2473- (file-directory-p TeX-auto-global))
2474- "virtex"
2475- "NoVirtexSymbols")
2476- "Style all documents use."
2477- :group 'TeX-parse
2478- :type 'string)
2479-
2480-(defvar TeX-active-styles nil
2481- "List of styles currently active in the document.")
2482- (make-variable-buffer-local 'TeX-active-styles)
2483-
2484-(defun TeX-run-style-hooks (&rest styles)
2485- "Run the TeX style hooks STYLES."
2486- (mapcar (lambda (style)
2487- ;; Avoid recursion.
2488- (unless (TeX-member style TeX-active-styles 'string-equal)
2489- (setq TeX-active-styles
2490- (cons style TeX-active-styles))
2491- (TeX-load-style style)
2492- (let ((default-directory default-directory))
2493- ;; Complex path.
2494- (when (string-match "\\`\\(.+[/\\]\\)\\([^/\\]*\\)\\'" style)
2495- ;; Set `default-directory' to directory of master
2496- ;; file since style files not stored in the fixed
2497- ;; style directories are usually located there.
2498- (setq default-directory (save-match-data
2499- (TeX-master-directory))
2500- style (substring style
2501- (match-beginning 2) (match-end 2))))
2502- (mapcar 'funcall
2503- (cdr-safe (assoc style TeX-style-hook-list))))))
2504- styles))
2505-
2506-(defcustom TeX-parse-self nil
2507- "Parse file after loading it if no style hook is found for it."
2508- :group 'TeX-parse
2509- :type 'boolean)
2510-
2511-(defvar TeX-style-hook-applied-p nil
2512- "Nil, unless the style specific hooks have been applied.")
2513- (make-variable-buffer-local 'TeX-style-hook-applied-p)
2514-
2515-(defvar TeX-update-style-hook nil
2516- "Hook run as soon as style specific hooks were applied.")
2517-
2518-(defun TeX-update-style (&optional force)
2519- "Run style specific hooks for the current document.
2520-
2521-Only do this if it has not been done before, or if optional argument
2522-FORCE is not nil."
2523- (unless (or (and (boundp 'TeX-auto-update)
2524- (eq TeX-auto-update 'BibTeX)) ; Not a real TeX buffer
2525- (and (not force)
2526- TeX-style-hook-applied-p))
2527- (setq TeX-style-hook-applied-p t)
2528- (message "Applying style hooks...")
2529- (TeX-run-style-hooks (TeX-strip-extension nil nil t))
2530- ;; Run parent style hooks if it has a single parent that isn't itself.
2531- (if (or (not (memq TeX-master '(nil t)))
2532- (and (buffer-file-name)
2533- (string-match TeX-one-master
2534- (file-name-nondirectory (buffer-file-name)))))
2535- (TeX-run-style-hooks (TeX-master-file)))
2536- (if (and TeX-parse-self
2537- (null (cdr-safe (assoc (TeX-strip-extension nil nil t)
2538- TeX-style-hook-list))))
2539- (TeX-auto-apply))
2540- (run-hooks 'TeX-update-style-hook)
2541- (message "Applying style hooks... done")))
2542-
2543-(defvar TeX-remove-style-hook nil
2544- "List of hooks to call when we remove the style specific information.")
2545- (make-variable-buffer-local 'TeX-remove-style-hook)
2546-
2547-(defun TeX-remove-style ()
2548- "Remove all style specific information."
2549- (setq TeX-style-hook-applied-p nil)
2550- (run-hooks 'TeX-remove-style-hook)
2551- (setq TeX-active-styles (list TeX-virgin-style)))
2552-
2553-(defun TeX-style-list ()
2554- "Return a list of all styles (subfiles) used by the current document."
2555- (TeX-update-style)
2556- TeX-active-styles)
2557-
2558-;;; Special Characters
2559-
2560-(defvar TeX-esc "\\" "The TeX escape character.")
2561- (make-variable-buffer-local 'TeX-esc)
2562-
2563-(defvar TeX-grop "{" "The TeX group opening character.")
2564- (make-variable-buffer-local 'TeX-grop)
2565-
2566-(defvar TeX-grcl "}" "The TeX group closing character.")
2567- (make-variable-buffer-local 'TeX-grcl)
2568-
2569-(defcustom plain-TeX-enable-toolbar t
2570- "Enable TeX tool bar in plain TeX mode."
2571- :group 'TeX-tool-bar
2572- :type 'boolean)
2573-
2574-(defun plain-TeX-maybe-install-toolbar ()
2575- "Conditionally install tool bar buttons for plain TeX mode.
2576-Install tool bar if `plain-TeX-enable-toolbar' is non-nil."
2577- (when plain-TeX-enable-toolbar
2578- ;; Defined in `tex-bar.el':
2579- (TeX-install-toolbar)))
2580-
2581-;;; Symbols
2582-
2583-;; Must be before keymaps.
2584-
2585-(defgroup TeX-macro nil
2586- "Support for TeX macros in AUCTeX."
2587- :prefix "TeX-"
2588- :group 'AUCTeX)
2589-
2590-(defcustom TeX-complete-word 'ispell-complete-word
2591- "*Function to call for completing non-macros in `tex-mode'."
2592- :group 'TeX-macro)
2593-
2594-(defvar TeX-complete-list nil
2595- "List of ways to complete the preceding text.
2596-
2597-Each entry is a list with the following elements:
2598-
2599-0. Regexp matching the preceding text.
2600-1. A number indicating the subgroup in the regexp containing the text.
2601-2. A function returning an alist of possible completions.
2602-3. Text to append after a succesful completion.
2603-
2604-Or alternatively:
2605-
2606-0. Regexp matching the preceding text.
2607-1. Function to do the actual completion.")
2608-
2609-(defun TeX-complete-symbol ()
2610- "Perform completion on TeX/LaTeX symbol preceding point."
2611- (interactive "*")
2612- (let ((list TeX-complete-list)
2613- entry)
2614- (while list
2615- (setq entry (car list)
2616- list (cdr list))
2617- (if (TeX-looking-at-backward (car entry) 250)
2618- (setq list nil)))
2619- (if (numberp (nth 1 entry))
2620- (let* ((sub (nth 1 entry))
2621- (close (nth 3 entry))
2622- (begin (match-beginning sub))
2623- (end (match-end sub))
2624- (pattern (TeX-match-buffer 0))
2625- (symbol (buffer-substring begin end))
2626- (list (funcall (nth 2 entry)))
2627- (completion (try-completion symbol list)))
2628- (cond ((eq completion t)
2629- (and close
2630- (not (looking-at (regexp-quote close)))
2631- (insert close)))
2632- ((null completion)
2633- (error "Can't find completion for \"%s\"" pattern))
2634- ((not (string-equal symbol completion))
2635- (delete-region begin end)
2636- (insert completion)
2637- (and close
2638- (eq (try-completion completion list) t)
2639- (not (looking-at (regexp-quote close)))
2640- (insert close)))
2641- (t
2642- (message "Making completion list...")
2643- (let ((list (all-completions symbol list nil)))
2644- (with-output-to-temp-buffer "*Completions*"
2645- (display-completion-list list)))
2646- (message "Making completion list...done"))))
2647- (funcall (nth 1 entry)))))
2648-
2649-(defcustom TeX-default-macro "ref"
2650- "*The default macro when creating new ones with `TeX-insert-macro'."
2651- :group 'TeX-macro
2652- :type 'string)
2653-
2654-(make-variable-buffer-local 'TeX-default-macro)
2655-
2656-(defcustom TeX-insert-braces t
2657- "*If non-nil, append a empty pair of braces after inserting a macro."
2658- :group 'TeX-macro
2659- :type 'boolean)
2660-
2661-(defcustom TeX-insert-macro-default-style 'show-optional-args
2662- "Specifies whether `TeX-insert-macro' will ask for all optional arguments.
2663-
2664-If set to the symbol `show-optional-args', `TeX-insert-macro' asks for
2665-optional arguments of TeX marcos. If set to `mandatory-args-only',
2666-`TeX-insert-macro' asks only for mandatory argument.
2667-
2668-When `TeX-insert-macro' is called with \\[universal-argument], it's the other
2669-way round.
2670-
2671-Note that for some macros, there are special mechanisms, see e.g.
2672-`LaTeX-includegraphics-options-alist'."
2673- :group 'TeX-macro
2674- :type '(choice (const mandatory-args-only)
2675- (const show-optional-args)))
2676-
2677-(defvar TeX-arg-opening-brace nil
2678- "String used as an opening brace for argument insertion.
2679-The variable will be temporarily let-bound with the necessary value.")
2680-
2681-(defvar TeX-arg-closing-brace nil
2682- "String used as a closing brace for argument insertion.
2683-The variable will be temporarily let-bound with the necessary value.")
2684-
2685-(defvar TeX-after-insert-macro-hook nil
2686- "A hook run after `TeX-insert-macro'.")
2687-
2688-(defvar TeX-macro-history nil)
2689-
2690-(defun TeX-insert-macro (symbol)
2691- "Insert TeX macro SYMBOL with completion.
2692-
2693-AUCTeX knows of some macros and may query for extra arguments, depending on
2694-the value of `TeX-insert-macro-default-style' and whether `TeX-insert-macro'
2695-is called with \\[universal-argument]."
2696- ;; When called with a prefix (C-u), only ask for mandatory arguments,
2697- ;; i.e. all optional arguments are skipped. See `TeX-parse-arguments' for
2698- ;; details. Note that this behavior may be changed in favor of a more
2699- ;; flexible solution in the future, therefore we don't document it at the
2700- ;; moment.
2701- (interactive (list (completing-read (concat "Macro (default "
2702- TeX-default-macro
2703- "): "
2704- TeX-esc)
2705- (TeX-symbol-list) nil nil nil
2706- 'TeX-macro-history)))
2707- (cond ((string-equal symbol "")
2708- (setq symbol TeX-default-macro))
2709- ((interactive-p)
2710- (setq TeX-default-macro symbol)))
2711- (TeX-parse-macro symbol (cdr-safe (assoc symbol (TeX-symbol-list))))
2712- (run-hooks 'TeX-after-insert-macro-hook))
2713-
2714-(defvar TeX-electric-macro-map
2715- (let ((map (make-sparse-keymap)))
2716- (set-keymap-parent map minibuffer-local-completion-map)
2717- (define-key map " " 'minibuffer-complete-and-exit)
2718- map))
2719-
2720-(defun TeX-electric-macro ()
2721- "Insert TeX macro with completion.
2722-
2723-AUCTeX knows of some macros, and may query for extra arguments.
2724-Space will complete and exit."
2725- (interactive)
2726- (cond ((eq (preceding-char) ?\\)
2727- (call-interactively 'self-insert-command))
2728- ((eq (preceding-char) ?.)
2729- (let ((TeX-default-macro " ")
2730- (minibuffer-local-completion-map TeX-electric-macro-map))
2731- (call-interactively 'TeX-insert-macro)))
2732- (t
2733- (let ((minibuffer-local-completion-map TeX-electric-macro-map))
2734- (call-interactively 'TeX-insert-macro)))))
2735-
2736-(defun TeX-parse-macro (symbol args)
2737- "How to parse TeX macros which takes one or more arguments.
2738-
2739-First argument SYMBOL is the name of the macro.
2740-
2741-If called with no additional arguments, insert macro with point
2742-inside braces. Otherwise, each argument of this function should
2743-match an argument to the TeX macro. What is done depend on the
2744-type of ARGS:
2745-
2746- string: Use the string as a prompt to prompt for the argument.
2747-
2748- number: Insert that many braces, leave point inside the first.
2749-
2750- nil: Insert empty braces.
2751-
2752- t: Insert empty braces, leave point between the braces.
2753-
2754- other symbols: Call the symbol as a function. You can define
2755- your own hook, or use one of the predefined argument hooks. If
2756- you add new hooks, you can assume that point is placed directly
2757- after the previous argument, or after the macro name if this is
2758- the first argument. Please leave point located after the
2759- argument you are inserting. If you want point to be located
2760- somewhere else after all hooks have been processed, set the value
2761- of `exit-mark'. It will point nowhere, until the argument hook
2762- set it. By convention, these hooks all start with `TeX-arg-'.
2763-
2764- list: If the car is a string, insert it as a prompt and the next
2765- element as initial input. Otherwise, call the car of the list
2766- with the remaining elements as arguments.
2767-
2768- vector: Optional argument. If it has more than one element,
2769- parse it as a list, otherwise parse the only element as above.
2770- Use square brackets instead of curly braces, and is not inserted
2771- on empty user input."
2772-
2773- (if (and (TeX-active-mark)
2774- (> (point) (mark)))
2775- (exchange-point-and-mark))
2776- (insert TeX-esc symbol)
2777- (let ((exit-mark (make-marker))
2778- (position (point)))
2779- (TeX-parse-arguments args)
2780- (cond ((marker-position exit-mark)
2781- (goto-char (marker-position exit-mark))
2782- (set-marker exit-mark nil))
2783- ((and TeX-insert-braces
2784- ;; Do not add braces for macros defined as `("foo" 0)'
2785- (not (and (= (safe-length args) 1)
2786- (numberp (car args))
2787- (= (car args) 0)))
2788- (equal position (point))
2789- (string-match "[a-zA-Z]+" symbol)
2790- (not (texmathp)))
2791- (insert TeX-grop)
2792- (if (TeX-active-mark)
2793- (progn
2794- (exchange-point-and-mark)
2795- (insert TeX-grcl))
2796- (insert TeX-grcl)
2797- (backward-char))))))
2798-
2799-(defun TeX-arg-string (optional &optional prompt initial-input)
2800- "Prompt for a string.
2801-
2802-If OPTIONAL is not nil then the PROMPT will start with ``(Optional) ''.
2803-INITIAL-INPUT is a string to insert before reading input."
2804- (TeX-argument-insert
2805- (if (and (not optional) (TeX-active-mark))
2806- (let ((TeX-argument (buffer-substring (point) (mark))))
2807- (delete-region (point) (mark))
2808- TeX-argument)
2809- (read-string (TeX-argument-prompt optional prompt "Text") initial-input))
2810- optional))
2811-
2812-(defun TeX-parse-arguments (args)
2813- "Parse TeX macro arguments ARGS.
2814-
2815-See `TeX-parse-macro' for details."
2816- (let ((last-optional-rejected nil)
2817- skip-opt)
2818- ;; Maybe get rid of all optional arguments. See `TeX-insert-macro' for
2819- ;; more comments. See `TeX-insert-macro-default-style'.
2820- (when (or (and (eq TeX-insert-macro-default-style 'show-optional-args)
2821- (equal current-prefix-arg '(4)))
2822- (and (eq TeX-insert-macro-default-style 'mandatory-args-only)
2823- (null (equal current-prefix-arg '(4)))))
2824- (while (vectorp (car args))
2825- (setq args (cdr args))))
2826-
2827- (while args
2828- (if (vectorp (car args))
2829- (unless last-optional-rejected
2830- (let ((TeX-arg-opening-brace LaTeX-optop)
2831- (TeX-arg-closing-brace LaTeX-optcl))
2832- (TeX-parse-argument t (if (equal (length (car args)) 1)
2833- (aref (car args) 0)
2834- (append (car args) nil)))))
2835- (let ((TeX-arg-opening-brace TeX-grop)
2836- (TeX-arg-closing-brace TeX-grcl))
2837- (setq last-optional-rejected nil)
2838- (TeX-parse-argument nil (car args))))
2839- (setq args (cdr args)))))
2840-
2841-(defun TeX-parse-argument (optional arg)
2842- "Depending on OPTIONAL, insert TeX macro argument ARG.
2843-If OPTIONAL is set, only insert if there is anything to insert, and
2844-then use square brackets instead of curly braces.
2845-
2846-See `TeX-parse-macro' for details."
2847- (let (insert-flag)
2848- (cond ((stringp arg)
2849- (TeX-arg-string optional arg)
2850- (setq insert-flag t))
2851- ((numberp arg)
2852- (unless (< arg 1)
2853- (TeX-parse-argument optional t)
2854- (while (> arg 1)
2855- (TeX-parse-argument optional nil)
2856- (setq arg (- arg 1)))))
2857- ((null arg)
2858- (insert TeX-arg-opening-brace)
2859- (when (and (not optional) (TeX-active-mark))
2860- (exchange-point-and-mark))
2861- (insert TeX-arg-closing-brace)
2862- (setq insert-flag t))
2863- ((eq arg t)
2864- (insert TeX-arg-opening-brace)
2865- (if (and (not optional) (TeX-active-mark))
2866- (progn
2867- (exchange-point-and-mark))
2868- (set-marker exit-mark (point)))
2869- (insert TeX-arg-closing-brace)
2870- (setq insert-flag t))
2871- ((symbolp arg)
2872- (funcall arg optional))
2873- ((listp arg)
2874- (let ((head (car arg))
2875- (tail (cdr arg)))
2876- (cond ((stringp head)
2877- (apply 'TeX-arg-string optional arg))
2878- ((symbolp head)
2879- (apply head optional tail))
2880- (t (error "Unknown list argument type %s"
2881- (prin1-to-string head))))))
2882- (t (error "Unknown argument type %s" (prin1-to-string arg))))
2883- (when (and insert-flag (not optional) (TeX-active-mark))
2884- (TeX-deactivate-mark))))
2885-
2886-(defun TeX-argument-insert (name optional &optional prefix)
2887- "Insert NAME surrounded by curly braces.
2888-
2889-If OPTIONAL, only insert it if not empty, and then use square brackets.
2890-If PREFIX is given, insert it before NAME."
2891- (if (and optional (string-equal name ""))
2892- (setq last-optional-rejected t)
2893- (insert TeX-arg-opening-brace)
2894- (if prefix
2895- (insert prefix))
2896- (if (and (string-equal name "")
2897- (null (marker-position exit-mark)))
2898- (set-marker exit-mark (point))
2899- (insert name))
2900- (insert TeX-arg-closing-brace)))
2901-
2902-(defun TeX-argument-prompt (optional prompt default &optional complete)
2903- "Return a argument prompt.
2904-
2905-If OPTIONAL is not nil then the prompt will start with ``(Optional) ''.
2906-
2907-PROMPT will be used if not nil, otherwise use DEFAULT.
2908-
2909-Unless optional argument COMPLETE is non-nil, ``: '' will be appended."
2910- (concat (if optional "(Optional) " "")
2911- (if prompt prompt default)
2912- (if complete "" ": ")))
2913-
2914-(defun TeX-string-divide-number-unit (string)
2915- "Divide number and unit in STRING.
2916-Return the number as car and unit as cdr."
2917- (if (string-match "[0-9]*\\.?[0-9]+" string)
2918- (list (substring string 0 (string-match "[^.0-9]" string))
2919- (substring string (if (string-match "[^.0-9]" string)
2920- (string-match "[^.0-9]" string)
2921- (length string))))
2922- (list "" string)))
2923-
2924-(defcustom TeX-default-unit-for-image "cm"
2925- "Default unit when prompting for an image size."
2926- :group 'TeX-macro
2927- :type '(choice (const "cm")
2928- (const "in")
2929- (const "\\linewidth")
2930- (string :tag "Other")))
2931-
2932-(defun TeX-arg-maybe (symbol list form)
2933- "Evaluates FORM, if SYMBOL is an element of LIST."
2934- (when (memq symbol list)
2935- (eval form)))
2936-
2937-(defun TeX-arg-free (optional &rest args)
2938- "Parse its arguments but use no braces when they are inserted."
2939- (let ((TeX-arg-opening-brace "")
2940- (TeX-arg-closing-brace ""))
2941- (if (equal (length args) 1)
2942- (TeX-parse-argument optional (car args))
2943- (TeX-parse-argument optional args))))
2944-
2945-(defun TeX-arg-literal (optional &rest args)
2946- "Insert its arguments ARGS into the buffer.
2947-Used for specifying extra syntax for a macro."
2948- ;; FIXME: What is the purpose of OPTIONAL here? -- rs
2949- (apply 'insert args))
2950-
2951-
2952-;;; Font Locking
2953-
2954-(defcustom TeX-install-font-lock 'font-latex-setup
2955- "Function to call to install font lock support.
2956-Choose `ignore' if you don't want AUCTeX to install support for font locking."
2957- :group 'TeX-misc
2958- :type '(radio (function-item font-latex-setup)
2959- (function-item tex-font-setup)
2960- (function-item ignore)
2961- (function :tag "Other")))
2962-
2963-;;; The Mode
2964-
2965-(defvar TeX-format-list
2966- '(("JLATEX" japanese-latex-mode
2967- "\\\\\\(documentstyle\\|documentclass\\)[^%\n]*{\\(j[s-]?\\|t\\)\
2968-\\(article\\|report\\|book\\|slides\\)")
2969- ("JTEX" japanese-plain-tex-mode
2970- "-- string likely in Japanese TeX --")
2971- ("AMSTEX" ams-tex-mode
2972- "\\\\document\\b")
2973- ("CONTEXT" context-mode
2974- "\\\\\\(start\\(text\\|tekst\\|proje[ck]t\\|proiect\\|\
2975-produ[ck]t\\|produs\\|environment\\|omgeving\\|umgebung\\|prostredi\\|mediu\\|\
2976-component\\|onderdeel\\|komponent[ea]\\|componenta\\)\
2977-\\|inizia\\(testo\\|progetto\\|prodotto\\|ambiente\\|componente\\)\
2978-\\)\\|%.*?interface=")
2979- ("LATEX" latex-mode
2980- "\\\\\\(begin\\|\\(?:sub\\)\\{0,2\\}section\\|chapter\\|documentstyle\\|\
2981-documentclass\\)\\b")
2982- ("TEX" plain-tex-mode "."))
2983- "*List of format packages to consider when choosing a TeX mode.
2984-
2985-A list with an entry for each format package available at the site.
2986-
2987-Each entry is a list with three elements.
2988-
2989-1. The name of the format package.
2990-2. The name of the major mode.
2991-3. A regexp typically matched in the beginning of the file.
2992-
2993-When entering `tex-mode', each regexp is tried in turn in order to find
2994-the major mode to be used.")
2995-
2996-(defcustom TeX-default-mode 'latex-mode
2997- "*Mode to enter for a new file when it can't be determined otherwise."
2998- :group 'TeX-misc
2999- :type '(radio (function-item latex-mode)
3000- (function-item plain-tex-mode)
3001- (function :tag "Other")))
3002-
3003-(defcustom TeX-force-default-mode nil
3004- "*If set to nil, try to infer the mode of the file from its content."
3005- :group 'TeX-misc
3006- :type 'boolean)
3007-
3008-;;;###autoload
3009-(defun TeX-tex-mode ()
3010- "Major mode in AUCTeX for editing TeX or LaTeX files.
3011-Tries to guess whether this file is for plain TeX or LaTeX.
3012-
3013-The algorithm is as follows:
3014-
3015- 1) if the file is empty or `TeX-force-default-mode' is not set to nil,
3016- `TeX-default-mode' is chosen
3017- 2) If \\documentstyle or \\begin{, \\section{, \\part{ or \\chapter{ is
3018- found, `latex-mode' is selected.
3019- 3) Otherwise, use `plain-tex-mode'"
3020- (interactive)
3021-
3022- (funcall (if (or (equal (buffer-size) 0)
3023- TeX-force-default-mode)
3024- TeX-default-mode
3025- (save-excursion
3026- (goto-char (point-min))
3027- (let ((comment-start-skip ;Used by TeX-in-comment
3028- (concat
3029- "\\(\\(^\\|[^\\\n]\\)\\("
3030- (regexp-quote TeX-esc)
3031- (regexp-quote TeX-esc)
3032- "\\)*\\)\\(%+ *\\)"))
3033- (entry TeX-format-list)
3034- answer)
3035- (while (and entry (not answer))
3036- (if (re-search-forward (nth 2 (car entry))
3037- 10000 t)
3038- (if (not (TeX-in-comment))
3039- (setq answer (nth 1 (car entry))))
3040- (setq entry (cdr entry))))
3041- (if answer
3042- answer
3043- TeX-default-mode))))))
3044-
3045-(defun VirTeX-common-initialization ()
3046- "Perform basic initialization."
3047- (kill-all-local-variables)
3048- (setq TeX-mode-p t)
3049- (setq TeX-output-extension (if TeX-PDF-mode "pdf" "dvi"))
3050- (setq local-abbrev-table text-mode-abbrev-table)
3051- (setq indent-tabs-mode nil)
3052-
3053- ;; Ispell support
3054- (make-local-variable 'ispell-parser)
3055- (setq ispell-parser 'tex)
3056- (make-local-variable 'ispell-tex-p)
3057- (setq ispell-tex-p t)
3058-
3059- ;; Redefine some standard variables
3060- (make-local-variable 'paragraph-start)
3061- (make-local-variable 'paragraph-separate)
3062- (make-local-variable 'comment-start)
3063- (setq comment-start "%")
3064- (make-local-variable 'comment-start-skip)
3065- (setq comment-start-skip
3066- (concat
3067- "\\(\\(^\\|[^\\\n]\\)\\("
3068- (regexp-quote TeX-esc)
3069- (regexp-quote TeX-esc)
3070- "\\)*\\)\\(%+[ \t]*\\)"))
3071- (set (make-local-variable 'comment-end-skip) "[ \t]*\\(\\s>\\|\n\\)")
3072- (set (make-local-variable 'comment-use-syntax) t)
3073- ;; `comment-padding' is defined here as an integer for compatibility
3074- ;; reasons because older Emacsen could not cope with a string.
3075- (make-local-variable 'comment-padding)
3076- (setq comment-padding 1)
3077- ;; Removed as commenting in (La)TeX is done with one `%' not two
3078- ;; (make-local-variable 'comment-add)
3079- ;; (setq comment-add 1) ;default to `%%' in comment-region
3080- (make-local-variable 'comment-indent-function)
3081- (setq comment-indent-function 'TeX-comment-indent)
3082- (make-local-variable 'comment-multi-line)
3083- (setq comment-multi-line nil)
3084- (make-local-variable 'compile-command)
3085- (unless (boundp 'compile-command)
3086- (setq compile-command "make"))
3087- (make-local-variable 'words-include-escapes)
3088- (setq words-include-escapes nil)
3089-
3090- ;; Make TAB stand out
3091- ;; (make-local-variable 'buffer-display-table)
3092- ;; (setq buffer-display-table (if standard-display-table
3093- ;; (copy-sequence standard-display-table)
3094- ;; (make-display-table)))
3095- ;; (aset buffer-display-table ?\t (apply 'vector (append "<TAB>" nil)))
3096-
3097- ;; Symbol completion.
3098- (make-local-variable 'TeX-complete-list)
3099- (setq TeX-complete-list
3100- (list (list "\\\\\\([a-zA-Z]*\\)"
3101- 1 'TeX-symbol-list (if TeX-insert-braces "{}"))
3102- (list "" TeX-complete-word)))
3103-
3104- (funcall TeX-install-font-lock)
3105-
3106- ;; We want this to be early in the list, so we do not add it before
3107- ;; we enter TeX mode the first time.
3108- (if (boundp 'local-write-file-hooks)
3109- (add-hook 'local-write-file-hooks 'TeX-safe-auto-write)
3110- (add-hook 'write-file-hooks 'TeX-safe-auto-write))
3111- (make-local-variable 'TeX-auto-update)
3112- (setq TeX-auto-update t)
3113-
3114- ;; Minor modes
3115- (when TeX-source-correlate-mode
3116- (TeX-source-correlate-mode 1))
3117-
3118- ;; Let `TeX-master-file' be called after a new file was opened and
3119- ;; call `TeX-update-style' on any file opened. (The addition to the
3120- ;; hook has to be made here because its local value will be deleted
3121- ;; by `kill-all-local-variables' if it is added e.g. in `tex-mode'.)
3122- ;;
3123- ;; `TeX-update-style' has to be called before
3124- ;; `global-font-lock-mode', which may also be specified in
3125- ;; `find-file-hooks', gets called. Otherwise style-based
3126- ;; fontification will break (in XEmacs). That means, `add-hook'
3127- ;; cannot be called with a non-nil value of the APPEND argument.
3128- ;;
3129- ;; `(TeX-master-file nil nil t)' has to be called *before*
3130- ;; `TeX-update-style' as the latter will call `TeX-master-file'
3131- ;; without the `ask' bit set.
3132- (when (and (featurep 'xemacs) (not (emacs-version>= 21 5)))
3133- (make-local-hook 'find-file-hooks))
3134- (add-hook 'find-file-hooks
3135- (lambda ()
3136- ;; Check if we are looking at a new or shared file.
3137- (when (or (not (file-exists-p (buffer-file-name)))
3138- (eq TeX-master 'shared))
3139- (TeX-master-file nil nil t))
3140- (TeX-update-style t)) nil t))
3141-
3142-;;; Plain TeX mode
3143-
3144-(defcustom plain-TeX-clean-intermediate-suffixes
3145- TeX-clean-default-intermediate-suffixes
3146- "List of regexps matching suffixes of intermediate files to be deleted.
3147-The regexps will be anchored at the end of the file name to be matched,
3148-i.e. you do _not_ have to cater for this yourself by adding \\\\' or $."
3149- :type '(repeat regexp)
3150- :group 'TeX-command)
3151-
3152-(defcustom plain-TeX-clean-output-suffixes TeX-clean-default-output-suffixes
3153- "List of regexps matching suffixes of output files to be deleted.
3154-The regexps will be anchored at the end of the file name to be matched,
3155-i.e. you do _not_ have to cater for this yourself by adding \\\\' or $."
3156- :type '(repeat regexp)
3157- :group 'TeX-command)
3158-
3159-(defcustom plain-TeX-mode-hook nil
3160- "A hook run in plain TeX mode buffers."
3161- :type 'hook
3162- :group 'TeX-misc)
3163-
3164-;;;###autoload
3165-(defun TeX-plain-tex-mode ()
3166- "Major mode in AUCTeX for editing plain TeX files.
3167-See info under AUCTeX for documentation.
3168-
3169-Special commands:
3170-\\{plain-TeX-mode-map}
3171-
3172-Entering `plain-tex-mode' calls the value of `text-mode-hook',
3173-then the value of `TeX-mode-hook', and then the value
3174-of plain-TeX-mode-hook."
3175- (interactive)
3176- (plain-TeX-common-initialization)
3177- (setq major-mode 'plain-tex-mode)
3178- (use-local-map plain-TeX-mode-map)
3179- (easy-menu-add plain-TeX-mode-menu plain-TeX-mode-map)
3180- (easy-menu-add plain-TeX-mode-command-menu plain-TeX-mode-map)
3181- (setq TeX-base-mode-name "TeX")
3182- (setq TeX-command-default "TeX")
3183- (setq TeX-sentinel-default-function 'TeX-TeX-sentinel)
3184- (add-hook 'tool-bar-mode-on-hook 'plain-TeX-maybe-install-toolbar nil t)
3185- (when (if (featurep 'xemacs)
3186- (featurep 'toolbar)
3187- (and (boundp 'tool-bar-mode) tool-bar-mode))
3188- (plain-TeX-maybe-install-toolbar))
3189- (TeX-run-mode-hooks 'text-mode-hook 'TeX-mode-hook 'plain-TeX-mode-hook)
3190- (TeX-set-mode-name))
3191-
3192-(defun plain-TeX-common-initialization ()
3193- "Common initialization for plain TeX like modes."
3194- (VirTeX-common-initialization)
3195- (set-syntax-table TeX-mode-syntax-table)
3196- (setq paragraph-start
3197- (concat
3198- "\\(^[ \t]*$"
3199- "\\|" (regexp-quote TeX-esc) "par\\|"
3200- "^[ \t]*"
3201- (regexp-quote TeX-esc)
3202- "\\("
3203- "begin\\|end\\|part\\|chapter\\|"
3204- "section\\|subsection\\|subsubsection\\|"
3205- "paragraph\\|include\\|includeonly\\|"
3206- "tableofcontents\\|appendix\\|label\\|caption\\|"
3207- "\\[\\|\\]" ; display math delimitors
3208- "\\)"
3209- "\\|"
3210- "^[ \t]*\\$\\$" ; display math delimitor
3211- "\\)" ))
3212- (setq paragraph-separate
3213- (concat
3214- "[ \t]*"
3215- "\\("
3216- (regexp-quote TeX-esc) "par\\|"
3217- "%\\|"
3218- "$\\|"
3219- "\\$\\$\\|"
3220- (regexp-quote TeX-esc)
3221- "\\("
3222- "begin\\|end\\|label\\|caption\\|part\\|chapter\\|"
3223- "section\\|subsection\\|subsubsection\\|"
3224- "paragraph\\|include\\|includeonly\\|"
3225- "tableofcontents\\|appendix\\|" (regexp-quote TeX-esc)
3226- "\\)"
3227- "\\)"))
3228- (setq TeX-header-end (regexp-quote "%**end of header"))
3229- (setq TeX-trailer-start (regexp-quote (concat TeX-esc "bye")))
3230- (TeX-run-style-hooks "TEX"))
3231-
3232-;;; Hilighting
3233-
3234-(if (boundp 'hilit-patterns-alist)
3235- (let ((latex-patterns (cdr-safe (assq 'latex-mode hilit-patterns-alist)))
3236- (plain-tex-patterns (cdr-safe (assq 'plain-tex-mode
3237- hilit-patterns-alist))))
3238- (if (and latex-patterns plain-tex-patterns)
3239- (setq hilit-patterns-alist
3240- (append (list (cons 'ams-tex-mode plain-tex-patterns))
3241- hilit-patterns-alist)))))
3242-
3243-;;; Parsing
3244-
3245-(defgroup TeX-parse nil
3246- "Parsing TeX files from AUCTeX."
3247- :group 'AUCTeX)
3248-
3249-(defvar TeX-auto-parser '((styles TeX-auto-file TeX-run-style-hooks)))
3250-;; Alist of parsed information.
3251-;; Each entry is a list with the following elements:
3252-;;
3253-;; 0. Name of information type.
3254-;; 1. Name of temporary variable used when parsing.
3255-;; 2. Name of function to add information to add to #3.
3256-;; 3. Name of variable holding buffer local information.
3257-;; 4. Name of variable indicating that #3 has changed.
3258-
3259-
3260-(defconst TeX-auto-parser-temporary 1)
3261-(defconst TeX-auto-parser-add 2)
3262-(defconst TeX-auto-parser-local 3)
3263-(defconst TeX-auto-parser-change 4)
3264-
3265-(defun TeX-auto-add-type (name prefix &optional plural)
3266- "Add information about NAME to the parser using PREFIX.
3267-
3268-Optional third argument PLURAL is the plural form of TYPE.
3269-By default just add an `s'.
3270-
3271-This function create a set of variables and functions to maintain a
3272-separate type of information in the parser."
3273- (let* ((names (or plural (concat name "s")))
3274- (tmp (intern (concat prefix "-auto-" name)))
3275- (add (intern (concat prefix "-add-" names)))
3276- (local (intern (concat prefix "-" name "-list")))
3277- (change (intern (concat prefix "-" name "-changed"))))
3278- (setq TeX-auto-parser
3279- (cons (list name tmp add local change) TeX-auto-parser))
3280- (set local nil)
3281- (make-variable-buffer-local local)
3282- (set change nil)
3283- (make-variable-buffer-local change)
3284- (fset add `(lambda (&rest entries)
3285- ,(concat "Add information about " (upcase name)
3286- " to the current buffer.
3287-Generated by `TeX-auto-add-type'.")
3288- (TeX-auto-add-information ,name entries)))
3289- (fset local `(lambda nil
3290- ,(concat "List of " names
3291- " active in the current buffer.
3292-Generated by `TeX-auto-add-type'.")
3293- (TeX-auto-list-information ,name)))
3294- (add-hook 'TeX-remove-style-hook
3295- `(lambda nil (setq ,(symbol-name local) nil)))))
3296-
3297-(defun TeX-auto-add-information (name entries)
3298- "For NAME in `TeX-auto-parser' add ENTRIES."
3299- (let* ((entry (assoc name TeX-auto-parser))
3300- (change (nth TeX-auto-parser-change entry))
3301- (change-value (symbol-value change))
3302- (local (nth TeX-auto-parser-local entry))
3303- (local-value (symbol-value local)))
3304- (if change-value
3305- (set local (cons entries local-value))
3306- (set change t)
3307- (set local (list entries local-value)))))
3308-
3309-(defun TeX-auto-list-information (name)
3310- "Return information in `TeX-auto-parser' about NAME."
3311- (TeX-update-style)
3312- (let* ((entry (assoc name TeX-auto-parser))
3313- (change (nth TeX-auto-parser-change entry))
3314- (change-value (symbol-value change))
3315- (local (nth TeX-auto-parser-local entry)))
3316- (if (not change-value)
3317- ()
3318- (set change nil)
3319- ;; Sort it
3320- (message "Sorting %s..." name)
3321- (set local
3322- (sort (mapcar 'TeX-listify (apply 'append (symbol-value local)))
3323- 'TeX-car-string-lessp))
3324- ;; Make it unique
3325- (message "Removing duplicates...")
3326- (let ((entry (symbol-value local)))
3327- (while (and entry (cdr entry))
3328- (let ((this (car entry))
3329- (next (car (cdr entry))))
3330- (if (not (string-equal (car this) (car next)))
3331- (setq entry (cdr entry))
3332- ;; We have two equal symbols. Use the one with
3333- ;; most arguments.
3334- (if (> (length next) (length this))
3335- (setcdr this (cdr next)))
3336- (setcdr entry (cdr (cdr entry)))))))
3337- (message "Removing duplicates... done"))
3338- (symbol-value local)))
3339-
3340-(TeX-auto-add-type "symbol" "TeX")
3341-
3342-(defvar TeX-auto-apply-hook nil
3343- "Hook run when a buffer is parsed and the information is applied.")
3344-
3345-(defun TeX-auto-apply ()
3346- "Parse and apply TeX information in the current buffer."
3347- (TeX-auto-parse)
3348- (run-hooks 'TeX-auto-apply-hook)
3349- (mapcar 'TeX-auto-apply-entry TeX-auto-parser))
3350-
3351-(defun TeX-auto-apply-entry (entry)
3352- "Apply the information in ENTRY in `TeX-auto-parser'."
3353- (let ((value (symbol-value (nth TeX-auto-parser-temporary entry)))
3354- (add (nth TeX-auto-parser-add entry)))
3355- (if value (apply add value))))
3356-
3357-(defun TeX-safe-auto-write ()
3358- "Call `TeX-auto-write' safely."
3359- (condition-case name
3360- (and (boundp 'TeX-auto-update)
3361- TeX-auto-update
3362- (TeX-auto-write))
3363- (error nil))
3364- ;; Continue with the other write file hooks.
3365- nil)
3366-
3367-(defcustom TeX-auto-save nil
3368- "*Automatically save style information when saving the buffer."
3369- :group 'TeX-parse
3370- :type 'boolean)
3371-
3372-(defcustom TeX-auto-untabify nil
3373- "*Automatically untabify when saving the buffer."
3374- :group 'TeX-parse
3375- :type 'boolean)
3376-
3377-(defun TeX-auto-write ()
3378- "Save all relevant TeX information from the current buffer."
3379- (if TeX-auto-untabify
3380- (untabify (point-min) (point-max)))
3381- (if (and TeX-auto-save TeX-auto-local)
3382- (let* ((file (expand-file-name
3383- (concat
3384- (file-name-as-directory TeX-auto-local)
3385- (TeX-strip-extension nil TeX-all-extensions t)
3386- ".el")
3387- (TeX-master-directory)))
3388- (dir (file-name-directory file)))
3389- ;; Create auto directory if possible.
3390- (if (not (file-exists-p dir))
3391- (condition-case name
3392- (make-directory dir)
3393- (error nil)))
3394- (if (file-writable-p file)
3395- (save-excursion
3396- (TeX-update-style)
3397- (TeX-auto-store file))
3398- (message "Can't write style information.")))))
3399-
3400-(defcustom TeX-macro-default (car-safe TeX-macro-private)
3401- "*Default directory to search for TeX macros."
3402- :group 'TeX-file
3403- :type 'directory)
3404-
3405-(defcustom TeX-auto-default (car-safe TeX-auto-private)
3406- "*Default directory to place automatically generated TeX information."
3407- :group 'TeX-file
3408- :type 'directory)
3409-
3410-;;;###autoload
3411-(defun TeX-auto-generate (tex auto)
3412- "Generate style file for TEX and store it in AUTO.
3413-If TEX is a directory, generate style files for all files in the directory."
3414- (interactive (list (setq TeX-macro-default
3415- (expand-file-name (read-file-name
3416- "TeX file or directory: "
3417- TeX-macro-default
3418- TeX-macro-default 'confirm)))
3419- (setq TeX-auto-default
3420- (expand-file-name (read-file-name
3421- "AUTO lisp directory: "
3422- TeX-auto-default
3423- TeX-auto-default 'confirm)))))
3424- (cond ((not (file-readable-p tex)))
3425- ((string-match TeX-ignore-file tex))
3426- ((file-directory-p tex)
3427- (let ((files (directory-files (expand-file-name tex)))
3428- (default-directory (file-name-as-directory
3429- (expand-file-name tex)))
3430- (TeX-file-recurse (cond ((symbolp TeX-file-recurse)
3431- TeX-file-recurse)
3432- ((zerop TeX-file-recurse)
3433- nil)
3434- ((1- TeX-file-recurse)))))
3435- (mapcar (lambda (file)
3436- (if (or TeX-file-recurse
3437- (not (file-directory-p file)))
3438- (TeX-auto-generate file auto)))
3439- files)))
3440- ((not (file-newer-than-file-p
3441- tex
3442- (concat (file-name-as-directory auto)
3443- (TeX-strip-extension tex TeX-all-extensions t)
3444- ".el"))))
3445- ((TeX-match-extension tex (append TeX-file-extensions
3446- BibTeX-file-extensions))
3447- (save-excursion
3448- (set-buffer (let (enable-local-eval)
3449- (find-file-noselect tex)))
3450- (message "Parsing %s..." tex)
3451- (TeX-auto-store (concat (file-name-as-directory auto)
3452- (TeX-strip-extension tex
3453- TeX-all-extensions
3454- t)
3455- ".el"))
3456- (kill-buffer (current-buffer))
3457- (message "Parsing %s... done" tex)))))
3458-
3459-;;;###autoload
3460-(defun TeX-auto-generate-global ()
3461- "Create global auto directory for global TeX macro definitions."
3462- (interactive)
3463- (unless (file-directory-p TeX-auto-global)
3464- (make-directory TeX-auto-global))
3465- (let ((TeX-file-extensions '("cls" "sty"))
3466- (BibTeX-file-extensions nil))
3467- (mapc (lambda (macro) (TeX-auto-generate macro TeX-auto-global))
3468- TeX-macro-global))
3469- (byte-recompile-directory TeX-auto-global 0))
3470-
3471-(defun TeX-auto-store (file)
3472- "Extract information for AUCTeX from current buffer and store it in FILE."
3473- (TeX-auto-parse)
3474-
3475- (if (member nil (mapcar 'TeX-auto-entry-clear-p TeX-auto-parser))
3476- (let ((style (TeX-strip-extension nil TeX-all-extensions t)))
3477- (TeX-unload-style style)
3478- (save-excursion
3479- (set-buffer (generate-new-buffer file))
3480- (erase-buffer)
3481- (insert "(TeX-add-style-hook \"" style "\"\n"
3482- " (lambda ()")
3483- (mapc (lambda (el) (TeX-auto-insert el style))
3484- TeX-auto-parser)
3485- (insert "))\n\n")
3486- (write-region (point-min) (point-max) file nil 'silent)
3487- (kill-buffer (current-buffer))))
3488- (if (file-exists-p (concat file "c"))
3489- (delete-file (concat file "c")))
3490- (if (file-exists-p file)
3491- (delete-file file))))
3492-
3493-(defun TeX-auto-entry-clear-p (entry)
3494- "Check if the temporary for `TeX-auto-parser' entry ENTRY is clear."
3495- ;; FIXME: This doc-string isn't clear to me. -- rs
3496- (null (symbol-value (nth TeX-auto-parser-temporary entry))))
3497-
3498-(defun TeX-auto-insert (entry &optional skip)
3499- "Insert code to initialize ENTRY from `TeX-auto-parser'.
3500-
3501-If SKIP is not-nil, don't insert code for SKIP."
3502- (let ((name (symbol-name (nth TeX-auto-parser-add entry)))
3503- (list (symbol-value (nth TeX-auto-parser-temporary entry))))
3504- (unless (null list)
3505- (insert "\n (" name)
3506- (dolist (el list)
3507- (cond ((and (stringp el) (not (string= el skip)))
3508- (insert "\n ")
3509- (insert (prin1-to-string el)))
3510- ((not (stringp el))
3511- (insert "\n ")
3512- (insert "'" (prin1-to-string el)))))
3513- (insert ")"))))
3514-
3515-(defvar TeX-auto-ignore
3516- '("csname" "filedate" "fileversion" "docdate" "next" "labelitemi"
3517- "labelitemii" "labelitemiii" "labelitemiv" "labelitemv"
3518- "labelenumi" "labelenumii" "labelenumiii" "labelenumiv"
3519- "labelenumv" "theenumi" "theenumii" "theenumiii" "theenumiv"
3520- "theenumv" "document" "par" "do" "expandafter")
3521- "List of symbols to ignore when scanning a TeX style file.")
3522-
3523-(defun TeX-auto-add-regexp (regexp)
3524- "Add REGEXP to `TeX-auto-regexp-list' if not already a member."
3525- (if (symbolp TeX-auto-regexp-list)
3526- (setq TeX-auto-regexp-list (symbol-value TeX-auto-regexp-list)))
3527- (or (memq regexp TeX-auto-regexp-list)
3528- (setq TeX-auto-regexp-list (cons regexp TeX-auto-regexp-list))))
3529-
3530-(defvar TeX-auto-empty-regexp-list
3531- '(("<IMPOSSIBLE>\\(\\'\\`\\)" 1 ignore))
3532- "List of regular expressions guaranteed to match nothing.")
3533-
3534-(defvar TeX-token-char
3535- (if (featurep 'mule)
3536- "\\(?:[a-zA-Z]\\|\\cj\\)"
3537- "[a-zA-Z]")
3538- "Regexp matching a character in a TeX macro.
3539-
3540-Please use a shy group if you use a grouping construct, because
3541-the functions/variables which use `TeX-token-char' expect not to
3542-alter the numbering of any ordinary, non-shy groups.")
3543-
3544-(defvar plain-TeX-auto-regexp-list
3545- (let ((token TeX-token-char))
3546- `((,(concat "\\\\def\\\\\\(" token "+\\)[^a-zA-Z@]") 1 TeX-auto-symbol-check)
3547- (,(concat "\\\\let\\\\\\(" token "+\\)[^a-zA-Z@]") 1 TeX-auto-symbol-check)
3548- (,(concat "\\\\font\\\\\\(" token "+\\)[^a-zA-Z@]") 1 TeX-auto-symbol)
3549- (,(concat "\\\\chardef\\\\\\(" token "+\\)[^a-zA-Z@]") 1 TeX-auto-symbol)
3550- (,(concat "\\\\new\\(?:count\\|dimen\\|muskip\\|skip\\)\\\\\\(" token "+\\)[^a-zA-Z@]")
3551- 1 TeX-auto-symbol)
3552- (,(concat "\\\\newfont{?\\\\\\(" token "+\\)}?") 1 TeX-auto-symbol)
3553- (,(concat "\\\\typein\\[\\\\\\(" token "+\\)\\]") 1 TeX-auto-symbol)
3554- ("\\\\input +\\(\\.*[^#%\\\\\\.\n\r]+\\)\\(\\.[^#%\\\\\\.\n\r]+\\)?"
3555- 1 TeX-auto-file)
3556- (,(concat "\\\\mathchardef\\\\\\(" token "+\\)[^a-zA-Z@]") 1 TeX-auto-symbol)))
3557- "List of regular expression matching common LaTeX macro definitions.")
3558-
3559-(defvar TeX-auto-full-regexp-list plain-TeX-auto-regexp-list
3560- "Full list of regular expression matching TeX macro definitions.")
3561-
3562-(defvar TeX-auto-prepare-hook nil
3563- "List of hooks to be called before parsing a TeX file.")
3564-
3565-(defvar TeX-auto-cleanup-hook nil
3566- "List of hooks to be called after parsing a TeX file.")
3567-
3568-(defcustom TeX-auto-parse-length 999999
3569- "Maximal length of TeX file (in characters) that will be parsed."
3570- :group 'TeX-parse
3571- :type 'integer)
3572- (make-variable-buffer-local 'TeX-auto-parse-length)
3573-
3574-(defcustom TeX-auto-x-parse-length 0
3575- "Maximum length of TeX file that will be parsed additionally.
3576-Use `TeX-auto-x-regexp-list' for parsing the region between
3577-`TeX-auto-parse-length' and this value."
3578- :group 'TeX-parse
3579- :type 'integer)
3580- (make-variable-buffer-local 'TeX-auto-x-parse-length)
3581-
3582-(defcustom TeX-auto-x-regexp-list 'LaTeX-auto-label-regexp-list
3583- "List of regular expressions used for additional parsing.
3584-See `TeX-auto-x-parse-length'."
3585- :type '(radio (variable-item TeX-auto-empty-regexp-list)
3586- (variable-item TeX-auto-full-regexp-list)
3587- (variable-item plain-TeX-auto-regexp-list)
3588- (variable-item LaTeX-auto-minimal-regexp-list)
3589- (variable-item LaTeX-auto-label-regexp-list)
3590- (variable-item LaTeX-auto-regexp-list)
3591- (symbol :tag "Other")
3592- (repeat :tag "Specify"
3593- (group (regexp :tag "Match")
3594- (sexp :tag "Groups")
3595- symbol)))
3596- :group 'TeX-parse)
3597- (make-variable-buffer-local 'TeX-auto-x-regexp-list)
3598-
3599-(defun TeX-regexp-group-count (regexp)
3600- "Return number of groups in a REGEXP. This is not foolproof:
3601-you should not use something like `[\\(]' for a character range."
3602- (let (start (n 0))
3603- (while (string-match "\\(\\`\\|[^\\]\\)\\(\\\\\\\\\\)*\\\\([^?]"
3604- regexp start)
3605- (setq start (- (match-end 0) 2)
3606- n (1+ n)))
3607- n))
3608-
3609-(defun TeX-auto-parse-region (regexp-list beg end)
3610- "Parse TeX information according to REGEXP-LIST between BEG and END."
3611- (if (symbolp regexp-list)
3612- (setq regexp-list (and (boundp regexp-list) (symbol-value regexp-list))))
3613- (if regexp-list
3614- ;; Extract the information.
3615- (let* (groups
3616- (count 1)
3617- (regexp (concat "\\("
3618- (mapconcat
3619- (lambda(x)
3620- (push (cons count x) groups)
3621- (setq count
3622- (+ 1 count
3623- (TeX-regexp-group-count (car x))))
3624- (car x))
3625- regexp-list "\\)\\|\\(")
3626- "\\)"))
3627- syms
3628- lst)
3629- (setq count 0)
3630- (goto-char (if end (min end (point-max)) (point-max)))
3631- (while (re-search-backward regexp beg t)
3632- (let* ((entry (cdr (TeX-member nil groups
3633- (lambda (a b)
3634- (match-beginning (car b))))))
3635- (symbol (nth 2 entry))
3636- (match (nth 1 entry)))
3637- (unless (TeX-in-comment)
3638- (looking-at (nth 0 entry))
3639- (if (fboundp symbol)
3640- (funcall symbol match)
3641- (puthash (if (listp match)
3642- (mapcar #'TeX-match-buffer match)
3643- (TeX-match-buffer match))
3644- (setq count (1- count))
3645- (cdr (or (assq symbol syms)
3646- (car (push
3647- (cons symbol
3648- (make-hash-table :test 'equal))
3649- syms)))))))))
3650- (setq count 0)
3651- (dolist (symbol syms)
3652- (setq lst (symbol-value (car symbol)))
3653- (while lst
3654- (puthash (pop lst)
3655- (setq count (1+ count))
3656- (cdr symbol)))
3657- (maphash (lambda (key value)
3658- (push (cons value key) lst))
3659- (cdr symbol))
3660- (clrhash (cdr symbol))
3661- (set (car symbol) (mapcar #'cdr (sort lst #'car-less-than-car)))))))
3662-
3663-
3664-(defun TeX-auto-parse ()
3665- "Parse TeX information in current buffer.
3666-
3667-Call the functions in `TeX-auto-prepare-hook' before parsing, and the
3668-functions in `TeX-auto-cleanup-hook' after parsing."
3669-
3670- (let ((case-fold-search nil))
3671-
3672- (mapc 'TeX-auto-clear-entry TeX-auto-parser)
3673- (run-hooks 'TeX-auto-prepare-hook)
3674-
3675- (save-excursion
3676- (and (> TeX-auto-x-parse-length TeX-auto-parse-length)
3677- (> (point-max) TeX-auto-parse-length)
3678- (TeX-auto-parse-region TeX-auto-x-regexp-list
3679- TeX-auto-parse-length
3680- TeX-auto-x-parse-length))
3681- (TeX-auto-parse-region TeX-auto-regexp-list
3682- nil TeX-auto-parse-length))
3683-
3684- ;; Cleanup ignored symbols.
3685-
3686- ;; NOTE: This is O(N M) where it could be O(N log N + M log M) if we
3687- ;; sorted the lists first.
3688- (while (member (car TeX-auto-symbol) TeX-auto-ignore)
3689- (setq TeX-auto-symbol (cdr TeX-auto-symbol)))
3690- (let ((list TeX-auto-symbol))
3691- (while (and list (cdr list))
3692- (if (member (car (cdr list)) TeX-auto-ignore)
3693- (setcdr list (cdr (cdr list)))
3694- (setq list (cdr list)))))
3695-
3696- (run-hooks 'TeX-auto-cleanup-hook)))
3697-
3698-(defun TeX-auto-clear-entry (entry)
3699- "Set the temporary variable in ENTRY to nil."
3700- (set (nth TeX-auto-parser-temporary entry) nil))
3701-
3702-(defvar LaTeX-auto-end-symbol nil)
3703-
3704-(defun TeX-auto-symbol-check (match)
3705- "Add MATCH to TeX-auto-symbols.
3706-Check for potential LaTeX environments."
3707- (let ((symbol (if (listp match)
3708- (mapcar 'TeX-match-buffer match)
3709- (TeX-match-buffer match))))
3710- (if (and (stringp symbol)
3711- (string-match "^end\\(.+\\)$" symbol))
3712- (add-to-list 'LaTeX-auto-end-symbol
3713- (substring symbol (match-beginning 1) (match-end 1)))
3714- (if (listp symbol)
3715- (dolist (elt symbol)
3716- (add-to-list 'TeX-auto-symbol elt))
3717- (add-to-list 'TeX-auto-symbol symbol)))))
3718-
3719-;;; Utilities
3720-;;
3721-;; Some of these functions has little to do with TeX, but nonetheless we
3722-;; should use the "TeX-" prefix to avoid name clashes.
3723-
3724-(defcustom TeX-auto-regexp-list 'TeX-auto-full-regexp-list
3725- "*List of regular expressions used for parsing the current file."
3726- :type '(radio (variable-item TeX-auto-empty-regexp-list)
3727- (variable-item TeX-auto-full-regexp-list)
3728- (variable-item plain-TeX-auto-regexp-list)
3729- (variable-item LaTeX-auto-minimal-regexp-list)
3730- (variable-item LaTeX-auto-label-regexp-list)
3731- (variable-item LaTeX-auto-regexp-list)
3732- (symbol :tag "Other")
3733- (repeat :tag "Specify"
3734- (group (regexp :tag "Match")
3735- (sexp :tag "Groups")
3736- symbol)))
3737- :group 'TeX-parse)
3738- (make-variable-buffer-local 'TeX-auto-regexp-list)
3739-
3740-(defgroup TeX-file-extension nil
3741- "File extensions recognized by AUCTeX."
3742- :group 'TeX-file)
3743-
3744-(defcustom TeX-file-extensions '("tex" "sty" "cls" "ltx" "texi" "texinfo" "dtx")
3745- "*File extensions used by manually generated TeX files."
3746- :group 'TeX-file-extension
3747- :type '(repeat (string :format "%v")))
3748-
3749-(defcustom TeX-all-extensions '("[^.\n]+")
3750- "All possible file extensions."
3751- :group 'TeX-file-extension
3752- :type '(repeat (regexp :format "%v")))
3753-
3754-(defcustom TeX-default-extension "tex"
3755- "*Default extension for TeX files."
3756- :group 'TeX-file-extension
3757- :type 'string)
3758-
3759- (make-variable-buffer-local 'TeX-default-extension)
3760-
3761-(defcustom docTeX-default-extension "dtx"
3762- "*Default extension for docTeX files."
3763- :group 'TeX-file-extension
3764- :type 'string)
3765-
3766-(defvar TeX-output-extension nil
3767- "Extension of TeX output file.
3768-This is either a string or a list with
3769-a string as element. Its value is obtained from `TeX-command-output-list'.
3770-Access to the value should be through the function `TeX-output-extension'.")
3771-
3772- (make-variable-buffer-local 'TeX-output-extension)
3773-
3774-(defcustom BibTeX-file-extensions '("bib")
3775- "Valid file extensions for BibTeX files."
3776- :group 'TeX-file-extension
3777- :type '(repeat (string :format "%v")))
3778-
3779-(defcustom BibTeX-style-extensions '("bst")
3780- "Valid file extensions for BibTeX styles."
3781- :group 'TeX-file-extension
3782- :type '(repeat (string :format "%v")))
3783-
3784-(defcustom TeX-ignore-file "\\(^\\|[/\\]\\)\\(\\.\\|\\.\\.\\|RCS\\|SCCS\\|CVS\\|babel\\..*\\)$"
3785- "Regular expression matching file names to ignore.
3786-
3787-These files or directories will not be considered when searching for
3788-TeX files in a directory."
3789- :group 'TeX-parse
3790- :type 'regexp)
3791-
3792-(defcustom TeX-file-recurse t
3793- "*Whether to search TeX directories recursively.
3794-nil means do not recurse, a positive integer means go that far deep in the
3795-directory hierarchy, t means recurse indefinitely."
3796- :group 'TeX-parse
3797- :type '(choice (const :tag "On" t)
3798- (const :tag "Off" nil)
3799- (integer :tag "Depth" :value 1)))
3800-
3801-(defun TeX-match-extension (file &optional extensions)
3802- "Return non-nil if FILE has one of EXTENSIONS.
3803-
3804-If EXTENSIONS is not specified or nil, the value of
3805-`TeX-file-extensions' is used instead."
3806-
3807- (if (null extensions)
3808- (setq extensions TeX-file-extensions))
3809-
3810- (let ((regexp (concat "\\.\\("
3811- (mapconcat 'identity extensions "\\|")
3812- "\\)$"))
3813- (case-fold-search t))
3814- (string-match regexp file)))
3815-
3816-(defun TeX-strip-extension (&optional string extensions nodir nostrip)
3817- "Return STRING without any trailing extension in EXTENSIONS.
3818-If NODIR is t, also remove directory part of STRING.
3819-If NODIR is `path', remove directory part of STRING if it is equal to
3820-the current directory, `TeX-macro-private' or `TeX-macro-global'.
3821-If NOSTRIP is set, do not remove extension after all.
3822-STRING defaults to the name of the current buffer.
3823-EXTENSIONS defaults to `TeX-file-extensions'."
3824-
3825- (if (null string)
3826- (setq string (or (buffer-file-name) "<none>")))
3827-
3828- (if (null extensions)
3829- (setq extensions TeX-file-extensions))
3830-
3831- (let* ((strip (if (and (not nostrip)
3832- (TeX-match-extension string extensions))
3833- (substring string 0 (match-beginning 0))
3834- string))
3835- (dir (expand-file-name (or (file-name-directory strip) "./"))))
3836- (if (or (eq nodir t)
3837- (string-equal dir (expand-file-name "./"))
3838- (member dir TeX-macro-global)
3839- (member dir TeX-macro-private))
3840- (file-name-nondirectory strip)
3841- strip)))
3842-
3843-(defcustom TeX-kpathsea-path-delimiter t
3844- "Path delimiter for kpathsea output.
3845-t means autodetect, nil means kpathsea is disabled."
3846- :group 'TeX-file
3847- :type '(choice (const ":")
3848- (const ";")
3849- (const :tag "Autodetect" t)
3850- (const :tag "Off" nil)))
3851-
3852-(defcustom TeX-kpathsea-format-alist
3853- '(("tex" "${TEXINPUTS.latex}" TeX-file-extensions)
3854- ("sty" "${TEXINPUTS.latex}" '("sty"))
3855- ("dvi" "${TEXDOCS}" '("dvi" "pdf" "ps" "txt" "html"
3856- "dvi.gz" "pdf.gz" "ps.gz" "txt.gz" "html.gz"
3857- "dvi.bz2" "pdf.bz2" "ps.bz2" "txt.bz2" "html.bz2"))
3858- ("eps" "${TEXINPUTS}" LaTeX-includegraphics-extensions)
3859- ("pdf" "${TEXINPUTS}" LaTeX-includegraphics-extensions)
3860- ("png" "${TEXINPUTS}" LaTeX-includegraphics-extensions)
3861- ("jpg" "${TEXINPUTS}" LaTeX-includegraphics-extensions)
3862- ("jpeg" "${TEXINPUTS}" LaTeX-includegraphics-extensions)
3863- ("bib" "$BIBINPUTS" BibTeX-file-extensions)
3864- ("bst" "$BSTINPUTS" BibTeX-style-extensions))
3865- "Formats to search for expansion using kpathsea.
3866-The key of the alist represents the name of the format. The
3867-first element of the cdr of the alist is string to expand by the
3868-respective kpathsea program and the second element is a list of
3869-file extensions to match."
3870- :group 'TeX-file
3871- :type '(alist :key-type string :value-type (group string sexp)))
3872-
3873-;; FIXME: Despite the first parameter named `extensions',
3874-;; `TeX-search-files-kpathsea' basically treats this as a format
3875-;; specifier. Only the first element in the respective list will be
3876-;; used to determine the search paths and file extensions with the
3877-;; help of `TeX-kpathsea-format-alist'. Out of these differences
3878-;; arises a need to unify the behavior of `TeX-search-files' and
3879-;; `TeX-search-files-kpathsea' and their treatment of parameters.
3880-;; Additionally `TeX-search-files-kpathsea' should be made more
3881-;; general to work with other platforms and TeX systems as well.
3882-(defun TeX-search-files-kpathsea (extensions nodir strip)
3883- "The kpathsea-enabled version of `TeX-search-files'.
3884-Except for DIRECTORIES (a kpathsea string), the arguments for
3885-EXTENSIONS, NODIR and STRIP are explained there."
3886- (and TeX-kpathsea-path-delimiter
3887- (catch 'no-kpathsea
3888- (let* ((format-spec (assoc (car extensions)
3889- TeX-kpathsea-format-alist))
3890- (dirs (with-output-to-string
3891- (unless (zerop
3892- (call-process
3893- "kpsewhich" nil (list standard-output nil)
3894- nil
3895- (concat
3896- "-expand-path="
3897- (nth 1 format-spec))))
3898- (if (eq TeX-kpathsea-path-delimiter t)
3899- (throw 'no-kpathsea
3900- (setq TeX-kpathsea-path-delimiter nil))
3901- (error "kpsewhich error")))))
3902- result)
3903- (when (eq TeX-kpathsea-path-delimiter t)
3904- (setq TeX-kpathsea-path-delimiter
3905- (cond ((string-match ";" dirs)
3906- ";")
3907- ((string-match ":" dirs)
3908- ":"))))
3909- (unless TeX-kpathsea-path-delimiter
3910- (throw 'no-kpathsea nil))
3911- (setq dirs (split-string dirs (concat "[\n\r"
3912- TeX-kpathsea-path-delimiter
3913- "]+")))
3914- (setq extensions (concat "\\."
3915- (regexp-opt (eval (nth 2 format-spec)) t)
3916- "\\'"))
3917- (setq result
3918- (apply #'append
3919- (mapcar
3920- (lambda(x) (directory-files x
3921- (not nodir)
3922- extensions))
3923- dirs)))
3924- (if strip
3925- (mapcar (lambda(x)
3926- (if (string-match extensions x)
3927- (substring x 0 (match-beginning 0))
3928- x))
3929- result)
3930- result)))))
3931-
3932-(defun TeX-search-files (&optional directories extensions nodir strip)
3933- "Return a list of all reachable files in DIRECTORIES ending with EXTENSIONS.
3934-If optional argument NODIR is set, remove directory part.
3935-If optional argument STRIP is set, remove file extension.
3936-If optional argument DIRECTORIES is set, search in those directories.
3937-Otherwise, search in all TeX macro directories.
3938-If optional argument EXTENSIONS is not set, use `TeX-file-extensions'"
3939- (if (null extensions)
3940- (setq extensions TeX-file-extensions))
3941- (or (TeX-search-files-kpathsea extensions nodir strip)
3942- (progn
3943- (if (null directories)
3944- (setq directories
3945- (cons "./" (append TeX-macro-private TeX-macro-global))))
3946- (let (match
3947- (TeX-file-recurse (cond ((symbolp TeX-file-recurse)
3948- TeX-file-recurse)
3949- ((zerop TeX-file-recurse)
3950- nil)
3951- ((1- TeX-file-recurse)))))
3952- (while directories
3953- (let* ((directory (car directories))
3954- (content (and directory
3955- (file-readable-p directory)
3956- (file-directory-p directory)
3957- (directory-files directory))))
3958- (setq directories (cdr directories))
3959- (while content
3960- (let ((file (concat directory (car content))))
3961- (setq content (cdr content))
3962- (cond ((string-match TeX-ignore-file file))
3963- ((not (file-readable-p file)))
3964- ((file-directory-p file)
3965- (if TeX-file-recurse
3966- (setq match
3967- (append match
3968- (TeX-search-files
3969- (list (file-name-as-directory file))
3970- extensions
3971- nodir strip)))))
3972- ((TeX-match-extension file extensions)
3973- (setq match (cons (TeX-strip-extension file
3974- extensions
3975- nodir
3976- (not strip))
3977- match))))))))
3978- match))))
3979-
3980-(defun TeX-car-string-lessp (s1 s2)
3981- "Compare the cars of S1 and S2 in lexicographic order.
3982-Return t if first is less than second in lexicographic order."
3983- (string-lessp (car s1) (car s2)))
3984-
3985-(defun TeX-listify (elt)
3986- "Return a newly created list with element ELT.
3987-If ELT already is a list, return ELT."
3988- (if (listp elt) elt (list elt)))
3989-
3990-(defun TeX-member (elt list how)
3991- "Return the member ELT in LIST. Comparison done with HOW.
3992-Return nil if ELT is not a member of LIST."
3993- (while (and list (not (funcall how elt (car list))))
3994- (setq list (cdr list)))
3995- (car-safe list))
3996-
3997-(defun TeX-elt-of-list-member (elts list)
3998- "Return non-nil if an element of ELTS is a member of LIST."
3999- (catch 'found
4000- (dolist (elt elts)
4001- (when (member elt list)
4002- (throw 'found t)))))
4003-
4004-(defun TeX-assoc (key list)
4005- "Return non-nil if KEY is `equal' to the car of an element of LIST.
4006-Like assoc, except case insensitive."
4007- (let ((case-fold-search t))
4008- (TeX-member key list
4009- (lambda (a b)
4010- (string-match (concat "^" (regexp-quote a) "$")
4011- (car b))))))
4012-
4013-(defun TeX-match-buffer (n)
4014- "Return the substring corresponding to the N'th match.
4015-See `match-data' for details."
4016- (if (match-beginning n)
4017- (buffer-substring-no-properties (match-beginning n) (match-end n))
4018- ""))
4019-
4020-(defun TeX-function-p (arg)
4021- "Return non-nil if ARG is callable as a function."
4022- (or (and (fboundp 'byte-code-function-p)
4023- (byte-code-function-p arg))
4024- (and (listp arg)
4025- (eq (car arg) 'lambda))
4026- (and (symbolp arg)
4027- (fboundp arg))))
4028-
4029-(defun TeX-booleanp (arg)
4030- "Return non-nil if ARG is t or nil."
4031- (memq arg '(t nil)))
4032-
4033-(defun TeX-looking-at-backward (regexp &optional limit)
4034- "Return non-nil if the text before point matches REGEXP.
4035-Optional second argument LIMIT gives a max number of characters
4036-to look backward for."
4037- (let ((pos (point)))
4038- (save-excursion
4039- (and (re-search-backward regexp
4040- (if limit (max (point-min) (- (point) limit)))
4041- t)
4042- (eq (match-end 0) pos)))))
4043-
4044-(defun TeX-current-line ()
4045- "The current line number."
4046- (format "%d" (1+ (TeX-current-offset))))
4047-
4048-(defun TeX-current-file-name-master-relative ()
4049- "Return current filename, relative to master directory."
4050- (file-relative-name
4051- (buffer-file-name)
4052- (TeX-master-directory)))
4053-
4054-(defun TeX-near-bobp ()
4055- "Return t iff there's nothing but whitespace between (bob) and (point)."
4056- (save-excursion
4057- (skip-chars-backward " \t\n")
4058- (bobp)))
4059-
4060-(defun TeX-deactivate-mark ()
4061- "Deactivate the mark.
4062-This is a compatibility function which works both in Emacs and
4063-XEmacs. In XEmacs the region is deactivated instead of the
4064-mark which is sort of equivalent."
4065- (if (featurep 'xemacs)
4066- (zmacs-deactivate-region)
4067- (deactivate-mark)))
4068-
4069-(defalias 'TeX-run-mode-hooks
4070- (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks))
4071-
4072-
4073-;;; Syntax Table
4074-
4075-(defvar TeX-mode-syntax-table (make-syntax-table)
4076- "Syntax table used while in TeX mode.")
4077-
4078- (make-variable-buffer-local 'TeX-mode-syntax-table)
4079-
4080-(progn ; Define TeX-mode-syntax-table.
4081- (modify-syntax-entry (string-to-char TeX-esc)
4082- "\\" TeX-mode-syntax-table)
4083- (modify-syntax-entry ?\f ">" TeX-mode-syntax-table)
4084- (modify-syntax-entry ?\n ">" TeX-mode-syntax-table)
4085- (modify-syntax-entry (string-to-char TeX-grop)
4086- (concat "(" TeX-grcl)
4087- TeX-mode-syntax-table)
4088- (modify-syntax-entry (string-to-char TeX-grcl)
4089- (concat ")" TeX-grop)
4090- TeX-mode-syntax-table)
4091- (modify-syntax-entry ?% "<" TeX-mode-syntax-table)
4092- (modify-syntax-entry ?\" "." TeX-mode-syntax-table)
4093- (modify-syntax-entry ?& "." TeX-mode-syntax-table)
4094- (modify-syntax-entry ?_ "." TeX-mode-syntax-table)
4095- (modify-syntax-entry ?@ "_" TeX-mode-syntax-table)
4096- (modify-syntax-entry ?~ "." TeX-mode-syntax-table)
4097- (modify-syntax-entry ?$ "$" TeX-mode-syntax-table)
4098- (modify-syntax-entry ?' "w" TeX-mode-syntax-table)
4099- (modify-syntax-entry ?« "." TeX-mode-syntax-table)
4100- (modify-syntax-entry ?» "." TeX-mode-syntax-table))
4101-
4102-;;; Menu Support
4103-
4104-(defvar TeX-command-current 'TeX-command-master
4105- "Specify whether to run command on master, buffer or region.")
4106-;; Function used to run external command.
4107-
4108-(defun TeX-command-select-master ()
4109- "Determine that the next command will be on the master file."
4110- (interactive)
4111- (message "Next command will be on the master file.")
4112- (setq TeX-command-current 'TeX-command-master))
4113-
4114-(defun TeX-command-select-buffer ()
4115- "Determine that the next command will be on the buffer."
4116- (interactive)
4117- (message "Next command will be on the buffer")
4118- (setq TeX-command-current 'TeX-command-buffer))
4119-
4120-(defun TeX-command-select-region ()
4121- "Determine that the next command will be on the region."
4122- (interactive)
4123- (message "Next command will be on the region")
4124- (setq TeX-command-current 'TeX-command-region))
4125-
4126-(defvar TeX-command-force nil)
4127-;; If non-nil, TeX-command-query will return the value of this
4128-;; variable instead of quering the user.
4129-
4130-(defun TeX-command-menu (name)
4131- "Execute `TeX-command-list' NAME from a menu."
4132- (let ((TeX-command-force name))
4133- (funcall TeX-command-current)))
4134-
4135-(defun TeX-command-menu-print (printer command name)
4136- "Print on PRINTER using method COMMAND to run NAME."
4137- (let ((TeX-printer-default (unless (string= printer "Other") printer))
4138- (TeX-printer-list (and (string= printer "Other") TeX-printer-list))
4139- (TeX-print-command command)
4140- (TeX-queue-command command))
4141- (TeX-command-menu name)))
4142-
4143-(defun TeX-command-menu-printer-entry (entry lookup command name)
4144- "Return `TeX-printer-list' ENTRY as a menu item."
4145- (vector (nth 0 entry)
4146- (list 'TeX-command-menu-print
4147- (nth 0 entry)
4148- (or (nth lookup entry) command)
4149- name)))
4150-
4151-(defun TeX-command-menu-entry (entry)
4152- "Return `TeX-command-list' ENTRY as a menu item."
4153- (let ((name (car entry)))
4154- (cond ((and (string-equal name TeX-command-Print)
4155- TeX-printer-list)
4156- (cons TeX-command-Print
4157- (mapcar (lambda (entry)
4158- (TeX-command-menu-printer-entry
4159- entry 1 TeX-print-command name))
4160- (append TeX-printer-list '(("Other"))))))
4161- ((and (string-equal name TeX-command-Queue)
4162- TeX-printer-list)
4163- (cons TeX-command-Queue
4164- (mapcar (lambda (entry)
4165- (TeX-command-menu-printer-entry
4166- entry 2 TeX-queue-command name))
4167- (append TeX-printer-list '(("Other"))))))
4168- (t
4169- (vconcat `(,name (TeX-command-menu ,name))
4170- (nthcdr 5 entry))))))
4171-
4172-(defconst TeX-command-menu-name "Command"
4173- "Name to be displayed for the command menu in all modes defined by AUCTeX.")
4174-
4175-;;; Keymap
4176-
4177-(defcustom TeX-electric-escape nil
4178- "If non-nil, ``\\'' will be bound to `TeX-electric-macro'."
4179- :group 'TeX-macro
4180- :type 'boolean)
4181-
4182-(defcustom TeX-electric-sub-and-superscript nil
4183- "If non-nil, insert braces after typing `^' and `_' in math mode."
4184- :group 'TeX-macro
4185- :type 'boolean)
4186-
4187-(defcustom TeX-newline-function 'newline
4188- "Function to be called upon pressing `RET'."
4189- :group 'TeX-indentation
4190- :type '(choice (const newline)
4191- (const newline-and-indent)
4192- (const reindent-then-newline-and-indent)
4193- (sexp :tag "Other")))
4194-
4195-(defun TeX-insert-backslash (arg)
4196- "Either insert typed key ARG times or call `TeX-electric-macro'.
4197-`TeX-electric-macro' will be called if `TeX-electric-escape' is non-nil."
4198- (interactive "*p")
4199- (if TeX-electric-escape
4200- (TeX-electric-macro)
4201- (self-insert-command arg)))
4202-
4203-(defun TeX-insert-sub-or-superscript (arg)
4204- "Insert typed key ARG times and possibly a pair of braces.
4205-Brace insertion is only done if point is in a math construct and
4206-`TeX-electric-sub-and-superscript' has a non-nil value."
4207- (interactive "*p")
4208- (self-insert-command arg)
4209- (when (and TeX-electric-sub-and-superscript (texmathp))
4210- (insert (concat TeX-grop TeX-grcl))
4211- (backward-char)))
4212-
4213-(defun TeX-newline ()
4214- "Call the function specified by the variable `TeX-newline-function'."
4215- (interactive) (funcall TeX-newline-function))
4216-
4217-(defvar TeX-mode-map
4218- (let ((map (make-sparse-keymap)))
4219- ;; Standard
4220- ;; (define-key map "\177" 'backward-delete-char-untabify)
4221- (define-key map "\C-c}" 'up-list)
4222- (define-key map "\C-c#" 'TeX-normal-mode)
4223- (define-key map "\C-c\C-n" 'TeX-normal-mode)
4224- (define-key map "\C-c?" 'TeX-doc)
4225- (define-key map "\C-c\C-i" 'TeX-goto-info-page)
4226- (define-key map "\r" 'TeX-newline)
4227-
4228- ;; From tex.el
4229- (define-key map "\"" 'TeX-insert-quote)
4230- (define-key map "$" 'TeX-insert-dollar)
4231- ;; Removed because LaTeX 2e have a better solution to italic correction.
4232- ;; (define-key map "." 'TeX-insert-punctuation)
4233- ;; (define-key map "," 'TeX-insert-punctuation)
4234- (define-key map "\C-c{" 'TeX-insert-braces)
4235- (define-key map "\C-c\C-f" 'TeX-font)
4236- (define-key map "\C-c\C-m" 'TeX-insert-macro)
4237- (define-key map "\\" 'TeX-insert-backslash)
4238- (define-key map "^" 'TeX-insert-sub-or-superscript)
4239- (define-key map "_" 'TeX-insert-sub-or-superscript)
4240- (define-key map "\e\t" 'TeX-complete-symbol) ;*** Emacs 19 way
4241-
4242- (define-key map "\C-c'" 'TeX-comment-or-uncomment-paragraph) ;*** Old way
4243- (define-key map "\C-c:" 'TeX-comment-or-uncomment-region) ;*** Old way
4244- (define-key map "\C-c\"" 'TeX-uncomment) ;*** Old way
4245-
4246- (define-key map "\C-c;" 'TeX-comment-or-uncomment-region)
4247- (define-key map "\C-c%" 'TeX-comment-or-uncomment-paragraph)
4248-
4249- (define-key map "\C-c\C-t\C-p" 'TeX-PDF-mode)
4250- (define-key map "\C-c\C-t\C-i" 'TeX-interactive-mode)
4251- (define-key map "\C-c\C-t\C-s" 'TeX-source-correlate-mode)
4252- (define-key map "\C-c\C-t\C-r" 'TeX-pin-region)
4253- (define-key map "\C-c\C-w" 'TeX-toggle-debug-bad-boxes); to be removed
4254- (define-key map "\C-c\C-t\C-b" 'TeX-toggle-debug-bad-boxes)
4255- (define-key map "\C-c\C-t\C-w" 'TeX-toggle-debug-warnings)
4256- (define-key map "\C-c\C-v" 'TeX-view)
4257- ;; From tex-buf.el
4258- (define-key map "\C-c\C-d" 'TeX-save-document)
4259- (define-key map "\C-c\C-r" 'TeX-command-region)
4260- (define-key map "\C-c\C-b" 'TeX-command-buffer)
4261- (define-key map "\C-c\C-c" 'TeX-command-master)
4262- (define-key map "\C-c\C-k" 'TeX-kill-job)
4263- (define-key map "\C-c\C-l" 'TeX-recenter-output-buffer)
4264- (define-key map "\C-c^" 'TeX-home-buffer)
4265- (define-key map "\C-c`" 'TeX-next-error)
4266- ;; Remap bindings of `next-error'
4267- (if (featurep 'xemacs)
4268- (substitute-key-definition 'next-error 'TeX-next-error map global-map)
4269- (define-key map [remap next-error] 'TeX-next-error))
4270- ;; Remap bindings of `previous-error'
4271- (if (featurep 'xemacs)
4272- (substitute-key-definition 'previous-error 'TeX-previous-error
4273- map global-map)
4274- (define-key map [remap previous-error] 'TeX-previous-error))
4275- ;; From tex-fold.el
4276- (define-key map "\C-c\C-o\C-f" 'TeX-fold-mode)
4277-
4278- ;; Multifile
4279- (define-key map "\C-c_" 'TeX-master-file-ask) ;*** temporary
4280- map)
4281- "Keymap for common TeX and LaTeX commands.")
4282-
4283-(defvar plain-TeX-mode-map
4284- (let ((map (make-sparse-keymap)))
4285- (set-keymap-parent map TeX-mode-map)
4286- map)
4287- "Keymap used in plain TeX mode.")
4288-
4289-(defun TeX-mode-specific-command-menu (mode)
4290- "Return a Command menu specific to the major MODE."
4291- ;; COMPATIBILITY for Emacs < 21
4292- (if (and (not (featurep 'xemacs))
4293- (= emacs-major-version 20))
4294- (cons TeX-command-menu-name
4295- (TeX-mode-specific-command-menu-entries mode))
4296- (list TeX-command-menu-name
4297- :filter `(lambda (&rest ignored)
4298- (TeX-mode-specific-command-menu-entries ',mode))
4299- "Bug.")))
4300-
4301-(defun TeX-mode-specific-command-menu-entries (mode)
4302- "Return the entries for a Command menu specific to the major MODE."
4303- (append
4304- (TeX-menu-with-help
4305- `("Command on"
4306- [ "Master File" TeX-command-select-master
4307- :keys "C-c C-c" :style radio
4308- :selected (eq TeX-command-current 'TeX-command-master)
4309- :help "Commands in this menu work on the Master File"]
4310- [ "Buffer" TeX-command-select-buffer
4311- :keys "C-c C-b" :style radio
4312- :selected (eq TeX-command-current 'TeX-command-buffer)
4313- :help "Commands in this menu work on the current buffer"]
4314- [ "Region" TeX-command-select-region
4315- :keys "C-c C-r" :style radio
4316- :selected (eq TeX-command-current 'TeX-command-region)
4317- :help "Commands in this menu work on the region"]
4318- [ "Fix the Region" TeX-pin-region
4319- :active (or (if prefix-arg
4320- (<= (prefix-numeric-value prefix-arg) 0)
4321- (and (boundp 'TeX-command-region-begin)
4322- (markerp TeX-command-region-begin)))
4323- (TeX-mark-active))
4324- ;;:visible (eq TeX-command-current 'TeX-command-region)
4325- :style toggle
4326- :selected (and (boundp 'TeX-command-region-begin)
4327- (markerp TeX-command-region-begin))
4328- :help "Fix the region for \"Command on Region\""]
4329- "-"
4330- ["Recenter Output Buffer" TeX-recenter-output-buffer
4331- :help "Show the output of current TeX process"]
4332- ["Kill Job" TeX-kill-job
4333- :help "Kill the current TeX process"]
4334- ["Next Error" TeX-next-error
4335- :help "Jump to the next error of the last TeX run"]
4336- ["Quick View" TeX-view
4337- :help "Start a viewer without prompting"]
4338- "-"
4339- ("TeXing Options"
4340- ,@(mapcar (lambda (x)
4341- (let ((symbol (car x)) (name (nth 1 x)))
4342- `[ ,(format "Use %s engine" name) (TeX-engine-set ',symbol)
4343- :style radio :selected (eq TeX-engine ',symbol)
4344- :help ,(format "Use %s engine for compiling" name) ]))
4345- (TeX-engine-alist))
4346- "-"
4347- [ "Generate PDF" TeX-PDF-mode
4348- :style toggle :selected TeX-PDF-mode
4349- :active (not (eq TeX-engine 'omega))
4350- :help "Use PDFTeX to generate PDF instead of DVI"]
4351- [ "Run Interactively" TeX-interactive-mode
4352- :style toggle :selected TeX-interactive-mode :keys "C-c C-t C-i"
4353- :help "Stop on errors in a TeX run"]
4354- [ "Correlate I/O" TeX-source-correlate-mode
4355- :style toggle :selected TeX-source-correlate-mode
4356- :help "Enable forward and inverse search in the previewer"]
4357- ["Debug Bad Boxes" TeX-toggle-debug-bad-boxes
4358- :style toggle :selected TeX-debug-bad-boxes :keys "C-c C-t C-b"
4359- :help "Make \"Next Error\" show overfull and underfull boxes"]
4360- ["Debug Warnings" TeX-toggle-debug-warnings
4361- :style toggle :selected TeX-debug-warnings
4362- :help "Make \"Next Error\" show warnings"])))
4363- (let ((file 'TeX-command-on-current));; is this actually needed?
4364- (TeX-maybe-remove-help
4365- (delq nil
4366- (mapcar 'TeX-command-menu-entry
4367- (TeX-mode-specific-command-list mode)))))))
4368-
4369-(defun TeX-mode-specific-command-list (mode)
4370- "Return the list of commands available in the given MODE."
4371- (let ((full-list TeX-command-list)
4372- out-list
4373- entry)
4374- (while (setq entry (pop full-list))
4375- ;; `(nth 4 entry)' may be either an atom in case of which the
4376- ;; entry should be present in any mode or a list of major modes.
4377- (if (or (atom (nth 4 entry))
4378- (memq mode (nth 4 entry)))
4379- (push entry out-list)))
4380- (nreverse out-list)))
4381-
4382-(defvar TeX-fold-menu
4383- (TeX-menu-with-help
4384- '("Show/Hide"
4385- ["Fold Mode" TeX-fold-mode
4386- :style toggle
4387- :selected (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4388- :help "Toggle folding mode"]
4389- "-"
4390- ["Hide All in Current Buffer" TeX-fold-buffer
4391- :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4392- :help "Hide all configured TeX constructs in the current buffer"]
4393- ["Hide All in Current Region" TeX-fold-region
4394- :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4395- :help "Hide all configured TeX constructs in the marked region"]
4396- ["Hide All in Current Paragraph" TeX-fold-paragraph
4397- :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4398- :help "Hide all configured TeX constructs in the paragraph containing point"]
4399- ["Hide Current Macro" TeX-fold-macro
4400- :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4401- :help "Hide the macro containing point"]
4402- ["Hide Current Environment" TeX-fold-env
4403- :visible (not (eq major-mode 'plain-tex-mode))
4404- :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4405- :help "Hide the environment containing point"]
4406- ["Hide Current Comment" TeX-fold-comment
4407- :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4408- :help "Hide the comment containing point"]
4409- "-"
4410- ["Show All in Current Buffer" TeX-fold-clearout-buffer
4411- :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4412- :help "Permanently show all folded content again"]
4413- ["Show All in Current Region" TeX-fold-clearout-region
4414- :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4415- :help "Permanently show all folded content in marked region"]
4416- ["Show All in Current Paragraph" TeX-fold-clearout-paragraph
4417- :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4418- :help "Permanently show all folded content in paragraph containing point"]
4419- ["Show Current Item" TeX-fold-clearout-item
4420- :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4421- :help "Permanently show the item containing point"]
4422- "-"
4423- ["Hide or Show Current Item" TeX-fold-dwim
4424- :active (and (boundp 'TeX-fold-mode) TeX-fold-mode)
4425- :help "Hide or show the item containing point"]))
4426- "Menu definition for commands from tex-fold.el.")
4427-
4428-
4429-;;; Menus for plain TeX mode
4430-(easy-menu-define plain-TeX-mode-command-menu
4431- plain-TeX-mode-map
4432- "Command menu used in TeX mode."
4433- (TeX-mode-specific-command-menu 'plain-tex-mode))
4434-
4435-(defvar TeX-customization-menu nil)
4436-
4437-(defvar TeX-common-menu-entries
4438- (TeX-menu-with-help
4439- `(("Multifile/Parsing"
4440- ["Switch to Master File" TeX-home-buffer
4441- :help "Switch to buffer of Master File, or buffer of last TeX command"]
4442- ["Save Document" TeX-save-document
4443- :help "Save all buffers associated with the current Master File"]
4444- ["Set Master File" TeX-master-file-ask
4445- :active (not (TeX-local-master-p))
4446- :help "Set the main file to run TeX commands on"]
4447- ["Reset Buffer" TeX-normal-mode
4448- :help "Save and reparse the current buffer for style information"]
4449- ["Reset AUCTeX" (TeX-normal-mode t) :keys "C-u C-c C-n"
4450- :help "Reset buffer and reload AUCTeX style files"])
4451- ["Find Documentation..." TeX-doc
4452- :help "Get help on commands, packages, or TeX-related topics in general"]
4453- ["Read the AUCTeX Manual" TeX-goto-info-page
4454- :help "Everything worth reading"]
4455- ("Customize AUCTeX"
4456- ["Browse Options"
4457- (customize-group 'AUCTeX)
4458- :help "Open the customization buffer for AUCTeX"]
4459- ["Extend this Menu"
4460- (progn
4461- (easy-menu-add-item
4462- nil
4463- ;; Ugly hack because docTeX mode uses the LaTeX menu.
4464- (list (if (eq major-mode 'doctex-mode) "LaTeX" TeX-base-mode-name))
4465- (or TeX-customization-menu
4466- (setq TeX-customization-menu
4467- (customize-menu-create 'AUCTeX "Customize AUCTeX")))))
4468- :help "Make this menu a full-blown customization menu"])
4469- ["Report AUCTeX Bug" TeX-submit-bug-report
4470- :help ,(format "Problems with AUCTeX %s? Mail us!"
4471- AUCTeX-version)])))
4472-
4473-(defvar plain-TeX-menu-entries
4474- (TeX-menu-with-help
4475- `(["Macro..." TeX-insert-macro
4476- :help "Insert a macro and possibly arguments"]
4477- ["Complete" TeX-complete-symbol
4478- :help "Complete the current macro"]
4479- "-"
4480- ("Insert Font"
4481- ["Emphasize" (TeX-font nil ?\C-e) :keys "C-c C-f C-e"]
4482- ["Bold" (TeX-font nil ?\C-b) :keys "C-c C-f C-b"]
4483- ["Typewriter" (TeX-font nil ?\C-t) :keys "C-c C-f C-t"]
4484- ["Small Caps" (TeX-font nil ?\C-c) :keys "C-c C-f C-c"]
4485- ["Sans Serif" (TeX-font nil ?\C-f) :keys "C-c C-f C-f"]
4486- ["Italic" (TeX-font nil ?\C-i) :keys "C-c C-f C-i"]
4487- ["Slanted" (TeX-font nil ?\C-s) :keys "C-c C-f C-s"]
4488- ["Roman" (TeX-font nil ?\C-r) :keys "C-c C-f C-r"]
4489- ["Calligraphic" (TeX-font nil ?\C-a) :keys "C-c C-f C-a"])
4490- ("Replace Font"
4491- ["Emphasize" (TeX-font t ?\C-e) :keys "C-u C-c C-f C-e"]
4492- ["Bold" (TeX-font t ?\C-b) :keys "C-u C-c C-f C-b"]
4493- ["Typewriter" (TeX-font t ?\C-t) :keys "C-u C-c C-f C-t"]
4494- ["Small Caps" (TeX-font t ?\C-c) :keys "C-u C-c C-f C-c"]
4495- ["Sans Serif" (TeX-font t ?\C-f) :keys "C-u C-c C-f C-f"]
4496- ["Italic" (TeX-font t ?\C-i) :keys "C-u C-c C-f C-i"]
4497- ["Slanted" (TeX-font t ?\C-s) :keys "C-u C-c C-f C-s"]
4498- ["Roman" (TeX-font t ?\C-r) :keys "C-u C-c C-f C-r"]
4499- ["Calligraphic" (TeX-font t ?\C-a) :keys "C-u C-c C-f C-a"])
4500- ["Delete Font" (TeX-font t ?\C-d) :keys "C-c C-f C-d"]
4501- "-"
4502- ["Comment or Uncomment Region" TeX-comment-or-uncomment-region
4503- :help "Comment or uncomment the currently selected region"]
4504- ["Comment or Uncomment Paragraph" TeX-comment-or-uncomment-paragraph
4505- :help "Comment or uncomment the paragraph containing point"]
4506- ,TeX-fold-menu
4507- "-" . ,TeX-common-menu-entries)))
4508-
4509-(easy-menu-define plain-TeX-mode-menu
4510- plain-TeX-mode-map
4511- "Menu used in plain TeX mode."
4512- (cons "TeX" plain-TeX-menu-entries))
4513-
4514-;;; AmSTeX
4515-
4516-(defvar AmSTeX-mode-map
4517- (let ((map (make-sparse-keymap)))
4518- (set-keymap-parent map TeX-mode-map)
4519- map)
4520- "Keymap used in `AmSTeX-mode'.")
4521-
4522-;; Menu for AmSTeX mode
4523-(easy-menu-define AmSTeX-mode-command-menu
4524- AmSTeX-mode-map
4525- "Command menu used in AmsTeX mode."
4526- (TeX-mode-specific-command-menu 'ams-tex-mode))
4527-
4528-(easy-menu-define AmSTeX-mode-menu
4529- AmSTeX-mode-map
4530- "Menu used in AMS-TeX mode."
4531- (cons "AmS-TeX" plain-TeX-menu-entries))
4532-
4533-;;;###autoload
4534-(defun ams-tex-mode ()
4535- "Major mode in AUCTeX for editing AmS-TeX files.
4536-See info under AUCTeX for documentation.
4537-
4538-Special commands:
4539-\\{AmSTeX-mode-map}
4540-
4541-Entering AmS-tex-mode calls the value of `text-mode-hook',
4542-then the value of `TeX-mode-hook', and then the value
4543-of `AmS-TeX-mode-hook'."
4544- (interactive)
4545- (plain-TeX-common-initialization)
4546- (setq major-mode 'ams-tex-mode)
4547- (use-local-map AmSTeX-mode-map)
4548-
4549- ;; Menu
4550- (easy-menu-add AmSTeX-mode-menu AmSTeX-mode-map)
4551- (easy-menu-add AmSTeX-mode-command-menu AmSTeX-mode-map)
4552-
4553- (setq TeX-base-mode-name "AmS-TeX")
4554- (setq TeX-command-default "AmSTeX")
4555- (TeX-run-mode-hooks 'text-mode-hook 'TeX-mode-hook 'AmS-TeX-mode-hook)
4556- (TeX-set-mode-name))
4557-
4558-
4559-;;; Verbatim constructs
4560-
4561-(defvar TeX-verbatim-p-function nil
4562- "Mode-specific function to be called by `TeX-verbatim-p'.")
4563-(make-variable-buffer-local 'TeX-verbatim-p-function)
4564-
4565-;; XXX: We only have an implementation for LaTeX mode at the moment (Oct 2009).
4566-(defun TeX-verbatim-p (&optional pos)
4567- "Return non-nil if position POS is in a verbatim-like construct.
4568-A mode-specific implementation is required. If it is not
4569-available, the function always returns nil."
4570- (when TeX-verbatim-p-function
4571- (funcall TeX-verbatim-p-function)))
4572-
4573-
4574-;;; Comments
4575-
4576-(defvar TeX-comment-start-regexp "%"
4577- "Regular expression matching a comment starter.
4578-Unlike the variable `comment-start-skip' it should not match any
4579-whitespace after the comment starter or any character before it.")
4580-(make-variable-buffer-local 'TeX-comment-start-regexp)
4581-
4582-(defun TeX-comment-region (beg end &optional arg)
4583- "Comment each line in the region from BEG to END.
4584-Numeric prefix arg ARG means use ARG comment characters.
4585-If ARG is negative, delete that many comment characters instead."
4586- (interactive "*r\nP")
4587- ;; `comment-padding' will not be recognized in XEmacs' (21.4)
4588- ;; `comment-region', so we temporarily modify `comment-start' to get
4589- ;; proper spacing. Unfortunately we have to check for the XEmacs
4590- ;; version and cannot test if `comment-padding' is bound as this
4591- ;; gets initialized in `VirTeX-common-initialization'.
4592- (let ((comment-start (if (and (featurep 'xemacs)
4593- (= emacs-major-version 21)
4594- (<= emacs-minor-version 4))
4595- (concat comment-start (TeX-comment-padding-string))
4596- comment-start)))
4597- (comment-region beg end arg)))
4598-
4599-(eval-and-compile
4600- ;; COMPATIBILITY for Emacs <= 21.3
4601- (if (fboundp 'comment-or-uncomment-region)
4602- (defalias 'TeX-comment-or-uncomment-region 'comment-or-uncomment-region)
4603- ;; The following function was copied from `newcomment.el' on
4604- ;; 2004-01-30 and adapted accordingly
4605- (defun TeX-comment-or-uncomment-region (beg end &optional arg)
4606- "Comment or uncomment a the region from BEG to END.
4607-Call `TeX-comment-region', unless the region only consists of
4608-comments, in which case call `TeX-uncomment-region'. If a prefix
4609-arg ARG is given, it is passed on to the respective function."
4610- (interactive "*r\nP")
4611- (funcall (if (save-excursion ;; check for already commented region
4612- (goto-char beg)
4613- (TeX-comment-forward (point-max))
4614- (<= end (point)))
4615- 'TeX-uncomment-region 'TeX-comment-region)
4616- beg end arg)))
4617-
4618- ;; COMPATIBILITY for Emacs <= 20. (Introduced in 21.1?)
4619- (if (fboundp 'uncomment-region)
4620- (defalias 'TeX-uncomment-region 'uncomment-region)
4621- (defun TeX-uncomment-region (beg end &optional arg)
4622- "Remove comment characters from the beginning of each line
4623-in the region from BEG to END. Numeric prefix arg ARG means use
4624-ARG comment characters. If ARG is negative, delete that many
4625-comment characters instead."
4626- (interactive "*r\nP")
4627- (or arg
4628- ;; Determine the number of comment characters at the
4629- ;; beginning of the first commented line.
4630- (setq arg
4631- (save-excursion
4632- (goto-char beg)
4633- (re-search-forward
4634- (concat "^" TeX-comment-start-regexp "+") end t)
4635- (length (match-string 0)))))
4636- (comment-region beg end (- arg)))))
4637-
4638-(defun TeX-uncomment ()
4639- "Delete comment characters from the beginning of each line in a comment."
4640- (interactive)
4641- (save-excursion
4642- ;; Find first comment line
4643- (beginning-of-line)
4644- (while (and (looking-at (concat "^[ \t]*" TeX-comment-start-regexp))
4645- (not (bobp)))
4646- (forward-line -1))
4647- (let ((beg (point)))
4648- (forward-line 1)
4649- ;; Find last comment line
4650- (while (and (looking-at (concat "^[ \t]*" TeX-comment-start-regexp))
4651- (not (eobp)))
4652- (forward-line 1))
4653- ;; Uncomment region
4654- (TeX-uncomment-region beg (point)))))
4655-
4656-(defun TeX-comment-or-uncomment-paragraph ()
4657- "Comment or uncomment current paragraph."
4658- (interactive)
4659- (if (TeX-in-commented-line)
4660- (TeX-uncomment)
4661- (save-excursion
4662- (beginning-of-line)
4663- ;; Don't do anything if we are in an empty line. If this line
4664- ;; is followed by a lot of commented lines, this shall prevent
4665- ;; that mark-paragraph skips over these lines and marks a
4666- ;; paragraph outside the visible window which might get
4667- ;; commented without the user noticing.
4668- (unless (looking-at "^[ \t]*$")
4669- (mark-paragraph)
4670- (TeX-comment-region (point) (mark))))))
4671-
4672-(defun TeX-in-comment ()
4673- "Return non-nil if point is in a comment."
4674- (if (or (bolp)
4675- (null comment-start-skip)
4676- (eq (preceding-char) ?\r))
4677- nil
4678- (save-excursion
4679- (save-match-data
4680- (let ((pos (point)))
4681- (beginning-of-line)
4682- (and (or (looking-at comment-start-skip)
4683- (re-search-forward comment-start-skip pos t))
4684- (not (TeX-verbatim-p))))))))
4685-
4686-(defun TeX-in-commented-line ()
4687- "Return non-nil if point is in a line consisting only of a comment.
4688-The comment can be preceded by whitespace. This means that
4689-`TeX-in-commented-line' is more general than `TeX-in-line-comment'
4690-which will not match commented lines with leading whitespace. But
4691-`TeX-in-commented-line' will match commented lines without leading
4692-whitespace as well."
4693- (save-excursion
4694- (forward-line 0)
4695- (skip-chars-forward " \t")
4696- (string= (buffer-substring-no-properties
4697- (point) (min (point-max) (+ (point) (length comment-start))))
4698- comment-start)))
4699-
4700-(defun TeX-in-line-comment ()
4701- "Return non-nil if point is in a line comment.
4702-A line comment is a comment starting in column one, i.e. there is
4703-no whitespace before the comment sign."
4704- (save-excursion
4705- (forward-line 0)
4706- (string= (buffer-substring-no-properties
4707- (point) (min (point-max) (+ (point) (length comment-start))))
4708- comment-start)))
4709-
4710-(defun TeX-comment-prefix ()
4711- "Return the comment prefix of the current line.
4712-If there are no comment starters after potential whitespace at
4713-the beginning of the line, return nil."
4714- (save-excursion
4715- (beginning-of-line)
4716- (save-match-data
4717- (when (looking-at (concat "\\([ \t]*" TeX-comment-start-regexp "+\\)+"))
4718- (match-string 0)))))
4719-
4720-(defun TeX-forward-comment-skip (&optional count limit)
4721- "Move forward to the next comment skip.
4722-This may be a switch between commented and not commented adjacent
4723-lines or between lines with different comment prefixes. With
4724-argument COUNT do it COUNT times. If argument LIMIT is given, do
4725-not move point further than this value."
4726- (unless count (setq count 1))
4727- ;; A value of 0 is nonsense.
4728- (when (= count 0) (setq count 1))
4729- (unless limit (setq limit (point-max)))
4730- (dotimes (i (abs count))
4731- (if (< count 0)
4732- (forward-line -1)
4733- (beginning-of-line))
4734- (let ((prefix (when (looking-at (concat "\\([ \t]*"
4735- TeX-comment-start-regexp "+\\)+"))
4736- (buffer-substring (+ (line-beginning-position)
4737- (current-indentation))
4738- (match-end 0)))))
4739- (while (save-excursion
4740- (and (if (> count 0)
4741- (<= (point) limit)
4742- (>= (point) limit))
4743- (zerop (if (> count 0)
4744- (forward-line 1)
4745- (forward-line -1)))
4746- (if prefix
4747- (if (looking-at (concat "\\([ \t]*"
4748- TeX-comment-start-regexp
4749- "+\\)+"))
4750- ;; If the preceding line is a commented line
4751- ;; as well, check if the prefixes are
4752- ;; identical.
4753- (string= prefix
4754- (buffer-substring
4755- (+ (line-beginning-position)
4756- (current-indentation))
4757- (match-end 0)))
4758- nil)
4759- (not (looking-at (concat "[ \t]*"
4760- TeX-comment-start-regexp))))))
4761- (if (> count 0)
4762- (forward-line 1)
4763- (forward-line -1)))
4764- (if (> count 0)
4765- (forward-line 1)))))
4766-
4767-(defun TeX-backward-comment-skip (&optional count limit)
4768- "Move backward to the next comment skip.
4769-This may be a switch between commented and not commented adjacent
4770-lines or between lines with different comment prefixes. With
4771-argument COUNT do it COUNT times. If argument LIMIT is given, do
4772-not move point to a position less than this value."
4773- (unless count (setq count 1))
4774- (when (= count 0) (setq count 1))
4775- (unless limit (setq limit (point-min)))
4776- (TeX-forward-comment-skip (- count) limit))
4777-
4778-;; Taken from `comment-forward' in Emacs' CVS on 2006-12-26. Used as
4779-;; a compatibility function for XEmacs 21.4.
4780-(defun TeX-comment-forward (&optional n)
4781- "Skip forward over N comments.
4782-Just like `forward-comment' but only for positive N
4783-and can use regexps instead of syntax."
4784- (when (fboundp 'comment-normalize-vars)
4785- (comment-normalize-vars))
4786- (if (fboundp 'comment-forward)
4787- (comment-forward n)
4788- (setq n (or n 1))
4789- (if (< n 0) (error "No comment-backward")
4790- (if comment-use-syntax (forward-comment n)
4791- (while (> n 0)
4792- (setq n
4793- (if (or (forward-comment 1)
4794- (and (looking-at comment-start-skip)
4795- (goto-char (match-end 0))
4796- (re-search-forward comment-end-skip nil 'move)))
4797- (1- n) -1)))
4798- (= n 0)))))
4799-
4800-(defun TeX-comment-padding-string ()
4801- "Return comment padding as a string.
4802-The variable `comment-padding' can hold an integer or a string.
4803-This function will return the appropriate string representation
4804-regardless of its data type."
4805- (if (integerp comment-padding)
4806- (make-string comment-padding ? )
4807- comment-padding))
4808-
4809-
4810-;;; Indentation
4811-
4812-(defgroup TeX-indentation nil
4813- "Indentation of TeX buffers in AUCTeX."
4814- :group 'AUCTeX)
4815-
4816-(defcustom TeX-brace-indent-level 2
4817- "*The level of indentation produced by an open brace."
4818- :group 'TeX-indentation
4819- :type 'integer)
4820-
4821-(defun TeX-comment-indent ()
4822- "Determine the indentation of a comment."
4823- (if (looking-at "%%%")
4824- (current-column)
4825- (skip-chars-backward " \t")
4826- (max (if (bolp) 0 (1+ (current-column)))
4827- comment-column)))
4828-
4829-(defun TeX-brace-count-line ()
4830- "Count number of open/closed braces."
4831- (save-excursion
4832- (let ((count 0) (limit (line-end-position)) char)
4833- (while (progn
4834- (skip-chars-forward "^{}\\\\" limit)
4835- (when (and (< (point) limit) (not (TeX-in-comment)))
4836- (setq char (char-after))
4837- (forward-char)
4838- (cond ((eq char ?\{)
4839- (setq count (+ count TeX-brace-indent-level)))
4840- ((eq char ?\})
4841- (setq count (- count TeX-brace-indent-level)))
4842- ((eq char ?\\)
4843- (when (< (point) limit)
4844- (forward-char)
4845- t))))))
4846- count)))
4847-
4848-;;; Navigation
4849-
4850-(defvar TeX-search-syntax-table
4851- (let ((table (make-syntax-table (make-char-table (if (featurep 'xemacs)
4852- 'syntax
4853- 'syntax-table)))))
4854- ;; Preset mode-independent syntax entries. (Mode-dependent
4855- ;; entries are set in the function `TeX-search-syntax-table'.)
4856- ;; ?\", ?\( and ?\) explicitely get whitespace syntax because
4857- ;; Emacs 21.3 and XEmacs don't generate a completely empty syntax
4858- ;; table.
4859- (dolist (elt '((?\f . ">") (?\n . ">") (?\" . " ") (?\( . " ") (?\) . " ")))
4860- (modify-syntax-entry (car elt) (cdr elt) table))
4861- table)
4862- "Syntax table used for searching purposes.
4863-It should be accessed through the function `TeX-search-syntax-table'.")
4864-
4865-(defun TeX-search-syntax-table (&rest args)
4866- "Return a syntax table for searching purposes.
4867-ARGS may be a list of characters. For each of them the
4868-respective predefined syntax is set. Currently the parenthetical
4869-characters ?{, ?}, ?[, ?], ?\(, ?\), ?<, and ?> are supported.
4870-The syntax of each of these characters not specified will be
4871-reset to \" \"."
4872- (let ((char-syntax-alist '((?\{ . "(}") (?\} . "){")
4873- (?\[ . "(]") (?\] . ")[")
4874- (?\( . "()") (?\) . ")(")
4875- (?\< . "(>") (?\> . ")<"))))
4876- ;; Clean entries possibly set before.
4877- (modify-syntax-entry ?\\ " " TeX-search-syntax-table)
4878- (modify-syntax-entry ?@ " " TeX-search-syntax-table)
4879- (modify-syntax-entry ?\% " " TeX-search-syntax-table)
4880- ;; Preset mode-dependent syntax entries. (Mode-independent entries
4881- ;; are set when the variable `TeX-search-syntax-table' is created.)
4882- (modify-syntax-entry (string-to-char TeX-esc) "\\" TeX-search-syntax-table)
4883- (unless (eq major-mode 'texinfo-mode)
4884- (modify-syntax-entry ?\% "<" TeX-search-syntax-table))
4885- ;; Clean up the entries which can be specified as arguments.
4886- (dolist (elt char-syntax-alist)
4887- (modify-syntax-entry (car elt) " " TeX-search-syntax-table))
4888- ;; Now set what we got.
4889- (dolist (elt args)
4890- (unless (assoc elt char-syntax-alist) (error "Char not supported"))
4891- (modify-syntax-entry elt (cdr (assoc elt char-syntax-alist))
4892- TeX-search-syntax-table))
4893- ;; Return the syntax table.
4894- TeX-search-syntax-table))
4895-
4896-(defun TeX-find-balanced-brace (&optional count depth limit)
4897- "Return the position of a balanced brace in a TeX group.
4898-The function scans forward COUNT parenthetical groupings.
4899-Default is 1. If COUNT is negative, it searches backwards. With
4900-optional DEPTH>=1, find that outer level. If LIMIT is non-nil,
4901-do not search further than this position in the buffer."
4902- (let ((count (if count
4903- (if (= count 0) (error "COUNT has to be <> 0") count)
4904- 1))
4905- (depth (if depth
4906- (if (< depth 1) (error "DEPTH has to be > 0") depth)
4907- 1)))
4908- (save-restriction
4909- (when limit
4910- (if (> count 0)
4911- (narrow-to-region (point-min) limit)
4912- (narrow-to-region limit (point-max))))
4913- (with-syntax-table (TeX-search-syntax-table ?\{ ?\})
4914- (condition-case nil
4915- (scan-lists (point) count depth)
4916- (error nil))))))
4917-
4918-(defun TeX-find-closing-brace (&optional depth limit)
4919- "Return the position of the closing brace in a TeX group.
4920-The function assumes that point is inside the group, i.e. after
4921-an opening brace. With optional DEPTH>=1, find that outer level.
4922-If LIMIT is non-nil, do not search further down than this
4923-position in the buffer."
4924- (TeX-find-balanced-brace 1 depth limit))
4925-
4926-(defun TeX-find-opening-brace (&optional depth limit)
4927- "Return the position of the opening brace in a TeX group.
4928-The function assumes that point is inside the group, i.e. before
4929-a closing brace. With optional DEPTH>=1, find that outer level.
4930-If LIMIT is non-nil, do not search further up than this position
4931-in the buffer."
4932- (TeX-find-balanced-brace -1 depth limit))
4933-
4934-(defun TeX-find-macro-boundaries (&optional lower-bound)
4935- "Return a list containing the start and end of a macro.
4936-If LOWER-BOUND is given, do not search backward further than this
4937-point in buffer. Arguments enclosed in brackets or braces are
4938-considered part of the macro."
4939- (save-restriction
4940- (when lower-bound
4941- (narrow-to-region lower-bound (point-max)))
4942- (let ((orig-point (point))
4943- start-point)
4944- ;; Point is located directly at the start of a macro. (-!-\foo{bar})
4945- (when (and (eq (char-after) (aref TeX-esc 0))
4946- (not (TeX-escaped-p)))
4947- (setq start-point (point)))
4948- ;; Point is located on a macro. (\fo-!-o{bar})
4949- (unless start-point
4950- (save-excursion
4951- (skip-chars-backward "A-Za-z@*")
4952- (when (and (eq (char-before) (aref TeX-esc 0))
4953- (not (TeX-escaped-p (1- (point)))))
4954- (setq start-point (1- (point))))))
4955- ;; Point is located in the argument of a macro. (\foo{ba-!-r})
4956- (unless start-point
4957- (save-excursion
4958- (catch 'abort
4959- (let ((parse-sexp-ignore-comments t))
4960- (when (condition-case nil (progn (up-list) t) (error nil))
4961- (while (progn
4962- (condition-case nil (backward-sexp)
4963- (error (throw 'abort nil)))
4964- (forward-comment -1)
4965- (and (memq (char-before) '(?\] ?\}))
4966- (not (TeX-escaped-p (1- (point)))))))
4967- (skip-chars-backward "A-Za-z@*")
4968- (when (and (eq (char-before) (aref TeX-esc 0))
4969- (not (TeX-escaped-p (1- (point)))))
4970- (setq start-point (1- (point)))))))))
4971- ;; Search forward for the end of the macro.
4972- (when start-point
4973- (save-excursion
4974- (goto-char (TeX-find-macro-end-helper start-point))
4975- (if (< orig-point (point))
4976- (cons start-point (point))
4977- nil))))))
4978-
4979-(defun TeX-find-macro-end-helper (start)
4980- "Find the end of a macro given its START.
4981-START is the position just before the starting token of the macro.
4982-If the macro is followed by square brackets or curly braces,
4983-those will be considered part of it."
4984- (save-excursion
4985- (save-match-data
4986- (catch 'found
4987- (goto-char (1+ start))
4988- (if (zerop (skip-chars-forward "A-Za-z@"))
4989- (forward-char)
4990- (skip-chars-forward "*"))
4991- (while (not (eobp))
4992- (cond
4993- ;; Skip over pairs of square brackets
4994- ((or (looking-at "[ \t]*\n?\\(\\[\\)") ; Be conservative: Consider
4995- ; only consecutive lines.
4996- (and (looking-at (concat "[ \t]*" TeX-comment-start-regexp))
4997- (save-excursion
4998- (forward-line 1)
4999- (looking-at "[ \t]*\\(\\[\\)"))))
5000- (goto-char (match-beginning 1))
The diff has been truncated for viewing.

Subscribers

People subscribed via source and target branches

to all changes: