Il 09/09/2011 19:45, Tommaso Cucinotta ha scritto:
Il 09/09/2011 14:31, Jean-Marc Lasgouttes ha scritto:
Perosnally, I'd prefer to avoid this syntax of 'everything until the
end of line', and stick with the good old
-x "buffer-export latex \"/path/to/file name with space.tex\""
which LyX should be able to handle transparently with a few changes.
How would you like to use that from the mini-command-buffer ?
Something like this ?
I also checked the front-end part by Guenter, and I have to say we had
that potential issue
that
lyx -o path -e latex
would work, but
lyx -e latex -o path
would not.
So, in the end, I thought the best way to support this, given how the
command-line parser is currently structured, was through a dedicated
separate switch with 2 arguments:
lyx -E latex /path/dest.tex
or
lyx --export-to latex /path/to/dest.tex
This is implemented in the attached patch. Can I commit to trunk, or do
you have further comments ?
One very last remark: the only alternative I can actually think of, is
to have 2 possible formats for the "-e" argument: either a format-name,
or a filename with extension. In the latter case, the export format
would be inferred by extension. That would mean:
lyx -e /path/to/myfile.tex mydoc.lyx
I have to admit I used myself multiple times exactly this syntax by
mistake in writing Makefiles, then I switched to the right syntax after
seeing it wasn't working. Of course, in case of multiple formats with
the same extension, this type of syntax would have to prefer one export
type over another.
T.
Index: src/LyX.cpp
===================================================================
--- src/LyX.cpp (revisione 39648)
+++ src/LyX.cpp (copia locale)
@@ -112,6 +112,9 @@
string geometryArg;
+/// Output filename to be used when issuing an export request (-e).
+string output_file;
+
LyX * singleton_ = 0;
void showFileError(string const & error)
@@ -1054,6 +1057,9 @@
" Look on Tools->Preferences->File formats->Format\n"
" to get an idea which parameters should be passed.\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"
+ " and filename is the destination filename.\n"
"\t-i [--import] fmt file.xxx\n"
" where fmt is the import format of choice\n"
" and file.xxx is the file to be imported.\n"
@@ -1123,6 +1129,24 @@
}
+int parse_export_to(string const & type, string const & output_file, string & batch)
+{
+ if (type.empty()) {
+ lyxerr << to_utf8(_("Missing file type [eg latex, ps...] after "
+ "--export-to switch")) << endl;
+ exit(1);
+ }
+ if (output_file.empty()) {
+ lyxerr << to_utf8(_("Missing destination filename after "
+ "--export-to switch")) << endl;
+ exit(1);
+ }
+ batch = "buffer-export " + type + " " + output_file;
+ use_gui = false;
+ return 2;
+}
+
+
int parse_export(string const & type, string const &, string & batch)
{
if (type.empty()) {
@@ -1216,8 +1240,10 @@
cmdmap["-userdir"] = parse_userdir;
cmdmap["-x"] = parse_execute;
cmdmap["--execute"] = parse_execute;
- cmdmap["-e"] = parse_export;
+ cmdmap["-e"] = parse_export;
cmdmap["--export"] = parse_export;
+ cmdmap["-E"] = parse_export_to;
+ cmdmap["--export-to"] = parse_export_to;
cmdmap["-i"] = parse_import;
cmdmap["--import"] = parse_import;
cmdmap["-geometry"] = parse_geometry;
Index: src/Buffer.h
===================================================================
--- src/Buffer.h (revisione 39648)
+++ src/Buffer.h (copia locale)
@@ -602,11 +602,12 @@
- ///
- bool doExport(std::string const & format, bool put_in_tempdir,
+ /// target is a format name optionally followed by a space
+ /// and a destination file-name
+ bool doExport(std::string const & target, bool put_in_tempdir,
bool includeall, std::string & result_file) const;
///
- bool doExport(std::string const & format, bool put_in_tempdir,
+ bool doExport(std::string const & target, bool put_in_tempdir,
bool includeall = false) const;
///
bool preview(std::string const & format, bool includeall = false) const;
Index: src/Buffer.cpp
===================================================================
--- src/Buffer.cpp (revisione 39648)
+++ src/Buffer.cpp (copia locale)
@@ -1928,10 +1928,18 @@
case LFUN_BUFFER_EXPORT: {
docstring const arg = cmd.argument();
- enable = arg == "custom" || params().isExportable(to_utf8(arg));
+ if (arg == "custom") {
+ enable = true;
+ break;
+ }
+ string format = to_utf8(arg);
+ size_t pos = format.find(' ');
+ if (pos != string::npos)
+ format = format.substr(0, pos);
+ enable = params().isExportable(format);
if (!enable)
flag.message(bformat(
- _("Don't know how to export to format: %1$s"), arg));
+ _("Don't know how to FUCK export to format: %1$s"), arg));
break;
}
@@ -3391,9 +3399,16 @@
}
-bool Buffer::doExport(string const & format, bool put_in_tempdir,
- bool includeall, string & result_file) const
+bool Buffer::doExport(string const & target, bool put_in_tempdir,
+ bool includeall, string & result_file) const
{
+ string format = target;
+ string filename;
+ size_t pos = target.find(' ');
+ if (pos != string::npos) {
+ filename = target.substr(pos + 1, target.length() - pos - 1);
+ format = target.substr(0, pos);
+ }
MarkAsExporting exporting(this);
string backend_format;
OutputParams runparams(¶ms().encoding());
@@ -3439,10 +3454,12 @@
runparams.flavor = OutputParams::XETEX;
}
- string filename = latexName(false);
- filename = addName(temppath(), filename);
- filename = changeExtension(filename,
- formats.extension(backend_format));
+ if (filename.empty()) {
+ filename = latexName(false);
+ filename = addName(temppath(), filename);
+ filename = changeExtension(filename,
+ formats.extension(backend_format));
+ }
// Plain text backend
if (backend_format == "text") {
@@ -3596,15 +3613,15 @@
}
-bool Buffer::doExport(string const & format, bool put_in_tempdir,
+bool Buffer::doExport(string const & target, bool put_in_tempdir,
bool includeall) const
{
string result_file;
// (1) export with all included children (omit \includeonly)
- if (includeall && !doExport(format, put_in_tempdir, true, result_file))
+ if (includeall && !doExport(target, put_in_tempdir, true, result_file))
return false;
// (2) export with included children only
- return doExport(format, put_in_tempdir, false, result_file);
+ return doExport(target, put_in_tempdir, false, result_file);
}