Skip to content

Fix typeset output #74

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion emacs_sage_shell_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ def default_preferences(self):
return DisplayPreferences(text=self.__text)

def supported_output(self):
return [OutputLatex, OutputPlainText, OutputHtml, OutputImagePng]

def _repr_(self):
return "Emacs babel"
Expand Down
4 changes: 2 additions & 2 deletions sage-shell-blocks.el
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

Note that '^' to match at the beginning of the line should not be added to
`sage-shell-blocks:delimiter'.
Strange behaviour might arise if `sage-shell-blocks:delimiter' matches multiple lines
at a time."
Strange behaviour might arise if `sage-shell-blocks:delimiter' matches
multiple lines at a time."
:type 'string
:group 'sage-shell)

Expand Down
37 changes: 24 additions & 13 deletions sage-shell-mode.el
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@

(defcustom sage-shell:input-history-cache-file
nil
"If non nil, then `comint-input-ring' is saved to this file when the Sage process exits."
"If non nil, then `comint-input-ring' is saved to this file
when the Sage process exits."
:group 'sage-shell
:type '(choice (file :tag "file")
(const :tag "Off" nil)))
Expand Down Expand Up @@ -186,32 +187,37 @@ If the value is equal to '(\"\"), then it does not ignore anything."
:type '(repeat string))

