From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Yuri D'Elia Newsgroups: gmane.emacs.devel Subject: Re: python.el, shell-send-region and exception handling Date: Thu, 25 Jun 2015 15:55:32 +0200 Message-ID: <558C0854.50804@thregr.org> References: <87y4p0zxgc.fsf@gnu.org> <5589623D.2060805@thregr.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1435240571 6429 80.91.229.3 (25 Jun 2015 13:56:11 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 25 Jun 2015 13:56:11 +0000 (UTC) Cc: emacs-devel@gnu.org To: =?UTF-8?Q?Fabi=c3=a1n_Ezequiel_Gallina?= Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 25 15:56:10 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z87dR-0003WH-Ix for ged-emacs-devel@m.gmane.org; Thu, 25 Jun 2015 15:56:09 +0200 Original-Received: from localhost ([::1]:55889 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z87dQ-0008M9-VA for ged-emacs-devel@m.gmane.org; Thu, 25 Jun 2015 09:56:08 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:35539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z87ct-0008Lo-ML for emacs-devel@gnu.org; Thu, 25 Jun 2015 09:55:36 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z87cs-0005dn-NX for emacs-devel@gnu.org; Thu, 25 Jun 2015 09:55:35 -0400 Original-Received: from e.thregr.org ([2001:41c8:1:556b::10]:36380) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z87cs-0005dc-Hf; Thu, 25 Jun 2015 09:55:34 -0400 Original-Received: from [2a02:27e8:20:9049:8edc:d4ff:fed6:5d5b] by e.thregr.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_RC3) (envelope-from ) id 1Z87cr-00052O-C8; Thu, 25 Jun 2015 15:55:33 +0200 Original-Newsgroups: gmane.emacs.devel X-Enigmail-Draft-Status: N1110 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.0 In-Reply-To: <5589623D.2060805@thregr.org> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:41c8:1:556b::10 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:187513 Archived-At: 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.