[issue19042] Idle: add option to autosave 'Untitled' edit window

2016-11-02 Thread perilbrain

perilbrain added the comment:

I have signed the CA. Meantime a came across one more problem in function 
tabnanny(encoding issue) so I am attaching the new version of ScriptBinding.py.

Summary:-

def tabnanny(self, source, encoding = None):
# XXX: tabnanny should work on binary files as well
#print(encoding)
f = io.StringIO(source.decode(encoding) if encoding else source)

def source_from_file(self, filename):
with open(filename, 'rb') as f:
source = f.read()
encoding = tokenize.detect_encoding(f.readline)[0]

return source, encoding

def _run_module_event(self, event):
...
if not filename:
self.no_save = True
source = self.source_from_editor()
filename = self.editwin.top.wm_title()
else:
source, encoding = self.source_from_file(filename)
self.no_save = False
code = self.checksyntax(source, filename)
if not code:
return 'break'
if not self.tabnanny(source, encoding):
return 'break'


--
Added file: http://bugs.python.org/file45328/ScriptBinding.py

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19042] Idle: add option to autosave 'Untitled' edit window

2016-11-02 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Looks promising.  The second half of a patch would be to fill in the missing 
lines.

Before I review, please sign a CA.  The online form at 
https://www.python.org/psf/contrib/contrib-form/ takes about 5 minutes.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19042] Idle: add option to autosave 'Untitled' edit window

2016-11-02 Thread perilbrain

perilbrain added the comment:

"To run without saving" was the first idea I got, but it was difficult to 
pursue in first phase. After your hints I think I have achieved what you have 
described.

I have done a few fixes(luckily in a single file ScriptBinding.py) which are 
giving satisfactory result.

I am attaching the original, modified and the diff version of files named 
ScriptBindingOriginal.py, ScriptBinding.py and ScriptBinding.diff respectively. 

Here is what I am getting with the new code
Traceback (most recent call last):
  File "*Untitled*", line 3, in 
  File "*Untitled*", line 2, in f
ZeroDivisionError: division by zero

This is the summary of the patch (idle-python3.4)

+import io


#== One member in class for reducing annoyance 
self.no_save = False

#== New definition for function tabnanny==
-def tabnanny(self, filename):
+def tabnanny(self, source):
+f = io.StringIO(source)# , os.linesep  *Maybe*
-with tokenize.open(filename) as f:

#== Added 2 functions =
def source_from_file(self, filename):
with open(filename, 'rb') as f:
source = f.read()
if b'\r' in source:
source = source.replace(b'\r\n', b'\n')
source = source.replace(b'\r', b'\n')
if source and source[-1] != ord(b'\n'):
source = source + b'\n'
return source

def source_from_editor(self):
self.editwin.io.fixlastline()
source = self.editwin.text.get("1.0", "end-1c")
return source

#== New definition for function checksyntax==
-def checksyntax(self, filename):
+def checksyntax(self, source, filename):

#== Changes in function run_module_event (Main) ==
def _run_module_event(self, event):
filename = self.getfilename()
filename = self.getfilename()
if not filename:
self.no_save = True
source = self.source_from_editor()
filename = self.editwin.top.wm_title()
else:
source = self.source_from_file(filename)
self.no_save = False
code = self.checksyntax(source, filename)
if not code:
return 'break'
if not self.tabnanny(source):
return 'break'
interp = self.shell.interp
if PyShell.use_subprocess:
interp.restart_subprocess(with_cwd=False)
if not self.no_save:
   
interp.runcode(code)
return 'break'

#== Finally suppressing the annoyance ==
if autosave and filename:
self.editwin.io.save(None)
elif self.no_save:
filename = None
else:
confirm = self.ask_save_dialog()

Please have a review and let me know if it can solve this issue.

--
nosy: +perilbrain
Added file: http://bugs.python.org/file45309/ScriptBinding.diff.zip

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19042] Idle: add option to autosave 'Untitled' edit window

2016-11-01 Thread Terry J. Reedy

Terry J. Reedy added the comment:

Duplicate #28581 has a autosave patch in the initial post, which points out 
that "We are often required to copy code from various sites say some tutorial 
or code samples which are good for one time usage."

It prompted me to think more about the idea to 'add a mechanism to truly run 
without saving [to disk]', which I mentioned in my first post above.  To run 
editor code, IDLE retrieves the code from the Text widget as a single strings; 
runs compile(code, 'filename', 'exec'), ships the code object to the user 
process, and runs exec(code, fakemain).  (I understand this much better now 
than 3 years ago.)  The only use of the disk copy is for tracebacks.  But is it 
*needed*?  I believe not.  Here is standard interactive Python (3.5.2):

>>> def f():
1/0

>>> f()
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 2, in f
ZeroDivisionError: division by zero
>>>

Here is the same traceback in IDLE's Shell:

Traceback (most recent call last):
  File "", line 1, in 
f()
  File "", line 2, in f
