Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17778

Re: Idiom for shelling out to $EDITOR/$PAGER?

From Ben Finney <ben+python@benfinney.id.au>
Newsgroups comp.lang.python
Subject Re: Idiom for shelling out to $EDITOR/$PAGER?
References <4EF4009E.8010109@tim.thechases.com> <mailman.4017.1324620143.27778.python-list@python.org>
Date 2011-12-23 17:12 +1100
Message-ID <877h1nn7ej.fsf@benfinney.id.au> (permalink)
Organization Unlimited download news at news.astraweb.com

Show all headers | View raw


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?

The exit status of text editors are not bound to distinguish “buffer was
modified”, and certainly don't do so in any standard way.

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.

-- 
 \       “Come on Milhouse, there's no such thing as a soul! It's just |
  `\      something they made up to scare kids, like the Boogie Man or |
_o__)                          Michael Jackson.” —Bart, _The Simpsons_ |
Ben Finney

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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