Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #17779
| Date | 2011-12-23 17:32 +1100 |
|---|---|
| From | Cameron Simpson <cs@zip.com.au> |
| Subject | Re: Idiom for shelling out to $EDITOR/$PAGER? |
| References | <877h1nn7ej.fsf@benfinney.id.au> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.4018.1324621939.27778.python-list@python.org> (permalink) |
On 23Dec2011 17:12, Ben Finney <ben+python@benfinney.id.au> wrote:
| Cameron Simpson <cs@zip.com.au> writes:
| > On 22Dec2011 22:16, Tim Chase <python.list@tim.thechases.com> wrote:
| > | -proper & efficient detection of file-change, to know whether the
| > | user actually did anything
| >
| > Wait for the editor to exit?
| > In that scenario I go for:
| > - wait for edit to exit
| > - if exit status 0 and file non-empty, trust it
| > (subject to parse issues afterwards of course)
|
| That doesn't address the concern Tim raised: did the user actually do
| anything, did the file change?
I'm not sure it matters. It's _quicker_ to do nothing if the file is
unchanged, but is it bad to act on it anyway?
| The exit status of text editors are not bound to distinguish “buffer was
| modified”, and certainly don't do so in any standard way.
Indeed not; my 0 above is just "did you user exit the editor or did it
crash"?
| My advice:
| * Compute a before-edit hash of the text (MD5 or SHA-1 would be fine).
| * Invoke the editor on that text.
| * Wait for (or detect) the exit of the editor process.
| * Compute an after-edit hash of the text resulting from the editor.
| * Compare the hashes to see whether the text changed.
Sure. But still, if you're able to act on a changed file, why not also
act on an unchanged file? The user asked to change things; take what you
got back and proceed!
And personally, as a user, I've often rewritten an unchanged file to
force a recompute of something.
Cheers,
--
Cameron Simpson <cs@zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/
"Don't you know the speed limit is 55 miles per hour???"
"Yeah, but I wasn't going to be out that long."
- Steven Wright
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: Idiom for shelling out to $EDITOR/$PAGER? Cameron Simpson <cs@zip.com.au> - 2011-12-23 17:02 +1100
Re: Idiom for shelling out to $EDITOR/$PAGER? Ben Finney <ben+python@benfinney.id.au> - 2011-12-23 17:12 +1100
Re: Idiom for shelling out to $EDITOR/$PAGER? Cameron Simpson <cs@zip.com.au> - 2011-12-23 17:32 +1100
Re: Idiom for shelling out to $EDITOR/$PAGER? Ben Finney <ben+python@benfinney.id.au> - 2011-12-23 23:06 +1100
Re: Idiom for shelling out to $EDITOR/$PAGER? Tim Chase <python.list@tim.thechases.com> - 2011-12-23 06:28 -0600
Re: Idiom for shelling out to $EDITOR/$PAGER? Owen Jacobson <angrybaldguy@gmail.com> - 2011-12-23 21:41 -0500
csiph-web