Commits

ncalexan committed 5632325

Add `sage-startup-hook' and make `sage-view' actually usable.

Comments (0)

Files changed (3)

emacs/sage-mode.el

   :group 'sage
   :type 'string)
 
+(defcustom sage-startup-hook nil
+  "*Normal hook (list of functions) run after `sage' is run and the first prompt is seen.
+See `run-hooks'."
+  :group 'sage
+  :type 'hook)
+
+(defun sage-send-startup-command ()
+  (sage-send-command sage-startup-command t))
+(add-hook 'sage-startup-hook 'sage-send-startup-command)
+
 (defvaralias 'sage-buffer 'python-buffer)
 ;; (defvar sage-buffer nil
 ;;   "*The current SAGE process buffer.
     (with-current-buffer sage-buffer
       (unless noshow (pop-to-buffer sage-buffer)) ; show progress
       (unless (inferior-sage-mode-p)
-	(inferior-sage-mode)
-	(when (inferior-sage-wait-for-prompt) ; wait for prompt
-	  (sage-send-command sage-startup-command t))))
+	(inferior-sage-mode))
+      (when (inferior-sage-wait-for-prompt) ; wait for prompt
+	(run-hooks 'sage-startup-hook)))
     
     (when (sage-mode-p)
       ;; If we're coming from a sage-mode buffer, update inferior buffer

emacs/sage-view.el

 ;; Put this file in a directory in `load-path' and add the following
 ;; line to `.emacs':
 
-;; (add-hook 'inferior-sage-mode-hook 'sage-view)
+;; if you want sage-view to be enabled for every sage session, try
+;; (add-hook 'sage-startup-hook 'sage-view-always)
 
 ;; This mode was inspired by doc-view.el by Tassilo Horn, preview.el
 ;; by David Kastrup, and imath.el by Yasuaki Honda.
       (sage-view-pretty-print-disable)
       )))
 
+(defun sage-view-always ()
+  (sage-view 1))
+
 (provide 'sage-view)
 ;;; sage-view.el ends here
 
 ;; If you want sage-view to typeset all your output and have plot()
 ;; commands inline, uncomment the following line and configure sage-view:
-;; (add-hook 'inferior-sage-mode-hook 'sage-view)
+;; (require 'sage-view "sage-view")
+;; (add-hook 'sage-startup-hook 'sage-view-always)
 EOF