changeset 92449:3db1228ead22

(latex-mode): Remove % from paragraph-separate so that M-q can fill comments. (tex-executable-exists-p, tex-compile): Extend with special syntax for commands implemented in elisp. (tex-compile-commands): Add an entry to use doc-view for pdf files. (tex-format-cmd): New function. (tex-compile): Use it to let the user specify default arguments. (tex-cmd-bibtex-args): New var. (tex-cmd-doc-view): New function.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Mon, 03 Mar 2008 13:55:41 +0000
parents cbb45cf56a18
children 235b5ef31f41
files lisp/ChangeLog lisp/textmodes/tex-mode.el
diffstat 2 files changed, 65 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/ChangeLog	Mon Mar 03 11:51:15 2008 +0000
+++ b/lisp/ChangeLog	Mon Mar 03 13:55:41 2008 +0000
@@ -1,3 +1,15 @@
+2008-03-03  Stefan Monnier  <monnier@iro.umontreal.ca>
+
+	* textmodes/tex-mode.el (latex-mode): Remove % from paragraph-separate
+	so that M-q can fill comments.
+	(tex-executable-exists-p, tex-compile): Extend with special syntax for
+	commands implemented in elisp.
+	(tex-compile-commands): Add an entry to use doc-view for pdf files.
+	(tex-format-cmd): New function.
+	(tex-compile): Use it to let the user specify default arguments.
+	(tex-cmd-bibtex-args): New var.
+	(tex-cmd-doc-view): New function.
+
 2008-03-03  Juanma Barranquero  <lekktu@gmail.com>
 
 	* faces.el (face-spec-set): Fix typos in docstring.
--- a/lisp/textmodes/tex-mode.el	Mon Mar 03 11:51:15 2008 +0000
+++ b/lisp/textmodes/tex-mode.el	Mon Mar 03 13:55:41 2008 +0000
@@ -1042,7 +1042,7 @@
 		"\\>\\|\\\\[a-z]*" (regexp-opt '("space" "skip" "page") t)
 		"\\>\\)"))
   (setq paragraph-separate
-	(concat "[\f%]\\|[ \t]*\\($\\|"
+	(concat "[\f]\\|[ \t]*\\($\\|"
 		"\\\\[][]\\|"
 		"\\\\" (regexp-opt (append
 				    (mapcar 'car latex-section-alist)
@@ -1785,6 +1785,7 @@
 		     (shell-quote-argument tex-start-commands)) " %f")
      t "%r.dvi")
     ("xdvi %r &" "%r.dvi")
+    ("\\doc-view \"%r.pdf\"" "%r.pdf")
     ("xpdf %r.pdf &" "%r.pdf")
     ("gv %r.ps &" "%r.ps")
     ("yap %r &" "%r.dvi")
@@ -1900,11 +1901,11 @@
 	 (save-excursion
 	   (goto-char (point-max))
 	   (and (re-search-backward
-                 (concat
-                  "(see the transcript file for additional information)"
-                  "\\|^Output written on .*"
-                  (regexp-quote (file-name-nondirectory file))
-                  " (.*)\\.") nil t)
+                 (concat "(see the transcript file for additional information)"
+                         "\\|^Output written on .*"
+                         (regexp-quote (file-name-nondirectory file))
+                         " (.*)\\.")
+                 nil t)
 		(> (save-excursion
 		     (or (re-search-backward "\\[[0-9]+\\]" nil t)
 			 (point-min)))
@@ -1945,11 +1946,15 @@
 (defvar tex-executable-cache nil)
 (defun tex-executable-exists-p (name)
   "Like `executable-find' but with a cache."
-  (let ((cache (assoc name tex-executable-cache)))
-    (if cache (cdr cache)
-      (let ((executable (executable-find name)))
-	(push (cons name executable) tex-executable-cache)
-	executable))))
+  (let ((f (and (string-match "^\\\\\\([^ \t\n]+\\)" name)
+                (intern-soft (concat "tex-cmd-" (match-string 1 name))))))
+    (if (fboundp f)
+        f
+      (let ((cache (assoc name tex-executable-cache)))
+        (if cache (cdr cache)
+          (let ((executable (executable-find name)))
+            (push (cons name executable) tex-executable-cache)
+            executable))))))
 
 (defun tex-command-executable (cmd)
   (let ((s (if (stringp cmd) cmd (eval (car cmd)))))
@@ -1968,6 +1973,24 @@
       (when (and (eq in t) (stringp out))
 	(not (tex-uptodate-p (format-spec out fspec)))))))
 
+(defcustom tex-cmd-bibtex-args "--min-crossref=100"
+  "Extra args to pass to `bibtex' by default."
+  :type 'string)
+
+(defun tex-format-cmd (format fspec)
+  "Like `format-spec' but adds user-specified args to the command.
+Only applies the FSPEC to the args part of FORMAT."
+  (if (not (string-match "\\([^ /\\]+\\) " format))
+      (format-spec format fspec)
+    (let* ((prefix (substring format 0 (match-beginning 0)))
+           (cmd (match-string 1 format))
+           (args (substring format (match-end 0)))
+           (sym (intern-soft (format "tex-cmd-%s-args" cmd)))
+           (extra-args (and sym (symbol-value sym))))
+      (concat prefix cmd
+              (if extra-args (concat " " extra-args))
+              " " (format-spec args fspec)))))
+         
 (defun tex-compile-default (fspec)
   "Guess a default command given the `format-spec' FSPEC."
   ;; TODO: Learn to do latex+dvips!
@@ -2038,7 +2061,10 @@
 	  ;; The history command was already applied to the same file,
 	  ;; so just reuse it.
 	  hist-cmd
-	(if cmds (format-spec (caar cmds) fspec))))))
+	(if cmds (tex-format-cmd (caar cmds) fspec))))))
+
+(defun tex-cmd-doc-view (file)
+  (pop-to-buffer (find-file-noselect file)))
 
 (defun tex-compile (dir cmd)
   "Run a command CMD on current TeX buffer's file in DIR."
@@ -2056,14 +2082,24 @@
 	   (completing-read
 	    (format "Command [%s]: " (tex-summarize-command default))
 	    (mapcar (lambda (x)
-		      (list (format-spec (eval (car x)) fspec)))
+		      (list (tex-format-cmd (eval (car x)) fspec)))
 		    tex-compile-commands)
 	    nil nil nil 'tex-compile-history default))))
   (save-some-buffers (not compilation-ask-about-save) nil)
-  (if (tex-shell-running)
-      (tex-kill-job)
-    (tex-start-shell))
-  (tex-send-tex-command cmd dir))
+  (let ((f (and (string-match "^\\\\\\([^ \t\n]+\\)" cmd)
+                (intern-soft (concat "tex-cmd-" (match-string 1 cmd))))))
+    (if (functionp f)
+        (condition-case nil
+            (let ((default-directory dir))
+              (apply f (split-string-and-unquote
+                        (substring cmd (match-end 0)))))
+          (wrong-number-of-arguments
+           (error "Wrong number of arguments to %s"
+                  (substring (symbol-name f) 8))))
+      (if (tex-shell-running)
+          (tex-kill-job)
+        (tex-start-shell))
+      (tex-send-tex-command cmd dir))))
 
 (defun tex-start-tex (command file &optional dir)
   "Start a TeX run, using COMMAND on FILE."