"File name that \\[tex-print] prints.
Set by \\[tex-region], \\[tex-buffer], and \\[tex-file].")
-(easy-mmode-defsyntax tex-mode-syntax-table
- '((?% . "<")
- (?\n . ">")
- (?\f . ">")
- (?\C-@ . "w")
- (?' . "w")
- (?@ . "_")
- (?* . "_")
- (?\t . " ")
+(defvar tex-mode-syntax-table
+ (let ((st (make-syntax-table)))
+ (modify-syntax-entry ?% "<" st)
+ (modify-syntax-entry ?\n ">" st)
+ (modify-syntax-entry ?\f ">" st)
+ (modify-syntax-entry ?\C-@ "w" st)
+ (modify-syntax-entry ?' "w" st)
+ (modify-syntax-entry ?@ "_" st)
+ (modify-syntax-entry ?* "_" st)
+ (modify-syntax-entry ?\t " " st)
;; ~ is printed by TeX as a space, but it's semantics in the syntax
;; of TeX is not `whitespace' (i.e. it's just like \hspace{foo}).
- (?~ . ".")
- (?$ . "$$")
- (?\\ . "/")
- (?\" . ".")
- (?& . ".")
- (?_ . ".")
- (?^ . "."))
+ (modify-syntax-entry ?~ "." st)
+ (modify-syntax-entry ?$ "$$" st)
+ (modify-syntax-entry ?\\ "/" st)
+ (modify-syntax-entry ?\" "." st)
+ (modify-syntax-entry ?& "." st)
+ (modify-syntax-entry ?_ "." st)
+ (modify-syntax-entry ?^ "." st)
+ st)
"Syntax table used while in TeX mode.")
\f
;;;;
;; Like tex-insert-braces, but for LaTeX.
(defalias 'tex-latex-block 'latex-insert-block)
(define-skeleton latex-insert-block
- "Create a matching pair of lines \\begin[OPT]{NAME} and \\end{NAME} at point.
+ "Create a matching pair of lines \\begin{NAME} and \\end{NAME} at point.
Puts point on a blank line between them."
(let ((choice (completing-read (format "LaTeX block name [%s]: "
latex-block-default)
;;;; LaTeX syntax navigation
;;;;
+(defmacro tex-search-noncomment (&rest body)
+ "Execute BODY as long as it return non-nil and point is in a comment.
+Return the value returned by the last execution of BODY."
+ (declare (debug t))
+ (let ((res-sym (make-symbol "result")))
+ `(let (,res-sym)
+ (while
+ (and (setq ,res-sym (progn ,@body))
+ (save-excursion (skip-chars-backward "^\n%") (not (bolp)))))
+ ,res-sym)))
+
(defun tex-last-unended-begin ()
"Leave point at the beginning of the last `\\begin{...}' that is unended."
(condition-case nil
- (while (and (re-search-backward "\\\\\\(begin\\|end\\)\\s *{")
+ (while (and (tex-search-noncomment
+ (re-search-backward "\\\\\\(begin\\|end\\)\\s *{"))
(looking-at "\\\\end"))
(tex-last-unended-begin))
(search-failed (error "Couldn't find unended \\begin"))))
(defun tex-next-unmatched-end ()
"Leave point at the end of the next `\\end' that is unended."
- (while (and (re-search-forward "\\\\\\(begin\\|end\\)\\s *{[^}]+}")
+ (while (and (tex-search-noncomment
+ (re-search-forward "\\\\\\(begin\\|end\\)\\s *{[^}]+}"))
(save-excursion (goto-char (match-beginning 0))
(looking-at "\\\\begin")))
(tex-next-unmatched-end)))
(defvar tex-compile-commands
'(((concat "pdf" tex-command
- " " (shell-quote-argument tex-start-commands) " %f")
+ " " (if (< 0 (length tex-start-commands))
+ (shell-quote-argument tex-start-commands)) " %f")
t "%r.pdf")
((concat tex-command
- " " (shell-quote-argument tex-start-commands) " %f")
+ " " (if (< 0 (length tex-start-commands))
+ (shell-quote-argument tex-start-commands)) " %f")
t "%r.dvi")
("xdvi %r &" "%r.dvi")
("advi %r &" "%r.dvi")
"Return the relative name of the main file."
(let* ((file (or tex-main-file
;; Compatibility with AUCTeX.
- (and (boundp 'TeX-master) (stringp TeX-master)
- (set (make-local-variable 'tex-main-file) TeX-master))
+ (with-no-warnings
+ (when (and (boundp 'TeX-master) (stringp TeX-master))
+ (make-local-variable 'tex-main-file)
+ (setq tex-main-file TeX-master)))
;; Try to guess the main file.
(if (not buffer-file-name)
(error "Buffer is not associated with any file")
;; FIXME: Use time-stamps on files to decide the next op.
(interactive
(let* ((file (tex-main-file))
- (dir (prog1 (file-name-directory (expand-file-name file))
- (setq file (file-name-nondirectory file))))
+ (default-directory
+ (prog1 (file-name-directory (expand-file-name file))
+ (setq file (file-name-nondirectory file))))
(root (file-name-sans-extension file))
(fspec (list (cons ?r (comint-quote-filename root))
(cons ?f (comint-quote-filename file))))
(default (tex-compile-default fspec)))
- (list dir
+ (list default-directory
(completing-read
(format "Command [%s]: " (tex-summarize-command default))
(mapcar (lambda (x)
(defvar tex-indent-item tex-indent-basic)
(defvar tex-indent-item-re "\\\\\\(bib\\)?item\\>")
-(easy-mmode-defsyntax tex-latex-indent-syntax-table
- '((?$ . ".")
- (?\( . ".")
- (?\) . "."))
- "Syntax table used while computing indentation."
- :copy tex-mode-syntax-table)
+(defvar tex-latex-indent-syntax-table
+ (let ((st (make-syntax-table tex-mode-syntax-table)))
+ (modify-syntax-entry ?$ "." st)
+ (modify-syntax-entry ?\( "." st)
+ (modify-syntax-entry ?\) "." st)
+ st)
+ "Syntax table used while computing indentation.")
(defun latex-indent (&optional arg)
(if (and (eq (get-text-property (line-beginning-position) 'face)