(require 'tex-site)
(setq
tex-default-mode 'latex-mode
TeX-auto-save t
TeX-parse-self t)
(setq-default TeX-master nil)
(defun tex-indent-complete ()
"A special indent/complete function"
(interactive)
(if (save-excursion (skip-chars-backward " \t") (not (bolp)))
(hippie-expand 1)
(indent-for-tab-command)))
(add-hook 'LaTeX-mode-hook
(function (lambda ()
(turn-on-reftex)
(flyspell-mode t)
(ispell-change-dictionary "deutsch8")
(setq ispell-parser 'tex)
(turn-on-auto-fill)
(define-key LaTeX-mode-map [(return)] 'reindent-then-newline-and-indent)
(define-key LaTeX-mode-map [(tab)] 'tex-indent-complete)
(define-key LaTeX-mode-map [(f10)] 'TeX-next-error))))
(defvar kdvi-script "kdvi"
"*Name of start script for kdvi.")
(defun kdvi-jump-to-line ()
"Call kdvi-script to perform a `forward search' for current file and line number.
See contents of kdvi-script for details.
If AucTeX is used, the value of TeX-master-file is used as filename
for the master .dvi file; else, the return value of kdvi-master-file-name
is used (which see)."
(interactive)
(save-excursion
(save-restriction
(widen)
(beginning-of-line 1)
(let* ( (current-line (format "%d" (+ 1 (count-lines (point-min) (point)))))
(master-file (expand-file-name (if (fboundp 'TeX-master-file)
(TeX-master-file t)
(kdvi-get-masterfile (kdvi-master-file-name)))))
(dvi-file (concat (file-name-sans-extension master-file) ".dvi"))
(filename (expand-file-name (buffer-file-name))))
(start-process "kdvi"
"kdvi-output" "kdvi" "--unique" (concat "file:" dvi-file "#src:" current-line filename)
)))))
(defun kdvi-get-masterfile (file)
"Small helper function for AucTeX compatibility.
Converts the special value t that TeX-master might be set to
into a real file name."
(if (eq file t)
(buffer-file-name)
file))
(defun kdvi-master-file-name ()
"Emulate AucTeX's TeX-master-file function.
Partly copied from tex.el's TeX-master-file and TeX-add-local-master."
(if (boundp 'TeX-master)
TeX-master
(let ((master-file (read-file-name "Master file (default this file): ")))
(if (y-or-n-p "Save info as local variable? ")
(progn
(goto-char (point-max))
(if (re-search-backward "^\\([^\n]+\\)Local Variables:" nil t)
(let* ((prefix (if (match-beginning 1)
(buffer-substring (match-beginning 1) (match-end 1))
""))
(start (point)))
(re-search-forward (regexp-quote (concat prefix "End:")) nil t)
(if (re-search-backward (regexp-quote (concat prefix "TeX-master")) start t)
(progn
(beginning-of-line 1)
(kill-line 1))
(beginning-of-line 1))
(insert prefix "TeX-master: " (prin1-to-string master-file) "\n"))
(insert "\n%%% Local Variables: "
"\n%%% TeX-master: " (prin1-to-string master-file)
"\n%%% End: \n"))
(save-buffer)
(message "(local variables written.)"))
(message "(nothing written.)"))
(set (make-local-variable 'TeX-master) master-file))))