X-Git-Url: https://code.delx.au/gnu-emacs-elpa/blobdiff_plain/d9da7341cc3c5a7fa4bba1ff50305130e8864933..a6d960ea153c964ffbb89627c1135c3226b28a02:/packages/auctex/latex.el diff --git a/packages/auctex/latex.el b/packages/auctex/latex.el index 8bf283a77..f9859a614 100644 --- a/packages/auctex/latex.el +++ b/packages/auctex/latex.el @@ -1,7 +1,7 @@ ;;; latex.el --- Support for LaTeX documents. -;; Copyright (C) 1991, 1993-1997, 1999, 2000, 2003-2012 -;; Free Software Foundation, Inc. +;; Copyright (C) 1991, 1993, 1994, 1995, 1996, 1997, 1999, 2000, 2003, +;; 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. ;; Maintainer: auctex-devel@gnu.org ;; Keywords: tex @@ -1099,10 +1099,10 @@ Just like array and tabular." (defun LaTeX-env-args (environment &rest args) "Insert ENVIRONMENT and arguments defined by ARGS." (LaTeX-insert-environment environment) - (save-excursion - (LaTeX-find-matching-begin) - (end-of-line) - (TeX-parse-arguments args))) + (let ((pos (point-marker))) + (end-of-line 0) + (TeX-parse-arguments args) + (goto-char pos))) ;;; Item hooks @@ -1197,48 +1197,27 @@ This is necessary since index entries may contain commands and stuff.") (1 2 3) LaTeX-auto-optional) (,(concat "\\\\\\(?:new\\|provide\\)command\\*?{?\\\\\\(" token "+\\)}?\\[\\([0-9]+\\)\\]") (1 2) LaTeX-auto-arguments) - (,(concat "\\\\\\(?:new\\|provide\\)command\\*?{?\\\\\\(" token "+\\)}?") - 1 TeX-auto-symbol) + (,(concat "\\\\\\(?:new\\|provide\\)command\\*?{?\\\\\\(" token "+\\)}?") 1 TeX-auto-symbol) (,(concat "\\\\newenvironment\\*?{?\\(" token "+\\)}?\\[\\([0-9]+\\)\\]\\[") 1 LaTeX-auto-environment) (,(concat "\\\\newenvironment\\*?{?\\(" token "+\\)}?\\[\\([0-9]+\\)\\]") (1 2) LaTeX-auto-env-args) - (,(concat "\\\\newenvironment\\*?{?\\(" token "+\\)}?") - 1 LaTeX-auto-environment) + (,(concat "\\\\newenvironment\\*?{?\\(" token "+\\)}?") 1 LaTeX-auto-environment) (,(concat "\\\\newtheorem{\\(" token "+\\)}") 1 LaTeX-auto-environment) ("\\\\input{\\(\\.*[^#}%\\\\\\.\n\r]+\\)\\(\\.[^#}%\\\\\\.\n\r]+\\)?}" 1 TeX-auto-file) ("\\\\include{\\(\\.*[^#}%\\\\\\.\n\r]+\\)\\(\\.[^#}%\\\\\\.\n\r]+\\)?}" 1 TeX-auto-file) - (, (concat "\\\\bibitem{\\(" token "[^, \n\r\t%\"#'()={}]*\\)}") - 1 LaTeX-auto-bibitem) + (, (concat "\\\\bibitem{\\(" token "[^, \n\r\t%\"#'()={}]*\\)}") 1 LaTeX-auto-bibitem) (, (concat "\\\\bibitem\\[[^][\n\r]+\\]{\\(" token "[^, \n\r\t%\"#'()={}]*\\)}") 1 LaTeX-auto-bibitem) - ("\\\\bibliography{\\([^#}\\\\\n\r]+\\)}" 1 LaTeX-auto-bibliography) - ("\\\\addbibresource\\(?:\\[[^]]+\\]\\)?{\\([^#}\\\\\n\r\.]+\\)\\..+}" - 1 LaTeX-auto-bibliography) - ("\\\\add\\(?:global\\|section\\)bib\\(?:\\[[^]]+\\]\\)?{\\([^#}\\\\\n\r\.]+\\)\\(?:\\..+\\)?}" 1 LaTeX-auto-bibliography) - ("\\\\newrefsection\\[\\([^]]+\\)\\]" 1 LaTeX-split-bibs) - ("\\\\begin{refsection}\\[\\([^]]+\\)\\]" 1 LaTeX-split-bibs))) + ("\\\\bibliography{\\([^#}\\\\\n\r]+\\)}" 1 LaTeX-auto-bibliography))) LaTeX-auto-class-regexp-list LaTeX-auto-label-regexp-list LaTeX-auto-index-regexp-list LaTeX-auto-minimal-regexp-list) "List of regular expression matching common LaTeX macro definitions.") -(defun LaTeX-split-bibs (match) - "Extract bibliography resources from MATCH. -Split the string at commas and remove Biber file extensions." - (let ((bibs (TeX-split-string " *, *" (TeX-match-buffer match)))) - (dolist (bib bibs) - (LaTeX-add-bibliographies (replace-regexp-in-string - (concat "\\(?:\\." - (mapconcat 'regexp-quote - TeX-Biber-file-extensions - "\\|\\.") - "\\)") - "" bib))))) - (defun LaTeX-auto-prepare () "Prepare for LaTeX parsing." (setq LaTeX-auto-arguments nil @@ -1252,47 +1231,23 @@ Split the string at commas and remove Biber file extensions." (defun LaTeX-listify-package-options (options) "Return a list from a comma-separated string of package OPTIONS. The input string may include LaTeX comments and newlines." - ;; We jump through all those hoops and don't just use `split-string' - ;; or the like in order to be able to deal with key=value package - ;; options which can look like this: "pdftitle={A Perfect Day}, - ;; colorlinks=false" - (let (opts match start) - (with-temp-buffer - (set-syntax-table LaTeX-mode-syntax-table) - (insert options) - (newline) ; So that the last entry can be found. - (goto-char (point-min)) - (setq start (point)) - (while (re-search-forward "[{ ,%\n\r]" nil t) - (setq match (match-string 0)) - (cond - ;; Step over groups. (Let's hope nobody uses escaped braces.) - ((string= match "{") - (up-list)) - ;; Get rid of whitespace. - ((string= match " ") - (delete-region (1- (point)) - (save-excursion - (skip-chars-forward " ") - (point)))) - ;; Add entry to output. - ((or (string= match ",") (= (point) (point-max))) - (add-to-list 'opts (buffer-substring-no-properties - start (1- (point))) t) - (setq start (point))) - ;; Get rid of comments. - ((string= match "%") - (delete-region (1- (point)) - (line-beginning-position 2))) - ;; Get rid of newlines. - ((or (string= match "\n") (string= match "\r")) - (delete-backward-char 1))))) + ;; FIXME: Parse key=value options like "pdftitle={A Perfect + ;; Day},colorlinks=false" correctly. When this works, the check for + ;; "=" can be removed again. + (let (opts) + (dolist (elt (TeX-split-string "\\(,\\|%[^\n\r]*[\n\r]\\)+" + options)) + (unless (string-match "=" elt) + ;; Strip whitespace. + (dolist (item (TeX-split-string "[ \t\r\n]+" elt)) + (unless (string= item "") + (add-to-list 'opts item))))) opts)) (defun LaTeX-auto-cleanup () "Cleanup after LaTeX parsing." - ;; Cleanup BibTeX/Biber files + ;; Cleanup BibTeX files (setq LaTeX-auto-bibliography (apply 'append (mapcar (lambda (arg) (TeX-split-string "," arg)) @@ -1428,12 +1383,6 @@ regenerated by the respective menu filter." (setq LaTeX-environment-menu nil) (setq LaTeX-environment-modify-menu nil)) -;;; Biber support - -(defvar LaTeX-using-Biber nil - "Used to track whether Biber is in use.") -(make-variable-buffer-local 'LaTeX-using-Biber) - ;;; BibTeX ;;;###autoload @@ -1648,7 +1597,6 @@ string." ("dinbrief") ("foils") ("letter") - ("memoir") ("minimal") ("prosper") ("report") @@ -1688,8 +1636,7 @@ OPTIONAL and IGNORE are ignored." (defun LaTeX-arg-usepackage (optional) "Insert arguments to usepackage. OPTIONAL is ignored." - (let ((TeX-file-extensions '("sty")) - (TeX-input-file-search t)) + (let ((TeX-file-extensions '("sty"))) (TeX-arg-input-file nil "Package") (save-excursion (search-backward-regexp "{\\(.*\\)}") @@ -1724,51 +1671,9 @@ OPTIONAL is ignored." (mapc 'TeX-run-style-hooks (LaTeX-listify-package-options options)) (TeX-argument-insert options t)))))) -(defcustom LaTeX-search-files-type-alist - '((texinputs "${TEXINPUTS.latex}" ("tex/generic/" "tex/latex/") - TeX-file-extensions) - (docs "${TEXDOCS}" ("doc/") TeX-doc-extensions) - (graphics "${TEXINPUTS}" ("tex/") LaTeX-includegraphics-extensions) - (bibinputs "${BIBINPUTS}" ("bibtex/bib/") BibTeX-file-extensions) - (bstinputs "${BSTINPUTS}" ("bibtex/bst/") BibTeX-style-extensions) - (biberinputs "${BIBINPUTS}" ("bibtex/bib/") TeX-Biber-file-extensions)) - "Alist of filetypes with locations and file extensions. -Each element of the alist consists of a symbol expressing the -filetype, a variable which can be expanded on kpathsea-based -systems into the directories where files of the given type -reside, a list of absolute directories, relative directories -below the root of a TDS-compliant TeX tree or a list of variables -with either type of directories as an alternative for -non-kpathsea-based systems and a list of extensions to be matched -upon a file search. Note that the directories have to end with a -directory separator. - -Reset the mode for a change of this variable to take effect." - :group 'TeX-file - :type '(alist :key-type symbol - :value-type - (group (string :tag "Kpathsea variable") - (choice :tag "Directories" - (repeat :tag "TDS subdirectories" string) - (repeat :tag "Absolute directories" directory) - (repeat :tag "Variables" variable)) - (choice :tag "Extensions" - variable (repeat string))))) - -(defcustom TeX-arg-input-file-search t - "If `TeX-arg-input-file' should search for files. -If the value is t, files in TeX's search path are searched for -and provided for completion. The file name is then inserted -without directory and extension. If the value is nil, the file -name can be specified manually and is inserted with a path -relative to the directory of the current buffer's file and with -extension. If the value is `ask', you are asked for the method -to use every time `TeX-arg-input-file' is called." - :group 'LaTeX-macro - :type '(choice (const t) (const nil) (const ask))) - (defvar TeX-global-input-files nil "List of the non-local TeX input files. + Initialized once at the first time you prompt for an input file. May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.") @@ -1778,32 +1683,28 @@ If OPTIONAL is non-nil, insert the resulting value as an optional argument, otherwise as a mandatory one. PROMPT is the prompt, LOCAL is a flag. If the flag is set, only complete with local files." - (let ((search (if (eq TeX-arg-input-file-search 'ask) - (not (y-or-n-p "Find file yourself? ")) - TeX-arg-input-file-search)) - file style) - (if search - (progn - (unless (or TeX-global-input-files local) - (message "Searching for files...") - (setq TeX-global-input-files - (mapcar 'list (TeX-search-files-by-type - 'texinputs 'global t t)))) - (setq file (completing-read - (TeX-argument-prompt optional prompt "File") - (TeX-delete-dups-by-car - (append (mapcar 'list (TeX-search-files-by-type - 'texinputs 'local t t)) - (unless local - TeX-global-input-files)))) - style file)) - (setq file (read-file-name - (TeX-argument-prompt optional prompt "File") nil "")) - (unless (string-equal file "") - (setq file (file-relative-name file))) - (setq style (file-name-sans-extension (file-name-nondirectory file)))) - (unless (string-equal "" style) - (TeX-run-style-hooks style)) + (unless (or TeX-global-input-files local) + (message "Searching for files...") + (setq TeX-global-input-files + (mapcar 'list (TeX-search-files (append TeX-macro-private + TeX-macro-global) + TeX-file-extensions t t)))) + (let ((file (if TeX-check-path + (completing-read + (TeX-argument-prompt optional prompt "File") + (TeX-delete-dups-by-car + (append (mapcar 'list + (TeX-search-files '("./") + TeX-file-extensions + t t)) + (unless local + TeX-global-input-files)))) + (read-file-name + (TeX-argument-prompt optional prompt "File"))))) + (if (null file) + (setq file "")) + (if (not (string-equal "" file)) + (TeX-run-style-hooks file)) (TeX-argument-insert file optional))) (defvar BibTeX-global-style-files nil @@ -1820,50 +1721,44 @@ string." (message "Searching for BibTeX styles...") (or BibTeX-global-style-files (setq BibTeX-global-style-files - (mapcar 'list (TeX-search-files-by-type 'bstinputs 'global t t)))) + (mapcar 'list + (TeX-search-files (append TeX-macro-private + TeX-macro-global) + BibTeX-style-extensions t t)))) + (TeX-argument-insert (completing-read (TeX-argument-prompt optional prompt "BibTeX style") - (append (mapcar 'list (TeX-search-files-by-type - 'bstinputs 'local t t)) + (append (mapcar 'list + (TeX-search-files '("./") + BibTeX-style-extensions + t t)) BibTeX-global-style-files)) optional)) (defvar BibTeX-global-files nil "Association list of BibTeX files. -Initialized once at the first time you prompt for a BibTeX file. -May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.") - -(defvar TeX-Biber-global-files nil - "Association list of Biber files. - -Initialized once at the first time you prompt for an Biber file. +Initialized once at the first time you prompt for an BibTeX file. May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.") (defun TeX-arg-bibliography (optional &optional prompt) - "Prompt for a BibTeX or Biber database file. + "Prompt for a BibTeX database file. If OPTIONAL is non-nil, insert the resulting value as an optional argument, otherwise as a mandatory one. Use PROMPT as the prompt string." - (let (name files inputs styles) - (if LaTeX-using-Biber - (progn - (setq name "Biber" - files 'TeX-Biber-global-files - inputs 'biberinputs)) - (setq name "BibTeX" - files 'BibTeX-global-files - inputs 'bibinputs)) - (message "Searching for %s files..." name) - (or (symbol-value files) - (set files (mapcar 'list (TeX-search-files-by-type - 'biberinputs 'global t t)))) - (setq styles (multi-prompt - "," t - (TeX-argument-prompt optional prompt (concat name " files")) - (append (mapcar 'list (TeX-search-files-by-type - inputs 'local t t)) - (symbol-value files)))) + (message "Searching for BibTeX files...") + (or BibTeX-global-files + (setq BibTeX-global-files + (mapcar 'list (TeX-search-files nil BibTeX-file-extensions t t)))) + + (let ((styles (multi-prompt + "," t + (TeX-argument-prompt optional prompt "BibTeX files") + (append (mapcar 'list + (TeX-search-files '("./") + BibTeX-file-extensions + t t)) + BibTeX-global-files)))) (apply 'LaTeX-add-bibliographies styles) (TeX-argument-insert (mapconcat 'identity styles ",") optional))) @@ -2034,7 +1929,7 @@ alist. The car of each element should be a string representing a key and the optional cdr should be a list with strings to be used as values for the key." (let ((options (multi-prompt-key-value - (TeX-argument-prompt optional "Options (k=v)" nil) + (TeX-argument-prompt optional "Options" nil) (if (symbolp key-val-alist) (eval key-val-alist) key-val-alist)))) @@ -2146,22 +2041,10 @@ non-parenthetical delimiters, like \\verb+foo+, are recognized." (/= (point) (line-beginning-position)))))) ;; Search forward for the macro end, unless we failed to find a start (unless (bolp) - (let* ((beg (1- (point))) - (macro-end (match-end 0)) - ;; XXX: Here we assume we are dealing with \verb which - ;; expects the delimiter right behind the command. - ;; However, \lstinline can also cope with whitespace as - ;; well as an optional argument after the command. - (delimiter (buffer-substring-no-properties - macro-end (1+ macro-end)))) - ;; Heuristic: If an opening brace is encountered, search for - ;; both the opening and the closing brace as an end marker. - ;; Like that the function should work for \verb|...| as well - ;; as for \url{...}. - (when (string= delimiter TeX-grop) - (setq delimiter (concat delimiter TeX-grcl))) - (goto-char (1+ macro-end)) - (skip-chars-forward (concat "^" delimiter)) + (let ((beg (1- (point)))) + (goto-char (1+ (match-end 0))) + (skip-chars-forward (concat "^" (buffer-substring-no-properties + (1- (point)) (point)))) (when (<= orig (point)) (cons beg (1+ (point))))))))) @@ -2976,8 +2859,8 @@ space does not end a sentence, so don't break a line there." (unless (or (bolp) ;; Comment starters and whitespace. (TeX-looking-at-backward - (concat "^\\([ \t]*" TeX-comment-start-regexp "+\\)*" - "[ \t]*") + (concat "^\\([ \t]*" TeX-comment-start-regexp + "+\\)+[ \t]*") (line-beginning-position))) (LaTeX-fill-newline))))) ;; Leave point after final newline. @@ -3231,7 +3114,6 @@ space does not end a sentence, so don't break a line there." ((string= match-string "$$") "$$") (t (concat TeX-esc "]"))) (point-max) t) - (skip-chars-forward "^ \n") (point)) (line-beginning-position)) fill-column))) @@ -4436,7 +4318,10 @@ use \\[customize]." (read-kbd-macro LaTeX-math-abbrev-prefix) LaTeX-math-abbrev-prefix)) -(defvar LaTeX-math-keymap (make-sparse-keymap) +(defvar LaTeX-math-keymap + (let ((map (make-sparse-keymap))) + (define-key map (LaTeX-math-abbrev-prefix) 'self-insert-command) + map) "Keymap used for `LaTeX-math-mode' commands.") (defvar LaTeX-math-menu @@ -4509,10 +4394,7 @@ the sequence by initializing this variable.") (list menu (vector (concat prefix value) name t)) (vector menu name t)) - (cdr parent))))))))) - ;; Make the math prefix char available if it has not been used as a prefix. - (unless (lookup-key map (LaTeX-math-abbrev-prefix)) - (define-key map (LaTeX-math-abbrev-prefix) 'self-insert-command))) + (cdr parent)))))))))) (define-minor-mode LaTeX-math-mode "A minor mode with easy access to TeX math macros. @@ -5019,8 +4901,6 @@ This happens when \\left is inserted." :type 'hook :group 'LaTeX) -(TeX-abbrev-mode-setup latex-mode) - ;;;###autoload (add-to-list 'auto-mode-alist '("\\.drv\\'" . latex-mode)) @@ -5053,8 +4933,6 @@ of `LaTeX-mode-hook'." filladapt-mode) (turn-off-filladapt-mode))) -(TeX-abbrev-mode-setup doctex-mode) - ;;;###autoload (add-to-list 'auto-mode-alist '("\\.dtx\\'" . doctex-mode)) @@ -5063,7 +4941,6 @@ of `LaTeX-mode-hook'." "Major mode in AUCTeX for editing .dtx files derived from `LaTeX-mode'. Runs `LaTeX-mode', sets a few variables and runs the hooks in `docTeX-mode-hook'." - :abbrev-table doctex-mode-abbrev-table (setq major-mode 'doctex-mode) (set (make-local-variable 'LaTeX-insert-into-comments) t) (set (make-local-variable 'LaTeX-syntactic-comments) t) @@ -5135,8 +5012,6 @@ i.e. you do _not_ have to cater for this yourself by adding \\\\' or $." (make-local-variable 'indent-line-function) (setq indent-line-function 'LaTeX-indent-line) - (setq local-abbrev-table latex-mode-abbrev-table) - ;; Filling (make-local-variable 'paragraph-ignore-fill-prefix) (setq paragraph-ignore-fill-prefix t) @@ -5176,8 +5051,6 @@ i.e. you do _not_ have to cater for this yourself by adding \\\\' or $." (setq TeX-verbatim-p-function 'LaTeX-verbatim-p) (setq TeX-search-forward-comment-start-function 'LaTeX-search-forward-comment-start) - (set (make-local-variable 'TeX-search-files-type-alist) - LaTeX-search-files-type-alist) (make-local-variable 'LaTeX-item-list) (setq LaTeX-item-list '(("description" . LaTeX-item-argument) @@ -5326,7 +5199,6 @@ i.e. you do _not_ have to cater for this yourself by adding \\\\' or $." '("nocite" TeX-arg-cite) '("bibliographystyle" TeX-arg-bibstyle) '("bibliography" TeX-arg-bibliography) - '("addbibresource" TeX-arg-bibliography) '("footnote" (TeX-arg-conditional TeX-arg-footnote-number-p ([ "Number" ]) nil) t) @@ -5339,8 +5211,6 @@ i.e. you do _not_ have to cater for this yourself by adding \\\\' or $." '("setlength" TeX-arg-macro "Length") '("addtolength" TeX-arg-macro "Length") '("settowidth" TeX-arg-macro t) - '("settoheight" TeX-arg-macro t) - '("settodepth" TeX-arg-macro t) '("\\" [ "Space" ]) '("\\*" [ "Space" ]) '("hyphenation" t) @@ -5387,11 +5257,11 @@ i.e. you do _not_ have to cater for this yourself by adding \\\\' or $." '("include" (TeX-arg-input-file "File" t)) '("includeonly" t) '("input" TeX-arg-input-file) - '("addcontentsline" - (TeX-arg-eval completing-read "File: " '(("toc") ("lof") ("lot"))) - (TeX-arg-eval completing-read "Numbering style: " LaTeX-section-list) t) - '("addtocontents" - (TeX-arg-eval completing-read "File: " '(("toc") ("lof") ("lot"))) t) + '("addcontentsline" TeX-arg-file + (TeX-arg-eval + completing-read "Numbering style: " LaTeX-section-list) + t) + '("addtocontents" TeX-arg-file t) '("typeout" t) '("typein" [ TeX-arg-define-macro ] t) '("verb" TeX-arg-verb) @@ -5419,9 +5289,8 @@ i.e. you do _not_ have to cater for this yourself by adding \\\\' or $." "clearpage" "cleardoublepage" "twocolumn" "onecolumn" "maketitle" "tableofcontents" "listoffigures" "listoftables" - '("tiny" -1) '("scriptsize" -1) '("footnotesize" -1) '("small" -1) - '("normalsize" -1) '("large" -1) '("Large" -1) '("LARGE" -1) '("huge" -1) - '("Huge" -1) + "tiny" "scriptsize" "footnotesize" "small" + "normalsize" "large" "Large" "LARGE" "huge" "Huge" "pounds" "copyright" "hfil" "hfill" "vfil" "vfill" "hrulefill" "dotfill" "indent" "noindent" "today" @@ -5477,7 +5346,6 @@ i.e. you do _not_ have to cater for this yourself by adding \\\\' or $." [ "Number of arguments" ] [ "Default value for first argument" ] t) '("usepackage" LaTeX-arg-usepackage) '("RequirePackage" LaTeX-arg-usepackage) - '("ProvidesPackage" "Name" [ "Version" ]) '("documentclass" TeX-arg-document))) (TeX-add-style-hook "latex2e" @@ -5522,7 +5390,6 @@ i.e. you do _not_ have to cater for this yourself by adding \\\\' or $." 'LaTeX-imenu-create-index-function) (use-local-map LaTeX-mode-map) - ;; Calling `easy-menu-add' may result in the menu filters being ;; executed which call `TeX-update-style'. So this is placed very ;; late in mode initialization to assure that all relevant variables