From mboxrd@z Thu Jan 1 00:00:00 1970 From: Nicolas Goaziou Subject: Re: Extraneous output from Python code blocks using :session option Date: Fri, 13 Mar 2015 09:21:09 +0100 Message-ID: <87ioe5xq8a.fsf@nicolasgoaziou.fr> References: <1931A590-8B23-4412-86C7-F3571EC466FF@haas.berkeley.edu> <87r3sv2xra.fsf@kyleam.com> <210D96E7-43E3-4438-8401-7841C6612023@haas.berkeley.edu> <87bnjxq59p.fsf@kyleam.com> <87d24dtmck.fsf@kmlap.domain.org> Mime-Version: 1.0 Content-Type: text/plain Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:36189) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWKp8-0003aN-QF for emacs-orgmode@gnu.org; Fri, 13 Mar 2015 04:20:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YWKp4-0001GJ-Le for emacs-orgmode@gnu.org; Fri, 13 Mar 2015 04:20:02 -0400 Received: from relay5-d.mail.gandi.net ([2001:4b98:c:538::197]:51850) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YWKp4-0001Fe-Fl for emacs-orgmode@gnu.org; Fri, 13 Mar 2015 04:19:58 -0400 In-Reply-To: <87d24dtmck.fsf@kmlap.domain.org> (Kyle Meyer's message of "Fri, 13 Mar 2015 02:58:35 -0400") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: Kyle Meyer Cc: Richard Stanton , emacs-orgmode@gnu.org, John Kitchin Hello, Kyle Meyer writes: > I've attached two patches. The first one is a proposed way to deal with > the indentation issues in sessions. It is very similar to what > python.el does for multiline input (use a temporary file and then > execute that from the shell). The second is an update of my previous > patch to remove shell prompt characters that are leaking into the > output. Thank you. I'll just comment about code, not functionality. > +(defconst org-babel-python-indented-lines-session-method > + (concat "fname= '%s'; fh = open(fname); " > + "exec(compile(fh.read(), fname, 'exec')); " > + "fh.close()") > + "Single line to execute indented Python code in session. > +%s will be formatted with the file name of the file containing > + the code.") ^^^ spurious space > +(defun org-babel-python--indented-p (input) > + "Return true if any line in INPUT is indented." Non-nil if ... > + (with-temp-buffer > + (insert input) > + (goto-char (point-min)) > + (re-search-forward "^\\s-" nil t))) aka (org-string-match-p "^[ \t]" input) > +(defun org-babel-python--strip-session-chars (string) > + "Remove leading '>>>' and '...' from Python session output. > +`org-babel-comint-with-output' splits by > +`comint-prompt-regexp' (which includes '>>>' and '...'), but, in > +some situations, these still make it through at the start of the > +output string." Argument STRING is not explained in the docstring. > + (with-temp-buffer > + (insert string) > + (goto-char (point-min)) > + (when (looking-at "\\s-*\n\\(\\(>>> \\)\\|\\(\\.\\.\\. \\)\\)*") > + (delete-region (match-beginning 0) (match-end 0))) > + (buffer-string))) aka (replace-regexp-in-string "\\`\\s-*\n\\(>>> \\|\\.\\.\\. \\)*" "" string) Regards, -- Nicolas Goaziou