From wavexx at thregr.org Sat Jun 20 12:48:04 2015 From: wavexx at thregr.org (Yuri D'Elia) Date: Sat, 20 Jun 2015 12:48:04 +0200 Subject: [Python-mode] Evaluating code blocks Message-ID: 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. From andreas.roehler at easy-emacs.de Sat Jun 20 21:09:09 2015 From: andreas.roehler at easy-emacs.de (=?UTF-8?B?QW5kcmVhcyBSw7ZobGVy?=) Date: Sat, 20 Jun 2015 21:09:09 +0200 Subject: [Python-mode] Evaluating python code blocks in python-mode In-Reply-To: References: Message-ID: <5585BA55.8090205@easy-emacs.de> 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. From andreas.roehler at easy-emacs.de Sun Jun 21 08:21:56 2015 From: andreas.roehler at easy-emacs.de (=?UTF-8?B?QW5kcmVhcyBSw7ZobGVy?=) Date: Sun, 21 Jun 2015 08:21:56 +0200 Subject: [Python-mode] Fwd: Re: Evaluating python code blocks in python-mode In-Reply-To: <558657BE.5090207@easy-emacs.de> References: <558657BE.5090207@easy-emacs.de> Message-ID: <55865804.3070605@easy-emacs.de> -------- Weitergeleitete Nachricht -------- Betreff: Re: Evaluating python code blocks in python-mode Datum: Sun, 21 Jun 2015 08:20:46 +0200 Von: Andreas R?hler An: help-gnu-emacs at gnu.org 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"))))) -------------- next part -------------- An HTML attachment was scrubbed... URL: From andreas.roehler at online.de Thu Jun 25 18:44:02 2015 From: andreas.roehler at online.de (=?UTF-8?B?QW5kcmVhcyBSw7ZobGVy?=) Date: Thu, 25 Jun 2015 18:44:02 +0200 Subject: [Python-mode] C-M-f, C-M-b Message-ID: <558C2FD2.6070103@online.de> Hi Barry, hi all, the equivalent of what forward-sexp in Emacs Lisp is --or should be-- is py-forward-expression. What about setting C-M-f to it? Resp. C-M-b If inside an expression C-M-f should to to its end. From end to next end same level if existing - or level up, or next top-level-form, or nil at EOB Any opinion? Cheers, Andreas From andreas.roehler at online.de Sun Jun 28 11:28:54 2015 From: andreas.roehler at online.de (=?UTF-8?B?QW5kcmVhcyBSw7ZobGVy?=) Date: Sun, 28 Jun 2015 11:28:54 +0200 Subject: [Python-mode] C-M-f, C-M-b In-Reply-To: <20150626142401.37bcc77a@anarchist.wooz.org> References: <558C2FD2.6070103@online.de> <20150626142401.37bcc77a@anarchist.wooz.org> Message-ID: <558FBE56.1020908@online.de> Am 26.06.2015 um 20:24 schrieb Barry Warsaw: > On Jun 25, 2015, at 06:44 PM, Andreas R?hler wrote: > >> the equivalent of what forward-sexp in Emacs Lisp is --or should be-- is >> py-forward-expression. >> >> What about setting C-M-f to it? Resp. C-M-b > Seems reasonable I think. > > -Barry Done. Keys will be set if py-sexp-use-expression-p is non-nil, default is nil. Cheers, Andreas