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: Thu, 25 Jun 2015 13:21:10 +0200 Message-ID: <558BE426.3090601@easy-emacs.de> References: <5585BA55.8090205@easy-emacs.de> <558657BE.5090207@easy-emacs.de> <5586E3BE.8080502@thregr.org> <55870801.8050200@easy-emacs.de> <558BD71D.1060605@thregr.org> 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 1435231318 13754 80.91.229.3 (25 Jun 2015 11:21:58 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 25 Jun 2015 11:21:58 +0000 (UTC) To: Yuri D'Elia , help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jun 25 13:21:46 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 1Z85E1-0005X1-56 for geh-help-gnu-emacs@m.gmane.org; Thu, 25 Jun 2015 13:21:45 +0200 Original-Received: from localhost ([::1]:55030 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z85E0-0006Zu-2B for geh-help-gnu-emacs@m.gmane.org; Thu, 25 Jun 2015 07:21:44 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:38658) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z85Dn-0006ZZ-9u for help-gnu-emacs@gnu.org; Thu, 25 Jun 2015 07:21:32 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z85Dg-0000r7-W0 for help-gnu-emacs@gnu.org; Thu, 25 Jun 2015 07:21:31 -0400 Original-Received: from mout.kundenserver.de ([212.227.17.13]:62782) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z85Dg-0000qY-M6 for help-gnu-emacs@gnu.org; Thu, 25 Jun 2015 07:21:24 -0400 Original-Received: from [192.168.178.31] ([77.6.204.184]) by mrelayeu.kundenserver.de (mreue101) with ESMTPSA (Nemesis) id 0Lh6r1-1YmCij3wKF-00oVQL; Thu, 25 Jun 2015 13:21:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 In-Reply-To: <558BD71D.1060605@thregr.org> X-Provags-ID: V03:K0:A40eob4IhnLZZkOcsKeYwClmIsx5/6A8lv2sRx4JWvrFDmjCSFd wBniRdpkN9uSyYMKu2dkWB92uGYwbjRFDalZXBzTZVYYHWnXsZ/MRDgUlBdrzrfDBzpARfD BUGQ1XpdZTj6/nTjvrEM486wJAPeIJwHtce6jNSflTGKnJy9oqz23JHsjaylp4rlcgJQLX2 tNA+0KEjhI7G6INaHIpMA== X-UI-Out-Filterresults: notjunk:1;V01:K0:/xkxXOALAg0=:ewHkvfpDOT+vsp6oYOthdu ow5nk292+iC6cljeSC2XV0jbS3MIXoYDYqwcf+oBT1sjrEyuvufMiI7npfaPBDTYfrbaI6Qs1 NqunHuGnqwx90u/rBHjwwZgqKSud7XNZ8D6PuXTVzmKO2Z7ROCrQ69qXuI9NJz+h73zYNMSYR BIf0cO2UB3JKPpX8v6IBkmdmh7r5JEdQEVnRjZw0fZv6Or5QeKTWh/uSOqRq8jTx2jASUvxOh K+I8bqUCVQCLS+vMovBnR8X35woLW3KIZol2pn+UWnlRy7nO7Vcnkv0zQ6AWvT5H61KvYfEMv CEigt3PvQHxck7d7H9ooaIx5JVDZfw0CL+xnIlfE6lNxnlRGKAftFrWXnZedQ+sbQ3NFhytiC TXiOtRUO/k01Z+i4rDpr12jdTy0nTHpEbJbgs5IMIUDPedaf1p5tAM/Veto4sDfMBTzPNZbkR xZQ62t0XSf2qZfRlGo1Zqm5P5dXreA8ek0lUDSuXUjdELSUGPr2HWbfkstalNcgVXSkKcprzK X16el7LltwW2Ry/MyKHJ/Wv4kKSE1/wKu4SX4GW1hxLcaeYR6PhGQfQXhipxQAWjXJKvkN0LZ xCA9hjHvACOrmZKfrNxW69zhB0Z0KxOoeyElP8KdAR2bfQe/EgK6JMsD+KvcW766RhlHfHtb8 AbQh3NKSjo0zIQG41/nOSoaJWZylgonBtQcrHytI6wdIJ+sXsfHGQSlh8EJIVzOEe2jO6hJmJ kOUnGIPvGvCq9jd4htPMn7ck7GCiwmuLYCeh9nUI7naYlqllxoFAOJBopjiziracyCzi8Zvi X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 212.227.17.13 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:105152 Archived-At: Am 25.06.2015 um 12:25 schrieb Yuri D'Elia: > On 06/21/2015 08:52 PM, Andreas Röhler wrote: >> It might be an option to use existing markers from folding-mode. OTOH >> don't see a command there how to copy the section. Do you? > So this is what I came up with and I currently use: > > http://www.thregr.org/~wavexx/tmp/python-mode-extra.el > > Sorry for not inlining the file, but I think it's more readable. > > The idea is that "C-c C-c" sends the current fold you're in. If you're in a nested fold, subfolds are send too. If you're not in a fold, the buffer (or narrowed region) is sent instead. > > As an added bonus, I wanted to define a generic block delimiter, which is # --- in my case. `python-shell-send-fold-or-section' will send the current fold if there's any, up to the closest block delimiter (if any). > > So for example, in a file like: > > print "1" > # --- > print "2" > > "C-c C-c" on either print statement will be limited to that statement. Block delimiters can be nested inside folds, and work as you'd expect: if you're in the same fold as a delimiter, the delimiter is used. If you're upwards, the delimiter is ignored. > > This makes it very easy to delimit "computation blocks", as you'd normally do in an interactive notebook, without the burden to define folds for each. > > To top that, the region being sent is added with a volatile highlight (volatile-highlights.el is required) so you see what's being evaluated. > > I love it. > > It works in Fabián's python-mode, but should work with minimal changes with other modes too. > > I actually redefine some bindings for python-mode to behave more like ESS (which IMHO has a better layout for interactive evaluation), resulting in something like: > > (add-hook 'python-mode-hook > (lambda () > (local-set-key (kbd "C-c C-j") 'python-shell-send-line) > (local-set-key (kbd "C-c C-n") 'python-shell-send-line and-step) > (local-set-key (kbd "C-c C-f") 'python-shell-send-defun) > (local-set-key (kbd "C-c C-b") 'python-shell-send-buffer) > (local-set-key (kbd "C-c C-c") 'python-shell-send-fold-or-section))) > > `python-shell-send-fold-or-section' is what is defined in python-mode-extra.el, which was a little tricker to define than anticipated, but it seems to work correctly. > > I re-use the markers defined in folding-mode, so if you want to customize the markers just use `folding-add-to-marks-list'. folding-mode doesn't need to be enabled. I actually don't use folding, I just wanted to re-use the same methods. > Thanks for the inspiration. The feature made it into python-mode.el meanwhile https://bugs.launchpad.net/python-mode/+bug/1467217 Kept it independent from folder-mode, as python-mode.el doesn't require any extern stuff for now. BTW see in your file unknown "vhl/add-range" Cheers, Andreas