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


Groups > comp.lang.python > #17779

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

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <cameron@cskk.homeip.net>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'sure.': 0.05; 'received:edu.au': 0.07; 'compute': 0.09; 'rewritten': 0.09; '"don\'t': 0.16; 'advice:': 0.16; 'finney': 0.16; 'from:addr:cs': 0.16; 'from:addr:zip.com.au': 0.16; 'from:name:cameron simpson': 0.16; 'message-id:@cskk.homeip.net': 0.16; 'not;': 0.16; 'received:202.125.174': 0.16; 'received:202.125.174.133': 0.16; 'received:boardofstudies.nsw.edu.au': 0.16; 'received:cskk.homeip.net': 0.16; 'received:harvey.boardofstudies.nsw.edu.au': 0.16; 'received:homeip.net': 0.16; 'received:nsw.edu.au': 0.16; 'unchanged,': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'file,': 0.19; 'cc:no real name:2**0': 0.20; 'cheers,': 0.20; '(or': 0.22; "doesn't": 0.22; 'asked': 0.22; 'header:In-Reply- To:1': 0.22; 'changed': 0.23; 'personally,': 0.23; 'cc:2**0': 0.24; 'writes:': 0.25; "i'm": 0.26; 'compare': 0.28; 'concern': 0.28; "wasn't": 0.28; 'exit': 0.29; 'cc:addr:python.org': 0.29; 'hash': 0.30; 'invoke': 0.30; 'subject:?': 0.31; "i've": 0.31; 'certainly': 0.32; 'header:User-Agent:1': 0.33; 'actually': 0.33; 'force': 0.34; 'anything': 0.34; 'parse': 0.34; 'wright': 0.34; 'file': 0.36; 'received:au': 0.36; 'bound': 0.37; 'miles': 0.37; 'but': 0.37; 'steven': 0.38; 'why': 0.39; "it's": 0.40; 'address': 0.61; 'efficient': 0.62; 'back': 0.62; 'act': 0.65; 'received:202': 0.66; 'limit': 0.67; 'anything,': 0.73; 'cameron': 0.73; '"did': 0.84; 'change?': 0.84; 'distinguish': 0.84; 'something.': 0.84; 'scenario': 0.93; 'subject: $': 0.97
Date Fri, 23 Dec 2011 17:32:16 +1100
From Cameron Simpson <cs@zip.com.au>
To Ben Finney <ben+python@benfinney.id.au>
Subject Re: Idiom for shelling out to $EDITOR/$PAGER?
MIME-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Disposition inline
Content-Transfer-Encoding 8bit
In-Reply-To <877h1nn7ej.fsf@benfinney.id.au>
User-Agent Mutt/1.5.21 (2010-09-15)
References <877h1nn7ej.fsf@benfinney.id.au>
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4018.1324621939.27778.python-list@python.org> (permalink)
Lines 46
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1324621939 news.xs4all.nl 6871 [2001:888:2000:d::a6]:57335
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17779

Show key headers only | View raw


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 | 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