unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* python.el, shell-send-region and exception handling
@ 2015-01-09 20:29 Yuri D'Elia
  2015-01-18  1:31 ` Fabián Ezequiel Gallina
  0 siblings, 1 reply; 5+ messages in thread
From: Yuri D'Elia @ 2015-01-09 20:29 UTC (permalink / raw)
  To: emacs-devel

Is there a way to have python-shell-send-region (and friends) to detect
uncaught exceptions at the python prompt?

I would like to be notified somehow of python exceptions either in the
minibuffer or by splitting the window and showing python's output.
Currently, uncaught exceptions simply go unnoticed if you don't have the
output buffer visible.

This is done currently in python-mode.el, but I couldn't find an
alternative in python.el.

If I wanted to implement such a feature, how would you suggest to
implement it?

Thanks.




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: python.el, shell-send-region and exception handling
  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
  0 siblings, 2 replies; 5+ messages in thread
From: Fabián Ezequiel Gallina @ 2015-01-18  1:31 UTC (permalink / raw)
  To: Yuri D'Elia; +Cc: emacs-devel

Yuri D'Elia <wavexx@thregr.org> writes:

> Is there a way to have python-shell-send-region (and friends) to detect
> uncaught exceptions at the python prompt?
>
> I would like to be notified somehow of python exceptions either in the
> minibuffer or by splitting the window and showing python's output.
> Currently, uncaught exceptions simply go unnoticed if you don't have the
> output buffer visible.
>
> This is done currently in python-mode.el, but I couldn't find an
> alternative in python.el.
>
> If I wanted to implement such a feature, how would you suggest to
> implement it?
>
> Thanks.
>
Hi Yuri,

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.



Regards,
Fabián



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: python.el, shell-send-region and exception handling
  2015-01-18  1:31 ` Fabián Ezequiel Gallina
@ 2015-01-18 12:05   ` Daniel Pimentel
  2015-06-23 13:42   ` Yuri D'Elia
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Pimentel @ 2015-01-18 12:05 UTC (permalink / raw)
  To: fgallina; +Cc: Yuri D'Elia, emacs-devel-bounces+d4n1=opmbx.org, emacs-devel

On 2015-01-17 22:31, fgallina@gnu.org wrote:
> Yuri D'Elia <wavexx@thregr.org> writes:
> 
>> Is there a way to have python-shell-send-region (and friends) to 
>> detect
>> uncaught exceptions at the python prompt?
>> 
>> I would like to be notified somehow of python exceptions either in the
>> minibuffer or by splitting the window and showing python's output.
>> Currently, uncaught exceptions simply go unnoticed if you don't have 
>> the
>> output buffer visible.
>> 
>> This is done currently in python-mode.el, but I couldn't find an
>> alternative in python.el.
>> 
>> If I wanted to implement such a feature, how would you suggest to
>> implement it?
>> 
>> Thanks.
>> 
> Hi Yuri,
> 
> 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.
> 
> 
> 
> Regards,
> Fabi�n
Thank you for it.
-- 
Daniel Pimentel (d4n1)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: python.el, shell-send-region and exception handling
  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
  1 sibling, 1 reply; 5+ messages in thread
From: Yuri D'Elia @ 2015-06-23 13:42 UTC (permalink / raw)
  To: Fabián Ezequiel Gallina; +Cc: emacs-devel

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?




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: python.el, shell-send-region and exception handling
  2015-06-23 13:42   ` Yuri D'Elia
@ 2015-06-25 13:55     ` Yuri D'Elia
  0 siblings, 0 replies; 5+ messages in thread
From: Yuri D'Elia @ 2015-06-25 13:55 UTC (permalink / raw)
  To: Fabián Ezequiel Gallina; +Cc: emacs-devel

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.




^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-06-25 13:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).