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: Evaluate current line in Python mode? Date: Mon, 30 Aug 2010 12:43:54 +0200 Message-ID: <4C7B8B6A.6030906@easy-emacs.de> References: <950559.18533.qm@web55007.mail.re4.yahoo.com> <4C7A140D.9080201@easy-emacs.de> <87iq2tu84v.fsf@tux.homenetwork> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1283166522 23829 80.91.229.12 (30 Aug 2010 11:08:42 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 30 Aug 2010 11:08:42 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon Aug 30 13:08:41 2010 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Oq2EB-0005uf-VU for geh-help-gnu-emacs@m.gmane.org; Mon, 30 Aug 2010 13:08:40 +0200 Original-Received: from localhost ([127.0.0.1]:56733 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oq2EB-0003AB-4e for geh-help-gnu-emacs@m.gmane.org; Mon, 30 Aug 2010 07:08:39 -0400 Original-Received: from [140.186.70.92] (port=58688 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Oq2D5-00032B-4s for help-gnu-emacs@gnu.org; Mon, 30 Aug 2010 07:07:33 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1Oq1s4-0000WA-4Q for help-gnu-emacs@gnu.org; Mon, 30 Aug 2010 06:45:53 -0400 Original-Received: from moutng.kundenserver.de ([212.227.126.171]:60385) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1Oq1s3-0008Vz-Oq for help-gnu-emacs@gnu.org; Mon, 30 Aug 2010 06:45:48 -0400 Original-Received: from [192.168.178.27] (brln-4dbc633f.pool.mediaWays.net [77.188.99.63]) by mrelayeu.kundenserver.de (node=mreu2) with ESMTP (Nemesis) id 0Me7T8-1OSSaS1vEU-00PP37; Mon, 30 Aug 2010 12:44:43 +0200 User-Agent: Mozilla/5.0 (X11; U; Linux i686; de; rv:1.9.1.11) Gecko/20100711 Thunderbird/3.0.6 In-Reply-To: <87iq2tu84v.fsf@tux.homenetwork> X-Provags-ID: V02:K0:s6H6nx4XqlrLlv3P7sYSvKzrTsXT4+HGMQIZ4uKZkxS MhcKQR8Nd0MOva0q6rrzfW1P8+P9WcJtEvPy6vcvKUFdRiaxRt zLNmY+vfXTSI0mpbmnv2aYZbM7L0+yCPM2l147PJOnRmOsDdAJ vlOY3KJRP/Q/LPNwuvnfxkPYYeuWIoPd6i9fH7uvqSHuIJ/Ml9 8uBUYQY+ni+vnSIwRhzJuvDkZp8BqbSABbWmTwUQSs= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:74832 Archived-At: Am 29.08.2010 10:37, schrieb Thierry Volpiatto: > Andreas Röhler writes: > >> Am 28.08.2010 21:45, schrieb Michael Hannon: >>> Greetings. I use Emacs for, among other things, running Python code and R >>> code. In both modes (Python and ESS "Emacs Speaks Statistics") there is a >>> function bound to the sequence: >>> >>> C-c C-n >>> >>> Both functions advance to the next line of code in the buffer, i.e., skipping >>> blank lines, comment lines, etc. >>> >>> In ESS mode the function bound to C-c C-n also (by default) sends the current >>> line to R for evaluation. I find this to be very convenient as a way to watch >>> calculations "evolve". >>> >>> It's possible to do something similar in Python mode by selecting the >>> current line and then sending the region (C-c C-r) to Python for evaluation, >>> but this is a bit cumbersome. >>> >>> Can anybody suggest a way to graft the ESS-mode behavior onto Python mode? >> >> Try this: >> >> (defun my-python-send-region (&optional beg end) >> (interactive) >> (let ((beg (cond (beg beg) >> ((region-active-p) >> (region-beginning)) >> (t (line-beginning-position)))) >> (end (cond (end end) >> ((region-active-p) >> (copy-marker (region-end))) >> (t (line-end-position))))) >> (python-send-region beg end))) >> >> HTH >> Comments welcome > > Isn't it simpler: > > (defun my-python-send-region (beg end) > (interactive "r") > (if (eq beg end) > (python-send-region (point-at-bol) (point-at-eol)) > (python-send-region beg end))) > "r" complains if no mark is set Did choose the default getting rid of that constraint > Otherwise, with cond you can write > > (cond (beg) > (end)) > > instead of > > (cond (beg beg) > (end end)) > >> Indeed, will change this. Thanks >> Andreas >> >> -- >> https://code.launchpad.net/~a-roehler/python-mode >> https://code.launchpad.net/s-x-emacs-werkstatt/ >> >>> I've appended the high-level descriptions of both functions. I understand >>> that the source code is available, and that I'm free to hack away to my >>> heart's content. I just don't have the skills at Emacs/Lisp required to do >>> such a thing in a finite amount of time. >>> >>> Thanks and best wishes, >>> >>> -- Mike >>> >>> >>> Python mode >>> =========== >>> >>> C-c C-n runs the command python-next-statement, which is an >>> interactive compiled Lisp function. >>> >>> It is bound to C-c C-n. >>> >>> (python-next-statement&optional COUNT) >>> >>> Go to start of next statement. >>> With argument COUNT, do it COUNT times. Stop at end of buffer. >>> Return count of statements left to move. >>> >>> ---------- >>> >>> ESS mode >>> ======== >>> >>> C-c C-n runs the command ess-eval-line-and-step, which is an >>> interactive compiled Lisp function in `ess-inf.el'. >>> >>> It is bound to C-c C-n, C-c C-e C-n, >> line& step>. >>> >>> (ess-eval-line-and-step&optional SIMPLE-NEXT EVEN-EMPTY INVISIBLY) >>> >>> Evaluate the current line visibly and step to the "next" line. >>> "next" = the next line with non-comment code _unless_ SIMPLE-NEXT is non-nil, >>> possibly via prefix arg. If 2nd arg EVEN-EMPTY [prefix as well], >>> also send empty lines. When the variable `ess-eval-empty' is non-nil >>> both SIMPLE-NEXT and EVEN-EMPTY are interpreted as true. >>> >>> >>> >>> >>> >> >> >> >