sagemath / sage-shell-mode

Emacs front end for SageMath
GNU General Public License v3.0
102 stars 16 forks source link

Sage-shell-view-mode breaks sage. #49

Closed simurgh9 closed 4 years ago

simurgh9 commented 4 years ago

Whenever I enable sage-shell-view-mode, sage can not process any inputs, e. g.,

sage: 2*2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-25-e3c01459b706> in <module>()
----> 1 Integer(2)*Integer(2)

/usr/lib/python2.7/dist-packages/IPython/core/displayhook.pyc in __call__(self, result)
    244             self.start_displayhook()
    245             self.write_output_prompt()
--> 246             format_dict, md_dict = self.compute_format_data(result)
    247             self.update_user_ns(result)
    248             self.fill_exec_result(result)

/usr/lib/python2.7/dist-packages/IPython/core/displayhook.pyc in compute_format_data(self, result)
    148             
    149         """
--> 150         return self.shell.display_formatter.format(result)
    151 
    152     # This can be set to True by the write_output_prompt method in a subclass

/usr/lib/python2.7/dist-packages/sage/repl/display/formatter.pyc in format(self, obj, include, exclude)
    200         """
    201         # First, use Sage rich output if there is any
--> 202         sage_format, sage_metadata = self.dm.displayhook(obj)
    203         assert PLAIN_TEXT in sage_format, 'plain text is always present'
    204         if not set(sage_format.keys()).issubset(self.default_mime()):

/usr/lib/python2.7/dist-packages/sage/repl/rich_output/display_manager.pyc in displayhook(self, obj)
    806         self._backend.set_underscore_variable(obj)
    807         plain_text, rich_output = self._rich_output_formatter(obj, dict())
--> 808         return self._backend.displayhook(plain_text, rich_output)
    809 
    810     def display_immediately(self, obj, **rich_repr_kwds):

/home/tashfeen46/.emacs.d/elpa/sage-shell-mode-20191103.1040/emacs_sage_shell_view.pyc in displayhook(self, plain_text, rich_output)
     55         elif isinstance(rich_output, OutputLatex):
     56             text = "" + str(plain_text.text.get(), 'utf-8') + ""
     58             return ({'text/plain': text}, {})
     59         else:

TypeError: str() takes at most 1 argument (2 given)

Interestingly, if I just toggle the inline plots by sage-shell-view-toggle-inline-plots then everything works fine but sage-shell-view-enable-inline-output breaks sage the same way as shown above.

Here is my use-package configurations for sage shell mode,

;; sagemath
(use-package sage-shell-mode
  :ensure t
  :hook
  (sage-shell-mode . eldoc-mode)
  (sage-shell:sage-mode . eldoc-mode)
  (sage-shell-after-prompt . sage-shell-view-toggle-inline-plots))

Any help?

reverland commented 4 years ago

this configuration works well for me.

(use-package sage-shell-mode
  :commands sage-shell:run-sage
  :init
  ;; Turn on eldoc-mode in Sage terminal and in Sage source files
  (add-hook 'sage-shell-mode-hook #'eldoc-mode)
  (add-hook 'sage-shell:sage-mode-hook #'eldoc-mode)
  (add-hook 'sage-shell-after-prompt-hook #'sage-shell-view-mode)
  )
EmmanuelCharpentier commented 4 years ago

WorksForMe(TM).

Note that I use my fork, which handles the incompatibility introduced by IPython upgrade in 9.2.beta8. PR submitted, waiting for review.