Re: Editing text with an external editor in Python

2014-09-03 Thread alister
On Tue, 02 Sep 2014 18:45:54 +1000, Chris Angelico wrote: > On Tue, Sep 2, 2014 at 6:35 PM, alister > wrote: >> if edlin is your only option then it would be better to spend you time >> writhing your own text editor! > > Heh! > > Considering how easy it is to deploy a multi-line edit widget in

Re: Editing text with an external editor in Python

2014-09-02 Thread Zachary Ware
On Tue, Sep 2, 2014 at 3:45 AM, Chris Angelico wrote: > Considering how easy it is to deploy a multi-line edit widget in any > GUI toolkit, it shouldn't be too hard to write a GUI text editor. Coincidentally, I was annoyed enough to write the following program sometime last week. I was sick of m

Re: Editing text with an external editor in Python

2014-09-02 Thread Terry Reedy
On 9/2/2014 5:36 PM, Chris Angelico wrote: On Wed, Sep 3, 2014 at 7:14 AM, Terry Reedy wrote: import tkinter as tk root = tk.Tk() text = tk.Text() text.pack() root.mainloop() I tested tested the functions and wrote the following. This is a test text entry. Enter and Tab work as expected. The

Re: Editing text with an external editor in Python

2014-09-02 Thread Chris Angelico
On Wed, Sep 3, 2014 at 7:14 AM, Terry Reedy wrote: > import tkinter as tk > root = tk.Tk() > text = tk.Text() > text.pack() > root.mainloop() > > I tested tested the functions and wrote the following. > > This is a test text entry. > Enter and Tab work as expected. > The Arrow (Cursor) keys work a

Re: Editing text with an external editor in Python

2014-09-02 Thread Terry Reedy
On 9/2/2014 4:45 AM, Chris Angelico wrote: On Tue, Sep 2, 2014 at 6:35 PM, alister wrote: if edlin is your only option then it would be better to spend you time writhing your own text editor! Heh! Considering how easy it is to deploy a multi-line edit widget in any GUI toolkit, it shouldn't

Re: Editing text with an external editor in Python

2014-09-02 Thread Chris Angelico
On Tue, Sep 2, 2014 at 6:35 PM, alister wrote: > if edlin is your only option then it would be better to spend you time > writhing your own text editor! Heh! Considering how easy it is to deploy a multi-line edit widget in any GUI toolkit, it shouldn't be too hard to write a GUI text editor. Now

Re: Editing text with an external editor in Python

2014-09-02 Thread alister
On Mon, 01 Sep 2014 15:06:04 -0500, Tim Chase wrote: > On 2014-09-02 04:23, Steven D'Aprano wrote: >> Read $VISUAL, if it exists, otherwise $EDITOR, if it exists, otherwise >> fall back on something hard coded. Or read it from an ini file. Or >> create an entry in the register. Whatever. That's up

Re: Editing text with an external editor in Python

2014-09-01 Thread Steven D'Aprano
Cameron Simpson wrote: > It is not just about being hacked. > > It is about being robust in the face of unusual setups. > > If I were producing this function for general use (even my own personal > general use) it would need to be reliable. That includes things like > $TMPDIR having spaces in it

Re: Editing text with an external editor in Python

2014-09-01 Thread gschemenauer3
On Monday, September 1, 2014 11:11:34 AM UTC-5, Steven D'Aprano wrote: > Python's input() or raw_input() function is good for getting a single line > > of text from the user. But what if you want a more substantial chunk of > > text from the user? Here's how to call out to an external editor such

Re: Editing text with an external editor in Python

2014-09-01 Thread Chris Angelico
On Tue, Sep 2, 2014 at 4:23 AM, Steven D'Aprano wrote: > Chris Angelico wrote: >> C:\>Python34\python 123123123.py >> cygwin warning: >> MS-DOS style path detected: C:\DOCUME~1\M\LOCALS~1\Temp\tmp94rcwd57 >> Preferred POSIX equivalent is: /DOCUME~1/M/LOCALS~1/Temp/tmp94rcwd57 > > That's arguab

Re: Editing text with an external editor in Python

2014-09-01 Thread Chris Angelico
On Tue, Sep 2, 2014 at 4:02 AM, Steven D'Aprano wrote: > I'm not really seeing how this is a security vulnerability. If somebody can > break into my system and set a hostile GIT_EDITOR, or TMPDIR, environment > variables, I've already lost. Agreed. If I'm calling on your program and setting EDITO

Re: Editing text with an external editor in Python

2014-09-01 Thread Cameron Simpson
On 02Sep2014 04:02, Steven D'Aprano wrote: Roy Smith wrote: Hmmm. Didn't we just have a thread about passing external data to shells? $ mkdir '/tmp/;rm -rf;' $ TMPDIR='/tmp/;rm -rf;' python Python 2.7.3 (default, Sep 26 2013, 20:03:06) [GCC 4.6.3] on linux2 Type "help", "copyright", "credits

Re: Editing text with an external editor in Python

2014-09-01 Thread Tim Chase
On 2014-09-02 04:23, Steven D'Aprano wrote: > Read $VISUAL, if it exists, otherwise $EDITOR, if it exists, > otherwise fall back on something hard coded. Or read it from an ini > file. Or create an entry in the register. Whatever. That's up to > the application which uses this function, not the fun

Re: Editing text with an external editor in Python

2014-09-01 Thread Steven D'Aprano
Chris Angelico wrote: > On Tue, Sep 2, 2014 at 2:11 AM, Steven D'Aprano > wrote: >> Anyone able to test it on Windows for me please? >> > > Seems to partially work. I added an 'import os' at the top, and a > simple test call to the function, and it did give me my editor (nano) > and retrieved th

Re: Editing text with an external editor in Python

2014-09-01 Thread Steven D'Aprano
Roy Smith wrote: > Hmmm. Didn't we just have a thread about passing external data to > shells? > > $ mkdir '/tmp/;rm -rf;' > $ TMPDIR='/tmp/;rm -rf;' python > Python 2.7.3 (default, Sep 26 2013, 20:03:06) > [GCC 4.6.3] on linux2 > Type "help", "copyright", "credits" or "license" for more informa

Re: Editing text with an external editor in Python

2014-09-01 Thread Roy Smith
In article <54049ab7$0$29972$c3e8da3$54964...@news.astraweb.com>, Steven D'Aprano wrote: > import tempfile > > def edit(editor, content=''): > f = tempfile.NamedTemporaryFile(mode='w+') > [...] > command = editor + " " + f.name > status = os.system(command) Hmmm. Didn't we jus

Re: Editing text with an external editor in Python

2014-09-01 Thread Chris Angelico
On Tue, Sep 2, 2014 at 2:11 AM, Steven D'Aprano wrote: > Anyone able to test it on Windows for me please? > Seems to partially work. I added an 'import os' at the top, and a simple test call to the function, and it did give me my editor (nano) and retrieved the text. It did give a warning, though

Editing text with an external editor in Python

2014-09-01 Thread Steven D'Aprano
Python's input() or raw_input() function is good for getting a single line of text from the user. But what if you want a more substantial chunk of text from the user? Here's how to call out to an external editor such as ed, nano, vim, emacs, and even GUI text editors: import tempfile def edit(edi