f433f96e0b21

Allow file extensions
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Wed, 11 Oct 2017 11:14:41 -0400
parents bfd9b1f910a3
children ce2f184901ce 2462583456f0
branches/tags (none)
files weechat/python/autoload/editor.py

Changes

--- a/weechat/python/autoload/editor.py	Wed Oct 11 11:09:36 2017 -0400
+++ b/weechat/python/autoload/editor.py	Wed Oct 11 11:14:41 2017 -0400
@@ -22,8 +22,8 @@
 weechat_version = 0
 
 
-def get_data(initial_data):
-    with tempfile.NamedTemporaryFile(suffix=".tmp", mode="w+") as tf:
+def get_data(suffix, initial_data):
+    with tempfile.NamedTemporaryFile(suffix=".%s" % suffix, mode="w+") as tf:
         tf.write(initial_data)
         tf.flush()
 
@@ -38,9 +38,11 @@
         return tf.readlines()
 
 def editor(data, buffer, args):
+    suffix = args or "tmp"
+
     line = weechat.buffer_get_string(buffer, "input")
 
-    data = get_data(line)
+    data = get_data(suffix, line)
     if data:
         weechat.command(buffer, "/input delete_line")
 
@@ -59,8 +61,8 @@
         weechat.hook_command(
             SCRIPT_COMMAND,
             'Open $EDITOR to compose a message',
-            '',
-            '',
+            '[file-extension]',
+            'If an argument is given, it will be used as the extension for the temporary file.',
             '',
             'editor',
             '')