On Tue, Feb 28, 2017 at 12:47:12AM +0100, Guillaume Munch wrote:
> commit a1faa41c839089a9f21323af6540926eae90ec6f
> Author: Guillaume Munch <g...@lyx.org>
> Date:   Mon Feb 27 20:43:11 2017 +0100
> 
>     buffer-export without argument exports the default format
>     
>     buffer-export is proposed as a default binding in the preferences so now 
> it does
>     what a user expects when binding it to a key.

Thanks for this commit. What do you think of the attached patch that
extends it so that one can export to the default format from the command
line?

Do you agree that, because of how we pass arguments, there is no simple
way to get it to work with -E (see the FIXME in the patch)?

If you think the idea is good, and agree there is no simple way to get
it to work with -E, then I would just remove that part of the patch, and
would document in --help for -E that "default" does not work as
described for -e.

In any case, the user can easily use bash to extend -e to -E on their
own (i.e., they can rename the output file).

Scott
From 6ea39a90b535499384743787f0bcff6f9c3886e8 Mon Sep 17 00:00:00 2001
From: Scott Kostyshak <skost...@lyx.org>
Date: Mon, 27 Feb 2017 22:21:51 -0500
Subject: [PATCH] Allow export of default format from CL with -e/-E

The command

  lyx -e "default" file.lyx

now exports using the default format (specified in document
settings).

This commit relies on a1faa41c, which implements the needed
functionality at the LFUN level.

Minor note: this commit has the negative effect that if the user has
defined a format with short name "default", it is now impossible to
export to the "default" format from the command line (unless the
custom-defined "default" format is actually the default format).
---
 src/LyX.cpp | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/LyX.cpp b/src/LyX.cpp
index 0633bcb..ed0ece7 100644
--- a/src/LyX.cpp
+++ b/src/LyX.cpp
@@ -1181,7 +1181,8 @@ int parse_help(string const &, string const &, string &)
                  "                  where fmt is the export format of choice. 
Look in\n"
                  "                  Tools->Preferences->File Handling->File 
Formats->Short Name\n"
                  "                  to see which parameter (which differs from 
the format name\n"
-                 "                  in the File->Export menu) should be 
passed.\n"
+                 "                  in the File->Export menu) should be 
passed. If \"default\"\n"
+                 "                  is specified, the document default format 
will be used.\n"
                  "                  Note that the order of -e and -x switches 
matters.\n"
                  "\t-E [--export-to] fmt filename\n"
                  "                  where fmt is the export format of choice 
(see --export),\n"
@@ -1274,7 +1275,12 @@ int parse_export_to(string const & type, string const & 
output_file, string & ba
                                         "--export-to switch")) << endl;
                exit(1);
        }
-       batch = "buffer-export " + type + " " + output_file;
+       if (type == "default") {
+               // FIXME this doesn't work because LFUN can't know whether 
"output_file" is fmt or output file.
+               batch = "buffer-export " + ' ' + output_file;
+       }
+       else
+               batch = "buffer-export " + type + " " + output_file;
        use_gui = false;
        return 2;
 }
@@ -1287,7 +1293,10 @@ int parse_export(string const & type, string const &, 
string & batch)
                                         "--export switch")) << endl;
                exit(1);
        }
-       batch = "buffer-export " + type;
+       if (type == "default")
+               batch = "buffer-export";
+       else
+               batch = "buffer-export " + type;
        use_gui = false;
        return 1;
 }
-- 
2.7.4

Attachment: signature.asc
Description: PGP signature

Reply via email to