1/0
ZeroDivisionError: division by zero

IDLE has filled in the missing lines from Shell's text.  I have not yet tracked 
where this is done (in pyshell.py, I believe), but I presume it could do the 
same for Untitled editor windows.  For this to work, the window titles should 
be Untitled-0, Untitled-1, ... .  The specific name used in the compile call 
would appear in the traceback, to be used to lookup the window the code came 
from.

With the ability to run the whole buffer without saving, it would be easy to 
run a selection.  (There have been multiple requests for this.)

IDLE already asks about saving when one tried to close a window with unsaved 
text, so there is no need to force saving when running for this purpose.

--
versions: +Python 3.6, Python 3.7 -Python 2.7, Python 3.3, Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19042] Idle: add option to autosave 'Untitled' edit window

2016-02-09 Thread Terry J. Reedy

Terry J. Reedy added the comment:

#1326830 ('python scratchpad', rejected) was about same issue, though less 
specific about the implementation.

A different solution to the multiline statement problem would be to separate 
Shell into the read-only history (with prompts in a sidebar, so normal 4 space 
indents would work) and an active mini-editor entry box that would continue to 
submit without saving.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19042] Idle: add option to autosave 'Untitled' edit window

2015-05-01 Thread irdb

Changes by irdb dalba.w...@gmail.com:


--
nosy: +irdb

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19042
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19042] Idle: add option to autosave 'Untitled' edit window

2013-09-17 Thread Terry J. Reedy

New submission from Terry J. Reedy:

The General tab of the IDLE Preferences dialog has this section with two 
radiobuttons:

Autosave Preferences
At Start of Run (F5)  () Prompt to Save   () No Prompt

The latter option actually means No prompt unless the window is a new window 
('Untitled') that has never been saved. In the latter case, there is a prompt 
anyway.

This issue proposes that the current No Prompt option be more truthfully 
labelled and that a true no-prompt option be added. Currently in .cnf 
configuration files, autosave = 0 or 1. The new option would be 2 ('really 
true' ;-).

The motivation is to provide a default scratch file for throwaway code and 
thereby encourage more use of the editor even for single multi-line statements, 
which are harder to edit in the Shell than single-line statements. The behavior 
of Untitled windows would not otherwise change.


Possible dialog forms

Autosave Preferences
When Running (F5) a window with unsaved changes, prompt to save
() Always   () Only for Untitled() Never

I find it slightly confusing that Autosave yes is selected in the negative with 
'no prompt'. An alternative:

Autosave Preferences
When Running (F5) a window with unsaved changes,
autosave instead of prompting to save
() Never   () Always except for Untitled() Always

Another alternative is to retitle the section

Prompt to Save versus Autosave
When Running (F5) a window with unsaved changes, prompt to save
() Always   () Only for Untitled() Never
--

However the dialog is worded, the new option would mean that unsaved new 
windows would be autosaved on Run to .idlerc/untitled.py. (I picked this 
directory because it already contains 4 per-user files, including 
recent-files.lst, and has to be writable.) This would be a common scratch file 
for all Untitled windows.

The particular Untitled window saved should not be 'associated' with that path. 
Its title would not change to 'untitled.py'. Idle allows only one edit window 
per disk file (path) but allows multiple Untitled windows not associated with 
any path.

The 'unsaved' flag on the window would not be cleared, so that closing the 
window would still bring up the 'save this untitled window' message box. (The 
alternative would be to clear it, but unclear it if any other Untitled window 
were saved.)

The full path to untitled.py would be added (or moved) to the top of the Recent 
Files list, just as with any other file. The file could then be retrieved (if 
not overwritten) in a later session. This would be particularly useful if 
running it caused a crash or freeze.
--

This proposal is based on Bruce Sherwood's vague description of a feature coded 
by G. Polo. I could not find a tracker issue for it. One apparent difference is 
that I propose adding a third option to the existing set instead of a new 
binary option. I have no idea whether Polo proposed to silently save the file 
(as I propose) or add a mechanism to truly run without saving (which is how a 
user will see it unless they look at Recent Files). In any case, my proposal is 
for a pretty minimal change. I believe it would take extra code to prevent the 
Recent Files listing.

--
components: IDLE
messages: 197997
nosy: bsherwood, roger.serwy, terry.reedy
priority: normal
severity: normal
stage: test needed
status: open
title: Idle: add option to autosave 'Untitled' edit window
type: enhancement
versions: Python 2.7, Python 3.3, Python 3.4

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19042
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue19042] Idle: add option to autosave 'Untitled' edit window

2013-09-17 Thread Bruce Sherwood

Bruce Sherwood added the comment:

Very nice, Terry. Good point about positive vs. negative specifications. I 
think maybe your Prompt to Save versus Autosave is the best scheme, because 
one is specifying whether or not to do something active (namely, put up a 
save dialog).

--
nosy: +Bruce.Sherwood

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue19042
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com