(defcustom sage-shell-edit:temp-file-header "# -*- coding: utf-8 -*-\n"
"`sage-shell-edit:send-region', `sage-shell-edit:send-buffer' and related commands use a temporary file.
"`sage-shell-edit:send-region', `sage-shell-edit:send-buffer' and related
commands use a temporary file.
This string will be inserted to the temporary file before evaluating code."
:type 'string
:group 'sage-shell)


(defcustom sage-shell:use-prompt-toolkit nil
"Non `nil' means the Sage process uses the new prompt of IPython 5 and 6. Must be disabled for Ipython >=7, which is incompatible"
"Non `nil' means the Sage process uses the new prompt of IPython 5 and 6.
Must be disabled for Ipython >=7, which is incompatible"
:type 'boolean
:group 'sage-shell)
;; (make-variable-buffer-local 'sage-shell:use-prompt-toolkit)

(defcustom sage-shell:use-simple-prompt t
"Non `nil' means the Sage process must be started with the `simple-prompt' option and use `readline' to interact with IPython >=7."
"Non `nil' means the Sage process must be started with the `simple-prompt'
option and use `readline' to interact with IPython >=7."
:type 'boolean
:group 'sage-shell)


(defcustom sage-shell:check-ipython-version-on-startup t
"Non `nil' means check if `sage-shell:use-prompt-toolkit' and `sage-shell:simple-prompt' are correctly set when starting the Sage process.
"Non `nil' means check if `sage-shell:use-prompt-toolkit' and
`sage-shell:simple-prompt' are correctly set when starting the Sage process.
The checking is done asyncally."
:type 'boolean
:group 'sage-shell)

(defcustom sage-shell:set-ipython-version-on-startup t
"Non `nil' means set `sage-shell:use-prompt-toolkit' and `sage-shell:simple-prompt' according to the available IPython version.
"Non `nil' means set `sage-shell:use-prompt-toolkit' and
`sage-shell:simple-prompt' according to the available IPython version.
This (synchronous) setting can be replaced by setting variables in the init file.")

(defcustom sage-shell-sagetex:pre-latex-command
Expand Down Expand Up @@ -1146,7 +1152,8 @@ When sync is nil this return a lambda function to get the result."
" To disable this checking, set `sage-shell:check-ipython-version-on-startup' to `nil'.")))

(defcustom sage-shell:shell-command "/bin/sh"
"Path of a command that behaves like a shell. It should accept -c option. This variable is used only when `sage-shell:use-prompt-toolkit' is non-`nil'."
"Path of a command that behaves like a shell. It should accept -c option.
This variable is used only when `sage-shell:use-prompt-toolkit' is non-`nil'."
:type 'string
:group 'sage-shell)

Expand Down Expand Up @@ -1286,8 +1293,8 @@ if [ $1 = .. ]; then shift; fi; exec \"$@\""
(switch-function 'switch-to-buffer)
buffer-name)
"Running Sage function internal.
SIWTCH-FUNCTION is 'no-switch, or a function with one
argument. If buffer-name is non-nil, it will be the buffer name of the process buffer."
SWITCH-FUNCTION is 'no-switch, or a function with one argument.
If buffer-name is non-nil, it will be the buffer name of the process buffer."
(let ((buf (get-buffer-create (if (stringp buffer-name)
buffer-name
(sage-shell:shell-buffer-name new))))
Expand Down Expand Up @@ -1347,7 +1354,8 @@ function asks which process is to be restarted."
(process-send-eof proc))))

(defun sage-shell:set-ipython-version (&optional startup-msg)
"Set `sage-shell:use-prompt-toolkit{ and `sage-shell:use-simple-prompt' according to the IPython version used by Sage."
"Set `sage-shell:use-prompt-toolkit{ and `sage-shell:use-simple-prompt'
according to the IPython version used by Sage."
(message
(concat
"Setting up sage-shell according to your Sage's IPython version... "
Expand Down Expand Up @@ -1375,7 +1383,8 @@ function asks which process is to be restarted."
'(sage-shell:use-simple-prompt t))))))

(defun sage-shell:check-ipython-version (&optional startup-msg)
"Check IPython version and check if sage-shell:use-prompt-toolkit is correctly set."
"Check IPython version and check if sage-shell:use-prompt-toolkit is
correctly set."
(interactive)
(message "Checking IPython version...")
(deferred:$
Expand Down Expand Up @@ -4105,7 +4114,8 @@ This function set the command list by using `sage-shell-cpl:set-cmd-lst'"
(lambda (_proc _event)
(message
"Scanning Magma types ... Done! (%d seconds)\n Saving cache to
'%s' for future instant use\n. Delete the above file to force re-creation of the cache."
'%s' for future instant use\n. Delete the above file to force re-creation of
the cache."
(- (cadr (current-time)) time)
(sage-shell-interfaces:get "magma" 'cache-file))))))))))

Expand Down Expand Up @@ -4742,7 +4752,8 @@ inserted in the process buffer before executing the command."

(defun sage-shell:send-doctest (arg)
(interactive "P")
"If looking at a sage: prompt, send the current doctest lines to the Sage process.
"If looking at a sage: prompt, send the current doctest lines to the Sage
process.
With prefix argument, send all doctests (at sage: prompts) until
the end of the docstring."
(sage-shell-edit:set-sage-proc-buf-internal :select-p t)
Expand Down
34 changes: 24 additions & 10 deletions sage-shell-view.el
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ Otherwise, if non-nil will start both.
Each of these can be enabled or disabled later by calling
`sage-shell-view-enable-inline-plots', `sage-shell-view-disable-inline-plots',
`sage-shell-view-enable-inline-output', `sage-shell-view-disable-inline-output',
`sage-shell-view-toggle-inline-plots' or `sage-shell-view-toggle-inline-output'."
`sage-shell-view-toggle-inline-plots' or
`sage-shell-view-toggle-inline-output'."
:type '(choice (const :tag "Inline Plots" plots)
(const :tag "Typeset Output" output)
(const :tag "Both" t))
Expand Down Expand Up @@ -199,7 +200,12 @@ computes the resolution automatically."
"
sage-shell-view-latex-documentclass
sage-shell-view-latex-preamble
math-expr))
sage-shell-view-latex-math-environment
;; math-expr
(replace-regexp-in-string
"^\$+" ""
(replace-regexp-in-string "\$+$" "" math-expr))
sage-shell-view-latex-math-environment))

(defun sage-shell-view-dir-name ()
(sage-shell-edit--set-and-make-temp-dir)
Expand Down Expand Up @@ -523,7 +529,8 @@ Function to be inserted in `comint-output-filter-functions'."
(sage-shell-view-output-filter-process-inline-output string))))))

(defun sage-shell-view-update-modeline ()
"Update modeline to include information about whether sage-shell-view is enabled."
"Update modeline to include information about whether sage-shell-view
is enabled."
(when (eq major-mode 'sage-shell-mode)
(let ((fmt (format "/%s%s"
(if sage-shell-view-inline-plots-enabled "p" "")
Expand All @@ -539,30 +546,37 @@ Function to be inserted in `comint-output-filter-functions'."

;;;###autoload
(defun sage-shell-view-enable-inline-output ()
"Enable inline output pretty-printing, i.e. typeset output from sage in the `sage-shell-mode' buffer.
WARNING: this communicates with the sage process. Only use this when sage is running."
"Enable inline output pretty-printing, i.e. typeset output from sage in the
`sage-shell-mode' buffer.
WARNING: this communicates with the sage process. Only use this when sage is
running."
(interactive)
(sage-shell-view--set-inline-state
'text t))

(defun sage-shell-view-disable-inline-output ()
"Disable inline output pretty-printing, i.e. do not typeset output from sage in the `sage-shell-mode' buffer.
"Disable inline output pretty-printing, i.e. do not typeset output from sage
in the `sage-shell-mode' buffer.
WARNING: this communicates with the sage process. Only use this when sage is running."
(interactive)
(sage-shell-view--set-inline-state
'text nil))

;;;###autoload
(defun sage-shell-view-enable-inline-plots ()
"Enable inline plotting, i.e. display plots in the `sage-shell-mode' buffer and do not spawn an external viewer.
WARNING: this communicates with the sage process. Only use this when sage is running."
"Enable inline plotting, i.e. display plots in the `sage-shell-mode' buffer
and do not spawn an external viewer.
WARNING: this communicates with the sage process.
Only use this when sage is running."
(interactive)
(sage-shell-view--set-inline-state
'plot t))

(defun sage-shell-view-disable-inline-plots ()
"Disable inline plotting, i.e. do not display plots in the `sage-shell-mode' buffer and instead spawn an external viewer.
WARNING: this communicates with the sage process. Only use this when sage is running."
"Disable inline plotting, i.e. do not display plots in the
`sage-shell-mode' buffer and instead spawn an external viewer.
WARNING: this communicates with the sage process.
Only use this when sage is running."
(interactive)
(sage-shell-view--set-inline-state
'plot nil))
Expand Down