Patchwork [2,of,3] edit: allow to configure the suffix of the temporary filename

login
register
mail settings
Submitter Jordi Gutiérrez Hermoso
Date March 18, 2016, 8:45 p.m.
Message ID <9c3a76f1439bf0e701d0.1458333937@Iris>
Download mbox | patch
Permalink /patch/13938/
State Superseded
Commit 87f92d6f0bc358d64991292f461deed157f3168f
Headers show

Comments

Jordi Gutiérrez Hermoso - March 18, 2016, 8:45 p.m.
# HG changeset patch
# User Jordi Gutiérrez Hermoso <jordigh@octave.org>
# Date 1458333017 14400
#      Fri Mar 18 16:30:17 2016 -0400
# Node ID 9c3a76f1439bf0e701d00343115db01949aedf18
# Parent  81813cad034146e598955b2b726093340a1c4c22
edit: allow to configure the suffix of the temporary filename

Sometimes, we can pick a more appropriate default suffix than ".txt",
for example, diffs could have a ".diff" suffix.

Patch

diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -900,12 +900,15 @@  class ui(object):
             self.write(*msg, **opts)
 
     def edit(self, text, user, extra=None, editform=None, pending=None):
-        extra_defaults = { 'prefix': 'editor' }
+        extra_defaults = {
+            'prefix': 'editor',
+            'suffix': '.txt',
+        }
         if extra is not None:
             extra_defaults.update(extra)
         extra = extra_defaults
         (fd, name) = tempfile.mkstemp(prefix='hg-' + extra['prefix'] + '-',
-                                      suffix=".txt", text=True)
+                                      suffix=extra['suffix'], text=True)
         try:
             f = os.fdopen(fd, "w")
             f.write(text)