Ivan Andrus avatar Ivan Andrus committed 92c10ef

Added sage-auctex.el

Comments (0)

Files changed (1)


+;;; sage-auctex.el --- AUCTeX support for Sage code
+;; Copyright (C) 2012  Ivan Andrus
+;; Author: Ivan Andrus <darthandrus@gmail.com>
+;; Keywords: sage tex
+;;; Commentary:
+;; This file adds functionality to AUCTeX supporting usage of SageTeX.
+;;; Code:
+(defun sage-run-sagetex (name command file)
+  "Function to be used in `TeX-command-list' to run sage on sagetex files.
+Makes `TeX-command-default' the next command to be run since we
+need to retypeset after running sage.
+For details of NAME, COMMAND and FILE see the documetation for `TeX-command-list'."
+  (TeX-run-compile name command file)
+  ;; TODO: This only works if there is a process buffer, i.e. not a compile buffer.
+  (TeX-process-set-variable file 'TeX-command-next
+                            TeX-command-default))
+(defadvice TeX-LaTeX-sentinel (after LaTeX-recognize-sage (process name))
+  "Recognize when Sage needs to be run."
+  ;; Only run if we haven't already found something "more important" to do
+  (when (eq TeX-command-next TeX-command-Show)
+    (cond ((re-search-forward "Package sagetex Warning: `final' option provided" nil t)
+           (message "Remove the final option to sagetex and rerun (La)TeX." )
+           (setq TeX-command-next TeX-command-default))
+          ;; More general -- right now there is only one warning
+          ((re-search-forward "Package sagetex Warning: \\(.*\\)" nil t)
+           (message "You should run Sage: %s." (match-string 1))
+           (setq TeX-command-next "Sage")))))
+(defun sage-auctex-setup ()
+  "Hooks Sage support into AUCTeX.
+Must be called after AUCTeX has been loaded.
+Adds entries `TeX-expand-list' and `TeX-command-list' and advises
+  (add-to-list 'TeX-expand-list
+               '("%(sage)" (lambda () (require 'sage) sage-command)))
+  (add-to-list 'TeX-expand-list
+               '("%(sagetex-extension)" (lambda () ".sagetex.sage")))
+  (add-to-list 'TeX-command-list
+               '("Sage" "%(sage) %s%(sagetex-extension)"
+                 sage-run-sagetex t t
+                 :help "Run Sage on sagetex files."))
+  ;; Support the Clean command
+  (dolist (l '(TeX-clean-default-intermediate-suffixes
+               plain-TeX-clean-intermediate-suffixes
+               LaTeX-clean-intermediate-suffixes
+               ConTeXt-clean-intermediate-suffixes
+               docTeX-clean-intermediate-suffixes
+               Texinfo-clean-output-suffixes))
+    ;; If they are not bound they will pick up the value from
+    ;; `TeX-clean-default-intermediate-suffixes'
+    (when (boundp l)
+      ;; cleanup .sagetex.sage .sagetex.py .sagetex.sout .sagetex.cmd
+      (add-to-list l "\\.sagetex\\..*")))
+  (ad-enable-advice 'TeX-LaTeX-sentinel 'after 'LaTeX-recognize-sage)
+  (ad-activate 'TeX-LaTeX-sentinel))
+(eval-after-load 'tex '(sage-auctex-setup))
+(provide 'sage-auctex)
+;;; sage-auctex.el ends here
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.