ui: allow open editor with custom filename
authorMykola Nikishov <mn@mn.com.ua>
Sat, 21 Nov 2015 22:04:09 +0200
changeset 27153 3553e40d0770
parent 27152 ac27b1b3be85
child 27154 3bc7919fb215
ui: allow open editor with custom filename By default, editor will use temp file named after hard-coded pattern 'hg-editor-XXX.txt' which makes it impossible for extensions to use another filename if desired. Now the middle part of the pattern ('editor') can be changed by setting extra['prefix'].
mercurial/ui.py
--- a/mercurial/ui.py	Mon Nov 30 20:45:07 2015 +0000
+++ b/mercurial/ui.py	Sat Nov 21 22:04:09 2015 +0200
@@ -846,10 +846,12 @@
             self.write(*msg, **opts)
 
     def edit(self, text, user, extra=None, editform=None, pending=None):
-        if extra is None:
-            extra = {}
-        (fd, name) = tempfile.mkstemp(prefix="hg-editor-", suffix=".txt",
-                                      text=True)
+        extra_defaults = { 'prefix': 'editor' }
+        if extra is not None:
+            extra_defaults.update(extra)
+        extra = extra_defaults
+        (fd, name) = tempfile.mkstemp(prefix='hg-' + extra['prefix'] + '-',
+                                      suffix=".txt", text=True)
         try:
             f = os.fdopen(fd, "w")
             f.write(text)