;;; ... -*- lexical-binding: t -*- ;; Latex (AUCTeX) (defmodefeature latex-bindings (local-set-key "\M-q" 'LaTeX-fill-paragraph) ;; This gets unset by latex-mode (local-set-key "\C-m" 'newline-and-indent)) (defmodefeature latex-faces ;; Make all of the section faces small (setq font-latex-match-sectioning-1-keywords '("problem")) (font-latex-match-sectioning-1-make)) (put 'TeX-master 'safe-local-variable t) (put 'TeX-PDF-mode 'safe-local-variable t) (put 'TeX-command-default 'safe-local-variable t) (drkp:autoload-mode 'tex-mode "auctex" "\\.tex$") (drkp:add-mode-features 'LaTeX-mode-hook '(autofill-code flyspell-full ; filladapt latex-bindings latex-faces)) (defun tex-choose-default-command () (let ((dir (file-name-directory (buffer-file-name)))) (if (or (file-exists-p (expand-file-name "Makefile" dir)) (file-exists-p (expand-file-name "GNUmakefile" dir)) (file-exists-p (expand-file-name "makefile" dir))) (setq TeX-command-default "Make") (setq TeX-command-default "Rubber")))) (eval-after-load "tex" '(progn (add-to-list 'TeX-command-list '("Make" "make" TeX-run-TeX t t) t) (add-to-list 'TeX-command-list '("Make PS" "make %f" TeX-run-TeX t t) t) ;; Always use rubber to compile LaTeX (add-to-list 'TeX-expand-list '("%(rubberarg)" (lambda () (if TeX-PDF-mode "--pdf" "")))) (add-to-list 'TeX-command-list '("Rubber" "rubber %(rubberarg) -Wrefs -Wmisc %t" TeX-run-compile nil (latex-mode))) (add-hook 'LaTeX-mode-hook 'tex-choose-default-command) (add-hook 'LaTeX-mode-hook 'reftex-mode) (when (executable-find "evince") (add-to-list 'TeX-view-program-selection '(output-pdf "Evince"))))) ;; SyncTeX/Evince support (require 'dbus) (defun switch-to-or-make-visible-frame () (let ((visible-frames (remove-if (lambda (f) (equal "F1" (cdr (assoc 'name (frame-parameters f))))) (visible-frame-list)))) (if visible-frames ;; Ignore these so that select-frame-set-input-focus (let ((focus-follows-mouse nil) (mouse-autoselect-window nil)) (select-frame-set-input-focus (car visible-frames))) (make-frame)))) (defun evince-sync (file linecol timestamp) (message "evince-sync %s %S %d; sleeping" file linecol timestamp) (sleep-for 0.1) (let* ((stripped-file (if (string-match "file://" file) (substring file (match-end 0)) file)) (buf (find-buffer-visiting stripped-file)) (line (car linecol)) (col (cadr linecol))) ;; Is there an open buffer? If there is, is it being displayed in ;; a visible frame? If so, switch to that frame. (if buf (let ((matching-windows (remove-if-not (lambda (x) (and (eq (window-buffer x) buf) (frame-visible-p (window-frame x)) x)) (window-list)))) (if matching-windows (progn (message "open window in visible frame") (select-frame-set-input-focus (window-frame (car matching-windows))) (select-window (car matching-windows))) (progn (message "open buffer but no visible window") (switch-to-or-make-visible-frame) (switch-to-buffer buf)))) (progn (message "no open buffer") (switch-to-or-make-visible-frame) (find-file stripped-file))) (goto-line (car linecol)) (unless (= col -1) (move-to-column col)))) (when (and (eq window-system 'x) (fboundp 'dbus-register-signal)) (dbus-register-signal :session nil "/org/gnome/evince/Window/0" "org.gnome.evince.Window" "SyncSource" 'evince-sync))