? biber.patch Index: font-latex.el =================================================================== RCS file: /sources/auctex/auctex/font-latex.el,v retrieving revision 5.194 diff -u -r5.194 font-latex.el --- font-latex.el 4 Jul 2012 06:11:58 -0000 5.194 +++ font-latex.el 21 Jul 2012 02:33:56 -0000 @@ -291,8 +291,36 @@ ("arabic" "{") ("roman" "{") ("Roman" "{") ("alph" "{") ("Alph" "{") ("fnsymbol" "{")) 'font-lock-variable-name-face 2 command) + ("biblatexnoarg" + ("newrefsegment" "mancite" "pno" "ppno" "nopp" "psq" "psqq") + 'font-lock-variable-name-face 2 noarg) + ("biblatex" + (("newrefsection" "[") ("ExecuteBibliographyOptions" "[{") + ("printbibliography" "[") ("printshorthands" "[") ("printbibheading" "[") + ("addbibresource" "[{") ("addglobalbib" "[{") ("addsectionbib" "[{") + ("bibbysection" "[") ("bibbysegment" "[") ("bibbycategory" "[") + ("DeclareBibliographyCategory" "{") ("addtocategory" "{{") ("defbibenvironment" "{{{{") + ("defbibheading" "{[{") ("defbibnote" "{{") ("defbibfilter" "{{") ("defbibcheck" "{{") + ("defbibentryset" "{{") ("Cite" "[[{") ("parencite" "*[[{") ("Parencite" "[[{") + ("footcite" "[[{") ("footcitetext" "[[{") ("textcite" "[[{") ("Textcite" "[[{") + ("smartcite" "[[{") ("Smartcite" "[[{") ("supercite" "{") ("autocite" "*[{{") + ("Autocite" "*[{{") ("citeauthor" "[{{") ("Citeauthor" "[{{") ("citetitle" "*[{{") + ("citeyear" "*[[{") ("citedate" "*[[{") ("citeurl" "[[{") ("parentext" "{") + ("brackettext" "{") ("fullcite" "[[{") ("fullfootcite" "[[{") ("volcite" "[{[[") + ("Volcite" "[{[[") ("pvolcite" "[{[[") ("Pvolcite" "[{[[") ("fvolcite" "[{[[") + ("ftvolcite" "[{[[") ("svolcite" "[{[[") ("Svolcite" "[{[[") ("tvolcite" "[{[[") + ("Tvolcite" "[{[[") ("avolcite" "[{[[") ("Avolcite" "[{[[") ("notecite" "[[{") + ("Notecite" "[[{") ("pnotecite" "[[{") ("Pnotecite" "[[{") ("fnotecite" "[[{") + ("citename" "[[{[{") ("citelist" "[[{[{") ("citefield" "[[{[{") ("citereset" "*") + ("RN" "{") ("Rn" "{") ("DefineBibliographyStrings" "{{") ("DefineBibliographyExtras" "{{") + ("UndefineBibliographyExtras" "{{") ("DefineHyphenationExceptions" "{{") + ("NewBibliographyString" "{") ("autocites" "(([[{") ("Autocites" "(([[{") + ("cites" "(([[{") ("Cites" "(([[{") ("parencites" "(([[{") ("Parencites" "(([[{") + ("footcites" "(([[{") ("footcitetexts" "(([[{") ("smartcites" "(([[{") + ("Smartcites" "(([[{") ("textcites" "(([[{") ("Textcites" "(([[{") ("supercites" "(([[{")) + 'font-lock-constant-face 2 command) ("reference" - (("nocite" "{") ("cite" "[{") ("label" "{") ("pageref" "{") + (("nocite" "*{") ("cite" "*[[{") ("label" "{") ("pageref" "{") ("vref" "{") ("eqref" "{") ("ref" "{") ("include" "{") ("input" "{") ("bibliography" "{") ("index" "{") ("glossary" "{") ("footnote" "[{") ("footnotemark" "[") ("footnotetext" "[{")) @@ -795,7 +823,7 @@ "Add KEYWORDS to CLASS. KEYWORDS is a list of keywords or keywords with syntax specs. CLASS corresponds to a keyword class and can be one of the -symbols 'warning, 'variable, 'reference, 'function, sectioning-0, +symbols 'warning, 'variable, 'reference, 'biblatex, 'function, sectioning-0, 'sectioning-1, 'sectioning-2, 'sectioning-3, 'sectioning-4, 'sectioning-5, 'slide-title, 'textual, 'bold-command, 'italic-command, 'math-command, 'type-command, 'bold-declaration, Index: latex.el =================================================================== RCS file: /sources/auctex/auctex/latex.el,v retrieving revision 5.470 diff -u -r5.470 latex.el --- latex.el 7 Aug 2011 15:32:42 -0000 5.470 +++ latex.el 21 Jul 2012 02:33:58 -0000 @@ -1212,13 +1212,37 @@ (, (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))) + ("\\\\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) + ("backend=\\(biber\\)" 1 LaTeX-biber) + ("\\\\ExecuteBibliographyOptions\\(?:\\[[^]]+\\]\\)?{.*?backend=\\(biber\\)}" 1 LaTeX-using-Biber))) 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.") +;; Either the user has set a global use biber flag or we detect it from the file +(defun LaTeX-biber (match) + (if (or LaTeX-always-use-Biber + (string= "biber" (TeX-match-buffer match))) + (setq LaTeX-using-Biber t) + (setq LaTeX-using-Biber nil))) + +(defun LaTeX-split-bibs (match) + (let ((bibs (TeX-split-string " *, *" (TeX-match-buffer match)))) + (dolist (bib bibs) + (LaTeX-add-bibliographies (replace-regexp-in-string + (concat "\\(?:\\." + (mapconcat 'regexp-quote + BibTeX-Biber-file-extensions + "\\|\\.") + "\\)") + "" bib))))) + (defun LaTeX-auto-prepare () "Prepare for LaTeX parsing." (setq LaTeX-auto-arguments nil @@ -1248,7 +1272,7 @@ (defun LaTeX-auto-cleanup () "Cleanup after LaTeX parsing." - ;; Cleanup BibTeX files + ;; Cleanup BibTeX/Biber files (setq LaTeX-auto-bibliography (apply 'append (mapcar (lambda (arg) (TeX-split-string "," arg)) @@ -1384,6 +1408,12 @@ (setq LaTeX-environment-menu nil) (setq LaTeX-environment-modify-menu nil)) +;;; Biber support +;;; Need a variable to say if we're using biber - certain things need consitionalising on this + +(defvar LaTeX-using-Biber nil "Used to track whether we detected Biber in use") +(defvar LaTeX-always-use-Biber nil "Global override for biber usage") + ;;; BibTeX ;;;###autoload @@ -1679,7 +1709,7 @@ TeX-file-extensions) (docs "${TEXDOCS}" ("doc/") TeX-doc-extensions) (graphics "${TEXINPUTS}" ("tex/") LaTeX-includegraphics-extensions) - (bibinputs "${BIBINPUTS}" ("bibtex/bib/") BibTeX-file-extensions) + (bibinputs "${BIBINPUTS}" ("bibtex/bib/") BibTeX-Biber-file-extensions) (bstinputs "${BSTINPUTS}" ("bibtex/bst/") BibTeX-style-extensions)) "Alist of filetypes with locations and file extensions. Each element of the alist consists of a symbol expressing the @@ -1777,27 +1807,27 @@ BibTeX-global-style-files)) optional)) -(defvar BibTeX-global-files nil - "Association list of BibTeX files. +(defvar BibTeX-Biber-global-files nil + "Association list of BibTeX/Biber files. -Initialized once at the first time you prompt for an BibTeX file. +Initialized once at the first time you prompt for an BibTeX/Biber file. May be reset with `\\[universal-argument] \\[TeX-normal-mode]'.") (defun TeX-arg-bibliography (optional &optional prompt) - "Prompt for a BibTeX database file. + "Prompt for a BibTeX/Biber 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." - (message "Searching for BibTeX files...") - (or BibTeX-global-files - (setq BibTeX-global-files + (message "Searching for BibTeX/Biber files...") + (or BibTeX-Biber-global-files + (setq BibTeX-Biber-global-files (mapcar 'list (TeX-search-files-by-type 'bibinputs 'global t t)))) (let ((styles (multi-prompt "," t - (TeX-argument-prompt optional prompt "BibTeX files") + (TeX-argument-prompt optional prompt "BibTeX/Biber files") (append (mapcar 'list (TeX-search-files-by-type 'bibinputs 'local t t)) - BibTeX-global-files)))) + BibTeX-Biber-global-files)))) (apply 'LaTeX-add-bibliographies styles) (TeX-argument-insert (mapconcat 'identity styles ",") optional))) @@ -5260,6 +5290,7 @@ '("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) Index: tex-buf.el =================================================================== RCS file: /sources/auctex/auctex/tex-buf.el,v retrieving revision 1.286 diff -u -r1.286 tex-buf.el --- tex-buf.el 20 Mar 2011 08:59:15 -0000 1.286 +++ tex-buf.el 21 Jul 2012 02:33:59 -0000 @@ -76,7 +76,7 @@ (defun TeX-save-document (name) "Save all files belonging to the current document. -Return non-nil if document need to be re-TeX'ed." +Return non-nil if document needs to be re-TeX'ed." (interactive (list (TeX-master-file))) (if (string-equal name "") (setq name (TeX-master-file))) @@ -366,37 +366,40 @@ command) (defun TeX-check-files (derived originals extensions) - "Check that DERIVED is newer than any of the ORIGINALS. + "Check if DERIVED is newer than any of the ORIGINALS. Try each original with each member of EXTENSIONS, in all directories -in `TeX-check-path'." - (let ((found nil) - (regexp (concat "\\`\\(" - (mapconcat (lambda (dir) - (regexp-quote - (expand-file-name - (file-name-as-directory dir)))) - TeX-check-path "\\|") - "\\).*\\(" - (mapconcat 'regexp-quote originals "\\|") - "\\)\\.\\(" - (mapconcat 'regexp-quote extensions "\\|") - "\\)\\'")) - (buffers (buffer-list))) +in `TeX-check-path'. Returns true if any of the ORIGINALS with any of the +EXTENSIONS are newer than DERIVED. Will prompt to save the buffer of any +ORIGINALS which are modified but not saved yet." + (let ((existingoriginals nil) + (found nil) + (buffers (buffer-list))) + (dolist (path (map 'list (lambda (dir) + (expand-file-name + (file-name-as-directory dir))) + TeX-check-path)) + (dolist (orig originals) + (dolist (ext extensions) + (let ((filepath (concat path orig "." ext))) + (if (file-exists-p filepath) + (setq existingoriginals (cons filepath existingoriginals))))))) (while buffers (let* ((buffer (car buffers)) - (name (buffer-file-name buffer))) - (setq buffers (cdr buffers)) - (if (and name (string-match regexp name)) - (progn - (and (buffer-modified-p buffer) - (or (not TeX-save-query) - (y-or-n-p (concat "Save file " - (buffer-file-name buffer) - "? "))) - (save-excursion (set-buffer buffer) (save-buffer))) - (if (file-newer-than-file-p name derived) - (setq found t)))))) - found)) + (name (buffer-file-name buffer))) + (setq buffers (cdr buffers)) + (if (and name (member name existingoriginals)) + (progn + (and (buffer-modified-p buffer) + (or (not TeX-save-query) + (y-or-n-p (concat "Save file " + (buffer-file-name buffer) + "? "))) + (save-excursion (set-buffer buffer) (save-buffer))))))) + (dolist (eo existingoriginals) + (if (file-newer-than-file-p eo derived) + (setq found t))) + found + )) (defcustom TeX-save-query t "*If non-nil, ask user for permission to save files before starting TeX." @@ -405,36 +408,43 @@ (defvar TeX-command-history nil) +;; Something to remember - if you are testing on a document with no content at all, +;; perhaps one with just \nocite{*} in it for testing Biber runs, no PDF file is created +;; by latex and so the first cond clause will match because (file-newer-than-p) returns +;; t when the second argument does not exist ... this has caused hours of pointless investigations +;; before ... (defun TeX-command-query (name) "Query the user for what TeX command to use." (let* ((default (cond ((if (string-equal name TeX-region) - (TeX-check-files (concat name "." (TeX-output-extension)) - (list name) - TeX-file-extensions) - (TeX-save-document (TeX-master-file))) - TeX-command-default) - ((and (memq major-mode '(doctex-mode latex-mode)) - (TeX-check-files (concat name ".bbl") - (mapcar 'car - (LaTeX-bibliography-list)) - BibTeX-file-extensions)) - ;; We should check for bst files here as well. - TeX-command-BibTeX) - ((TeX-process-get-variable name - 'TeX-command-next - TeX-command-Show)) - (TeX-command-Show))) - (completion-ignore-case t) - (answer (or TeX-command-force - (completing-read - (concat "Command: (default " default ") ") - (TeX-mode-specific-command-list major-mode) nil t - nil 'TeX-command-history)))) - ;; If the answer "latex" it will not be expanded to "LaTeX" + (TeX-check-files (concat name "." (TeX-output-extension)) + (list name) + TeX-file-extensions) + (TeX-save-document (TeX-master-file))) + TeX-command-default) + ((and (memq major-mode '(doctex-mode latex-mode)) + ;; Want to know if bib file is newer than .bbl + ;; We don't care whether the bib files are open in emacs + (TeX-check-files (concat name ".bbl") + (mapcar 'car + (LaTeX-bibliography-list)) + BibTeX-Biber-file-extensions)) + ;; We should check for bst files here as well. + (if LaTeX-using-Biber TeX-command-Biber TeX-command-BibTeX)) + ((TeX-process-get-variable name + 'TeX-command-next + TeX-command-Show)) + (TeX-command-Show))) + (completion-ignore-case t) + (answer (or TeX-command-force + (completing-read + (concat "Command: (default " default ") ") + (TeX-mode-specific-command-list major-mode) nil t + nil 'TeX-command-history)))) + ;; If the answer is "latex" it will not be expanded to "LaTeX" (setq answer (car-safe (TeX-assoc answer TeX-command-list))) (if (and answer - (not (string-equal answer ""))) - answer + (not (string-equal answer ""))) + answer default))) (defvar TeX-command-next nil @@ -673,6 +683,14 @@ process (TeX-synchronous-sentinel name file process)))) +(defun TeX-run-Biber (name command file) + "Create a process for NAME using COMMAND to format FILE with Biber." + (let ((process (TeX-run-command name command file))) + (setq TeX-sentinel-function 'TeX-Biber-sentinel) + (if TeX-process-asynchronous + process + (TeX-synchronous-sentinel name file process)))) + (defun TeX-run-compile (name command file) "Ignore first and third argument, start compile with second argument." (compile command)) @@ -940,17 +958,34 @@ (cond ((TeX-TeX-sentinel-check process name)) ((and (save-excursion (re-search-forward + "^Package biblatex Warning: Please (re)run Biber on the file" nil t)) + (with-current-buffer TeX-command-buffer + (and (LaTeX-bibliography-list) + (TeX-check-files (TeX-master-file "bbl") + (TeX-style-list) + (append TeX-file-extensions + BibTeX-Biber-file-extensions))))) + (message "%s%s" "You should run Biber to get citations right, " + (TeX-current-pages)) + (setq TeX-command-next (with-current-buffer TeX-command-buffer + TeX-command-Biber))) + ((and (save-excursion + (re-search-forward "^\\(?:LaTeX\\|Package natbib\\) Warning: Citation" nil t)) (with-current-buffer TeX-command-buffer (and (LaTeX-bibliography-list) (TeX-check-files (TeX-master-file "bbl") (TeX-style-list) (append TeX-file-extensions - BibTeX-file-extensions))))) + BibTeX-Biber-file-extensions))))) (message "%s%s" "You should run BibTeX to get citations right, " (TeX-current-pages)) (setq TeX-command-next (with-current-buffer TeX-command-buffer TeX-command-BibTeX))) + ((re-search-forward "^(biblatex)\\W+Page breaks have changed" nil t) + (message "%s%s" "You should run LaTeX again - page breaks have changed, " + (TeX-current-pages)) + (setq TeX-command-next TeX-command-default)) ((re-search-forward "^\\(?:LaTeX Warning: Label(s)\\|\ Package natbib Warning: Citation(s)\\)" nil t) (message "%s%s" "You should run LaTeX again to get references right, " @@ -1008,8 +1043,32 @@ "\\\\[TeX-recenter-output-buffer]"))) (t (message (concat "BibTeX finished successfully. " - "Run LaTeX again to get citations right.")))) - (setq TeX-command-next TeX-command-default)) + "Run LaTeX again to get citations right.")) + (setq TeX-command-next TeX-command-default)))) + +(defun TeX-Biber-sentinel (process name) + "Cleanup TeX output buffer after running Biber." + (goto-char (point-max)) + (cond + ((re-search-backward (concat + "^INFO - \\(WARNINGS\\|ERRORS\\): \\([0-9]+\\)") nil t) + (message (concat "Biber finished with %s %s. " + "Type `%s' to display output.") + (match-string 2) (downcase (match-string 1)) + (substitute-command-keys + "\\\\[TeX-recenter-output-buffer]")) + (setq TeX-command-next TeX-command-default)) + ((re-search-backward (concat + "^FATAL") nil t) + (message (concat "Biber had a fatal error and did not finish! " + "Type `%s' to display output.") + (substitute-command-keys + "\\\\[TeX-recenter-output-buffer]")) + (setq TeX-command-next TeX-command-Biber)) + (t + (message (concat "Biber finished successfully. " + "Run LaTeX again to get citations right.")) + (setq TeX-command-next TeX-command-default)))) ;;; Process Control Index: tex.el =================================================================== RCS file: /sources/auctex/auctex/tex.el,v retrieving revision 5.697 diff -u -r5.697 tex.el --- tex.el 22 Jun 2012 06:26:04 -0000 5.697 +++ tex.el 21 Jul 2012 02:34:02 -0000 @@ -135,6 +135,7 @@ TeX-run-TeX nil (context-mode) :help "Run ConTeXt until completion") ("BibTeX" "bibtex %s" TeX-run-BibTeX nil t :help "Run BibTeX") + ("Biber" "biber %s" TeX-run-Biber nil t :help "Run Biber") ,(if (or window-system (getenv "DISPLAY")) '("View" "%V" TeX-run-discard-or-function t t :help "Run Viewer") '("View" "dvi2tty -q -w 132 %s" TeX-run-command t t @@ -179,6 +180,8 @@ TeX-run-BibTeX: For BibTeX output. +TeX-run-Biber: For Biber output. + TeX-run-compile: Use `compile' to run the process. TeX-run-shell: Use `shell-command' to run the process. @@ -227,6 +230,7 @@ (function-item TeX-run-TeX) (function-item TeX-run-interactive) (function-item TeX-run-BibTeX) + (function-item TeX-run-Biber) (function-item TeX-run-compile) (function-item TeX-run-shell) (function-item TeX-run-discard) @@ -1781,6 +1785,12 @@ :type 'string) (make-variable-buffer-local 'TeX-command-BibTeX) +(defcustom TeX-command-Biber "Biber" + "*The name of the Biber entry in `TeX-command-list'." + :group 'TeX-command-name + :type 'string) + (make-variable-buffer-local 'TeX-command-Biber) + (defcustom TeX-command-Show "View" "*The default command to show (view or print) a TeX file. Must be the car of an entry in `TeX-command-list'." @@ -3293,7 +3303,7 @@ (TeX-strip-extension tex TeX-all-extensions t) ".el")))) ((TeX-match-extension tex (append TeX-file-extensions - BibTeX-file-extensions)) + BibTeX-Biber-file-extensions)) (save-excursion (set-buffer (let (enable-local-eval) (find-file-noselect tex))) @@ -3313,7 +3323,7 @@ (unless (file-directory-p TeX-auto-global) (make-directory TeX-auto-global)) (let ((TeX-file-extensions '("cls" "sty")) - (BibTeX-file-extensions nil)) + (BibTeX-Biber-file-extensions nil)) (mapc (lambda (macro) (TeX-auto-generate macro TeX-auto-global)) TeX-macro-global)) (byte-recompile-directory TeX-auto-global 0)) @@ -3628,8 +3638,8 @@ (make-variable-buffer-local 'TeX-output-extension) -(defcustom BibTeX-file-extensions '("bib") - "Valid file extensions for BibTeX files." +(defcustom BibTeX-Biber-file-extensions '("bib" "ris" "xml") + "Valid file extensions for BibTeX/Biber files." :group 'TeX-file-extension :type '(repeat (string :format "%v"))) @@ -3804,7 +3814,7 @@ '((texinputs "${TEXINPUTS}" ("tex/") TeX-file-extensions) (docs "${TEXDOCS}" ("doc/") TeX-doc-extensions) (graphics "${TEXINPUTS}" ("tex/") LaTeX-includegraphics-extensions) - (bibinputs "${BIBINPUTS}" ("bibtex/bib/") BibTeX-file-extensions) + (bibinputs "${BIBINPUTS}" ("bibtex/bib/") BibTeX-Biber-file-extensions) (bstinputs "${BSTINPUTS}" ("bibtex/bst/") BibTeX-style-extensions)) "Alist of filetypes with locations and file extensions. Each element of the alist consists of a symbol expressing the @@ -5161,7 +5171,7 @@ (if arg (setq TeX-style-hook-list nil BibTeX-global-style-files nil - BibTeX-global-files nil + BibTeX-Biber-global-files nil TeX-global-input-files nil)) (let ((TeX-auto-save t)) (if (buffer-modified-p)