From: Yuri D'Elia <wavexx@thregr.org>
To: "Fabián Ezequiel Gallina" <fgallina@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: python.el, shell-send-region and exception handling
Date: Thu, 25 Jun 2015 15:55:32 +0200 [thread overview]
Message-ID: <558C0854.50804@thregr.org> (raw)
In-Reply-To: <5589623D.2060805@thregr.org>
On 06/23/2015 03:42 PM, Yuri D'Elia wrote:
> On 01/18/2015 02:31 AM, Fabián Ezequiel Gallina wrote:
>>> If I wanted to implement such a feature, how would you suggest to
>>> implement it?
>>
>> A simple way to achieve this would be to create a comint output filter
>> function. The `python-pdbtrack-comint-output-filter-function` is a nice
>> guide to start. You would check with a regexp for the occurrence of an
>> exception and act accordingly.
>>
>> I plan to add this to python.el. If you'd like your implementation to
>> be considered feel free to propose it, otherwise expect my approach to
>> land in the next few weeks.
>
> Hi again Fabián, did you eventually develop something in that regard?
So here's a crude approach:
(defun python-shell-show-exception (buffer)
(pop-to-buffer buffer))
(defun python-comint-show-exceptions (output)
(save-excursion
(when (re-search-backward "\\bTraceback (most recent call last):\n File "
comint-last-output-start t)
(python-shell-show-exception (current-buffer)))))
(add-hook 'inferior-python-mode-hook
(lambda ()
(add-hook 'comint-output-filter-functions
'python-comint-show-exceptions)))
This will call `python-shell-show-exception' (which is just a simple stub here)
if a traceback is detected in the output buffer.
Matching on the regex is pretty crude, but I guess there's nothing much
better that can be done? You cannot assume it's the last output, and not the
first either, so the regex just tries to match the beginning of a traceback.
At first, it seems to work as intended. But clearly some better names/
customization is needed in order to let the user decide what to do in
case of exceptions.
next prev parent reply other threads:[~2015-06-25 13:55 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-09 20:29 python.el, shell-send-region and exception handling Yuri D'Elia
2015-01-18 1:31 ` Fabián Ezequiel Gallina
2015-01-18 12:05 ` Daniel Pimentel
2015-06-23 13:42 ` Yuri D'Elia
2015-06-25 13:55 ` Yuri D'Elia [this message]
-- strict thread matches above, loose matches on Subject: below --
2015-01-09 15:35 Yuri D'Elia
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=558C0854.50804@thregr.org \
--to=wavexx@thregr.org \
--cc=emacs-devel@gnu.org \
--cc=fgallina@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.