From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?B?QW5kcmVhcyBSw7ZobGVy?= Newsgroups: gmane.emacs.help Subject: Re: Evaluating python code blocks in python-mode Date: Sun, 21 Jun 2015 08:20:46 +0200 Message-ID: <558657BE.5090207@easy-emacs.de> References: <5585BA55.8090205@easy-emacs.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1434867687 31890 80.91.229.3 (21 Jun 2015 06:21:27 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 21 Jun 2015 06:21:27 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Jun 21 08:21:19 2015 Return-path: Envelope-to: geh-help-gnu-emacs@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 1Z6Yd4-0004md-3q for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Jun 2015 08:21:18 +0200 Original-Received: from localhost ([::1]:35245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z6Yd3-00064k-1o for geh-help-gnu-emacs@m.gmane.org; Sun, 21 Jun 2015 02:21:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:39842) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z6Ycs-00064e-JR for help-gnu-emacs@gnu.org; Sun, 21 Jun 2015 02:21:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z6Ycp-00079q-CG for help-gnu-emacs@gnu.org; Sun, 21 Jun 2015 02:21:06 -0400 Original-Received: from mout.kundenserver.de ([212.227.126.131]:64911) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z6Ycp-00079b-15 for help-gnu-emacs@gnu.org; Sun, 21 Jun 2015 02:21:03 -0400 Original-Received: from [192.168.178.31] ([77.12.85.204]) by mrelayeu.kundenserver.de (mreue005) with ESMTPSA (Nemesis) id 0MGDrv-1ZIOL41V39-00FA9u for ; Sun, 21 Jun 2015 08:21:01 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 In-Reply-To: <5585BA55.8090205@easy-emacs.de> X-Provags-ID: V03:K0:2rLGwBHqum1YEbTSMyaXFMaYMAbQtD66KyCef0zO6C9CmvoaqTT /hMdQGKiWkvU+R27ejqlUjnGXuZ1bWgJuZHS2rLHMXali+mbuiEQ6kTaqTsPGnsAaRjC1qB saJoUKtCmPi7Eej1/BM8l6NLA5xTSu+kmfAy49Bkf+qCYvM8DdeQp66KTh6Gxbk6kxph2Lr 9gHV9myi3BGi8TxdNCaDw== X-UI-Out-Filterresults: notjunk:1;V01:K0:seS+W7gj4zU=:dntAPw84RE3VJLsXG9w13V +0ZYclONhcEqJ7UPWlW4QKadjE8eUSzRVwt8NCEOdPnVIpL31JzgRhAoocyE7DWqxyX9sLTm4 qFcVYWcB2tmFAK7sFBI/rH77GrlafSRjgYgahzlUXiBJIy5rydj2QAv9vrRY5+GWgr+BFn+9z AyKODqoTTxg7lUSJR4f915JRQ/ysDzIIQFPhjiQkBxLXyn2MBXt9aYE67jx4OvoIYTqFl7HwD WujhN0W2Vhn5rZY43JuKSyzpYueLaR+GV11rNxrpf34sKreDaSrdIFi+bcMZ35IfVhKQKEi8F 6E0jL68FGTpBLe5CMiU9oH/aSEUn4hl93/k1H1TjzgUVp4DQBgmYPKfuDSgcH8E110AE17wOe xjh890OERao12dPRjM0vHUfW6XecXxAUFUp/Jci0C/CrwD9kM1VIkeDK/OEjpmnw9sDoT1FsP /ynwpqdoZrNSJ5VtDWX2OZfEJEA5pfkvt2vyP30y7iL6SL744E7hZAa8DBdoahe7t2isX0UfX dprtyqtwjgPtPEV6vjF1SlGKhji679VwJCg8ARImb9buGQNQkz1ruyoIs4ZlLbljthFb+UyWw KnPq1ilkVwMP6nf4TknEo3vofwwpUn9ja2uqwkrrr8mAKoIRFWhuKh9dHXKmK1xKtMxn+Ht9p 4gu7D98kwdLccIqQDFO9nK3LIqiOPWCJ8+ebKx7DISv9DXEBzvkSqxVGLZ1Uyaii3CMxO+Faq HqW85Jx9+4qLcQISqO/aVVEZChSxtscIof+KEb5/z/TugDJ0KUBMUhiT+T4= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 212.227.126.131 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:105055 Archived-At: Am 20.06.2015 um 21:09 schrieb Andreas Röhler: > > Am 20.06.2015 um 12:50 schrieb Yuri D'Elia: >> Hi everyone, >> >> I'd like some advice about using python-mode with a python subprocess. >> I always preferred to use emacs+file+external process as opposed to use >> an ipython's notebook-like interface: it's just more convenient, >> especially when debugging existing code. >> >> I often use the same setup when doing some analysis, and this is when an >> inotebook-like interface is more convenient for evaluation: I'd like to >> evaluate code not line-by-line, or by defun, but by my custom-defined >> blocks. I realized I was continuously selecting a region, and using >> py-send-region over and over. >> >> Right now I narrow to the region I'm editing, and use py-send-buffer >> instead. It's ok-eish, but narrow/widen narrow/widen, while less common, >> is still inconvenient. >> >> I've seen people using org-mode for this kind of setup instead. Which >> might be ok, but I'd like to know what other choices I could have as >> well. >> >> I was thinking of defining a custom region using comments, and defining >> my own py-send-custom-block using comment markers as boundaries. Surely, >> something like this must already exists. >> >> > > > IIUC in question are arbitrary chunks of code. > What about something like that: > > ;;;; > > (defvar py-section-start "# {{") > (defvar py-section-end "# }}") > > (defun py-send-section () > (interactive) > (save-excursion > (unless (looking-at py-section-start) > (search-backward py-section-start) > (set-mark (point)) > (if (and (looking-at py-section-start)(search-forward > py-section-end)) > (py-execute-region (region-beginning) (region-end)) > (error "Can't see boundaries of py-section"))))) > > ;;;; > > BTW didn't call it block, as this is already used by forms heading > others. > > > As python-mode sends a plain string to interpreter anyway, must not touch mark in buffer: (defun py-send-section () (interactive) (save-excursion (let ((start (progn (unless (looking-at py-section-start) (search-backward py-section-start) (point))))) (if (and (looking-at py-section-start)(search-forward py-section-end)) (py-execute-region start (point)) (error "Can't see boundaries of py-section")))))