Coder Social home page Coder Social logo

comint-mime's People

Contributors

astoff avatar jabirali avatar pedrormjunior avatar swflint avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

comint-mime's Issues

Adaptations are needed for MacOS

A few small adaptations:

  • might be worth indicating in the instructions that coreutils need to be installed
  • probably need to use "file -bI" instead of "file -bi" (in shell mode)
  • the format of file types is not exactly the same as in Linux
  • my current installed version of Emacs is 28.0.50 (I think that's what you get, at least if you install through brew), might be worth considering making that the minimum version rather than 28.1

mode not working in inferior python

I wanted to try out the package and managed to get it working with the regular shell-mode, but in the case of python I am not able to get inline images. I set it up as described in the readme.

When trying to produce a plot as follows

>>> import matplotlib.pyplot as plt
>>> plt.plot([1, 1], [0, 1])

I get the following error and result

[<matplotlib.lines.Line2D object at 0x7f7c58f87b50>]
Traceback (most recent call last):
  File "/usr/lib/python3.9/base64.py", line 510, in _input_type_check
    m = memoryview(s)
TypeError: memoryview: a bytes-like object is required, not 'str'

The above exception was the direct cause of the following exception:
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/matplotlib_inline/backend_inline.py", line 41, in show
    display(
  File "/usr/lib/python3.9/site-packages/IPython/core/display.py", line 327, in display
    publish_display_data(data=format_dict, metadata=md_dict, **kwargs)
  File "/usr/lib/python3.9/site-packages/IPython/core/display.py", line 119, in publish_display_data
    display_pub.publish(
  File "/usr/lib/python3.9/site-packages/IPython/core/displaypub.py", line 112, in publish
    handler(data[mime], metadata.get(mime, None))
  File "<string>", line 33, in print_osc
  File "/usr/lib/python3.9/base64.py", line 527, in encodebytes
    _input_type_check(s)
  File "/usr/lib/python3.9/base64.py", line 513, in _input_type_check
    raise TypeError(msg) from err
TypeError: expected bytes-like object, not str

In the case of the sympy example, I do not get an error, but the TeX output is not rendered in any form. The example

>>> import sympy
>>> from sympy import Symbol, integrate
>>> x = Symbol("x")
>>> integrate(1 / x)

produces only $\displaystyle \log{\left(x \right)}$ and no inline math. I am running emacs-version 28.0.60 and the comint-mime version corresponds to the last commit here. For python it's

Python 3.9.9 (main, Nov 20 2021, 21:30:06) 
Type 'copyright', 'credits' or 'license' for more information
IPython 7.30.0 -- An enhanced Interactive Python. Type '?' for help.

The comint-mime script can be sent to the python process within Emacs and it does not produce any errors, so if I am missing something I'd be glad about any pointers.

Customize the ipython shell displayed plot and font size in comint buffer.

Currently, I'm using the comint-mime package with the following configuration:

(use-package comint-mime
  :straight (:host github :repo "astoff/comint-mime"
             :files (:defaults "*.py" "*.sh"))
  :hook ((shell-mode inferior-python-mode) . comint-mime-setup))

With the help of this package, I can display python matplotlib plot and LaTeX formula in Emacs comint buffer, as shown in the screenshot below:

image

But I want to know if I can customize the ipython shell displayed plot and font size in comint buffer. Any hints will be appreciated.

Regards, HZ

`Comint-mime` causes the shell prompt to be printed twice.

On Ubuntu 20.04.3 LTS, I use self-compiled git master Emacs, and installed comint-mime via straight's use-package integration as follows:

(use-package comint-mime
  :straight ( :host github
	      :repo "astoff/comint-mime"
	      :files (:defaults "*.py" "*.sh"))
  ;;https://github.com/jwiegley/use-package#hooks
  ;;https://github.com/astoff/comint-mime#usage
  ;;https://mail.google.com/mail/u/0?ik=7b73d6af10&view=om&permmsgid=msg-a%3Ar-1233702610310931433
  ;;https://mail.google.com/mail/u/0?ik=7b73d6af10&view=om&permmsgid=msg-a%3Ar5550893479419332762
  :hook ((shell-mode inferior-python-mode) . comint-mime-setup)
  :custom
  ;;  https://emacs.stackexchange.com/a/33992
  ;;https://github.com/astoff/comint-mime/issues/4#issuecomment-938384059
  (org-format-latex-options '(plist-put org-format-latex-options :scale 1.5))
  )

When I issue the M-x shell RET command, I found that comint-mime causes the shell prompt to be printed twice as follows:

image

Are there any tips for solving this problem?

Regards,
HZ

user-error: ‘comint-mime’ only makes sense in comint buffers

I tried with the following example:

import matplotlib.pyplot as plt
from numpy import arange, sin, pi
t = arange(0, 2*pi, 0.01)
plt.plot(sin(4*t), sin(5*t))

The corresponding Emacs configuration:

(use-package comint-mime
  :straight (:host github :type git :repo "astoff/comint-mime"
             :files (:defaults "*.py" "*.sh"))
  :after elpy
  ;https://github.com/jwiegley/use-package#hooks
  ;https://github.com/astoff/comint-mime#usage
  ;https://mail.google.com/mail/u/0?ik=7b73d6af10&view=om&permmsgid=msg-a%3Ar-1233702610310931433
  ;https://mail.google.com/mail/u/0?ik=7b73d6af10&view=om&permmsgid=msg-a%3Ar5550893479419332762
  :hook (
        ((shell-mode inferior-python-mode) . comint-mime-setup)
        )
  :config
  (when (executable-find "ipython3")
    (setq python-shell-interpreter "ipython3"
          ;python-shell-interpreter-args "--simple-prompt --classic"
          ;https://elpy.readthedocs.io/en/latest/ide.html#interpreter-setup
          python-shell-interpreter-args "-i --simple-prompt --classic --pprint")))

When I run the python code, I meet the following error:

File mode specification error: (user-error ‘comint-mime’ only makes sense in comint buffers)
blank line at end of file [W391] [2 times]
Sent: import matplotlib.pyplot as plt...
Shell native completion is enabled.
Can’t guess python-indent-offset, using defaults: 4
user-error: ‘comint-mime’ only makes sense in comint buffers

Any hints for this problem?

Regards,
HZ

error when command hostname not available

When using comint-mime in shell-mode, it complains that the command hostname cannot be found

bash: hostname: command not found

Is there perhaps a more portable way to retrieve the value for hostname? I suppose the variable $HOSTNAME could be checked (which bash sets) or if hostname is not available maybe hostnamectl hostname could be executed, which does the same on systemd-based systems. If all that fails maybe it could just pass along any string? The error above didn't change the outcome as far as I could see.

Otherwise, it might be sensible to specify that this command is a dependency of the project.

Running from python-mode.el

Hi,
great package. Running from python-mode.el needs a minor tweak. Should deliver a patch. For the moment a picture from a working example. BTW output appears as a separate window here, which should not be an issue
python-mode-el
.

Python code can't be indented automatically in the IPython console while working with comint-mime.

On Ubuntu 20.04.3 LTS, I installed comint-mime with the following configuration:

(use-package comint-mime
  :straight ( :host github
	      :repo "astoff/comint-mime"
	      :files (:defaults "*.py" "*.sh"))
  ;;https://github.com/jwiegley/use-package#hooks
  ;;https://github.com/astoff/comint-mime#usage
  ;;https://mail.google.com/mail/u/0?ik=7b73d6af10&view=om&permmsgid=msg-a%3Ar-1233702610310931433
  ;;https://mail.google.com/mail/u/0?ik=7b73d6af10&view=om&permmsgid=msg-a%3Ar5550893479419332762
  :hook ((shell-mode inferior-python-mode) . comint-mime-setup)
  :custom
  ;;  https://emacs.stackexchange.com/a/33992
  ;;https://github.com/astoff/comint-mime/issues/4#issuecomment-938384059
  (org-format-latex-options '(plist-put org-format-latex-options :scale 1.5))
  )

When I type some python code in the IPython console with the major mode inferior-python-mode enabled, I find that the Python code can't be indented automatically, as shown below:

image

Any hints for this problem?

Regards,
HZ

how to debug?

Hi,

I'm trying to use your package with spacemacs, but installing the package and activating it via comint-mime-setup in the REPL doesn't seem to have any effect. I also tried adding hooks as in your readme. It does work perfectly in emacs -q (after installing the package).

Do you have any suggestions about how to debug this? So far I've tried to debug by checking that comint-mime-setup has the desired effect; I checked that comint-osc-handlers contains ("5151" . comint-mime-osc-handler) and that comint-output-filter-functions contains comint-osc-process-output. These look fine. But I'm not sure what to look at next.

Thanks!

run-hooks: Symbol’s value as variable is void: comint-osc-handlers

I installed comint-mime with the following configuration:

(use-package comint-mime
  :straight (:host github :type git :repo "astoff/comint-mime"
             :files (:defaults "*.py" "*.sh"))
  :hook ((shell-mode inferior-python-mode) . comint-mime-setup)
  :custom
  (org-format-latex-options '(plist-put org-format-latex-options :scale 1.5))

But when I start the python interpreter by C-c C-p, the following message will be triggered:

run-hooks: Symbol’s value as variable is void: comint-osc-handlers
Shell native completion is disabled, using fallback

Any hints for this problem?

Regards,
HZ

This package will trigger a very slow auto-completion of company-mode.

On Ubuntu 20.04.2 LTS, I test this package with the following configuration:

(use-package comint-mime
  :straight (:host github :type git :repo "astoff/comint-mime"
             :files (:defaults "*.py" "*.sh"))
  :after elpy
  ;https://github.com/jwiegley/use-package#hooks
  ;https://github.com/astoff/comint-mime#usage
  ;https://mail.google.com/mail/u/0?ik=7b73d6af10&view=om&permmsgid=msg-a%3Ar-1233702610310931433
  :hook (
        ((shell-mode inferior-python-mode) . comint-mime-setup)
        )
  :config
  (when (executable-find "ipython3")
    (setq python-shell-interpreter "ipython3"
          python-shell-interpreter-args "--simple-prompt --classic"
          ;https://elpy.readthedocs.io/en/latest/ide.html#interpreter-setup
          ;python-shell-interpreter-args "-i --simple-prompt --classic --pprint"
          )))

I find that it will trigger a very slow auto-completion of company-mode.

Regards,
HZ

realpath on Mac does not accept -e flag

In the comint-mime.sh script, line 22:

    file=$(realpath -e "$1") || return 1

the -e flag on linux indicates that 'all components of the path must exist'

This -e flag doesn't exist on Mac version of realpath in /bin. Instead realpath will error if the file does not exist. So on Mac, the -e flag can be deleted to have the same effect as realpath on linux (it seems).

Ipython console with inferior python mode can't complete many python keywords/hints.

On Ubuntu 20.04.3 LTS, I use comint-mime with the following configuration:

(use-package comint-mime
  :straight ( :host github
	      :repo "astoff/comint-mime"
	      :files (:defaults "*.py" "*.sh"))
  ;;https://github.com/jwiegley/use-package#hooks
  ;;https://github.com/astoff/comint-mime#usage
  ;;https://mail.google.com/mail/u/0?ik=7b73d6af10&view=om&permmsgid=msg-a%3Ar-1233702610310931433
  ;;https://mail.google.com/mail/u/0?ik=7b73d6af10&view=om&permmsgid=msg-a%3Ar5550893479419332762
  :hook ((shell-mode inferior-python-mode) . comint-mime-setup)
  :custom
  ;;  https://emacs.stackexchange.com/a/33992
  ;;https://github.com/astoff/comint-mime/issues/4#issuecomment-938384059
  (org-format-latex-options '(plist-put org-format-latex-options :scale 1.5))
  )

But I find that ipython console with inferior python mode can't complete many python keywords/hints. See the following for detailed information:

image

In the normal python mode, the completion will be shown as follows:

image

Any hints for this problem?

Regards,
HZ

SVG plots in IPython?

First of all, thanks for creating this nice package!

I have been trying it out with python-mode via ipython on Emacs Mac port (v29.1) using the configuration below and it works quite well. However, the resolution of the Matplotlib plots is unfortunately not great; it might be because I'm using a hiDPI / Retina screen (and I know this is handled differently on different Emacs ports), but the text in the Matplotlib figure is quite blurry.

One solution is to use SVG figures instead of PNG figures for the Matplotlib plots. I believe e.g. VSCode offers this as a setting when working with IPython / Jupyter. For comparison, I have added a screenshot comparing how a Matplotlib figure looks in the Inferior Python buffer with comint-mime (top right) vs. how it looks when I run plt.savefig("test.svg") and open the corresponding SVG file directly in Emacs image-mode (bottom). As you can see, the SVG version has much crisper text.

Is there a way to use SVG figures as a format when working with Matplotlib plots in comint-mime?

Screenshot:
Screenshot 2024-04-24 at 11 20 04

My configuration:

(use-package comint-mime
  :ensure t
  :hook (inferior-python-mode . comint-mime-setup))

(use-package python
  :custom
  (python-indent-guess-indent-offset t)
  (python-indent-guess-indent-offset-verbose nil)
  (python-shell-interpreter "ipython3")
  (python-shell-interpreter-args "--simple-prompt --classic"))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.