[PATCH] ui: refactor and introduce editfile
Brodie Rao
brodie at bitheap.org
Sat Aug 28 09:39:04 CDT 2010
On Aug 25, 2010, at 12:13 PM, Mads Kiilerich wrote:
> # HG changeset patch
> # User Mads Kiilerich <mads at kiilerich.com>
> # Date 1282752611 -7200
> # Branch stable
> # Node ID 89fc6341853d1a660e5c529e3d812085139508d1
> # Parent 927d63be166b11e16756eea3b9e9f8b82620dbbd
> ui: refactor and introduce editfile
>
> Contrary to ui.edit this will show the right filename when file
> content is
> edited.
>
> diff --git a/mercurial/ui.py b/mercurial/ui.py
> --- a/mercurial/ui.py
> +++ b/mercurial/ui.py
> @@ -522,6 +522,7 @@
> opts['label'] = opts.get('label', '') + ' ui.debug'
> self.write(*msg, **opts)
> def edit(self, text, user):
> + '''let the user edit text in a temporary file using
> configured editor'''
> (fd, name) = tempfile.mkstemp(prefix="hg-editor-",
> suffix=".txt",
> text=True)
> try:
> @@ -529,12 +530,7 @@
> f.write(text)
> f.close()
>
> - editor = self.geteditor()
> -
> - util.system("%s \"%s\"" % (editor, name),
> - environ={'HGUSER': user},
> - onerr=util.Abort, errprefix=_("edit failed"))
> -
> + self.editfile(name, user)
> f = open(name)
> t = f.read()
> f.close()
> @@ -543,6 +539,14 @@
>
> return t
>
> + def editfile(self, filename, user):
> + '''let the user edit a file using configured editor'''
> + editor = self.geteditor()
> +
> + util.system("%s \"%s\"" % (editor, filename),
> + environ={'HGUSER': user},
> + onerr=util.Abort, errprefix=_("edit failed"))
> +
What if I want to call ui.editfile() even though there's no configured
username? What should I pass?
Also, it'd be nice if it were documented that HGUSER is available to
the editor. I see at one point long ago it was used in hgeditor when
invoking gpg, but it no longer uses it.
> def traceback(self, exc=None):
> '''print exception traceback if traceback printing enabled.
> only to call in exception handler. returns true if traceback
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel at selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
More information about the Mercurial-devel
mailing list