Il 09/09/2011 08:10, Guenter Milde ha scritto:
Presumably what is needed here is a "buffer-export-as" LFUN.
or I don't know if one can add an optional argument to the same
buffer-export LFUN, i.e.:
Alt-x buffer-export ps
Alt-x buffer-export ps /tmp/foo.ps
... as implemented in the attached patch.
However, the above-proposed command line syntax seems more "natural" to me.
How about something in the line of:
@@ -1126,7 +1126,12 @@ int parse_execute(string const& arg, string const&,
string& batch)
return 1;
}
-
+int parse_output_file(string const& filename, string const&, string& batch)
+{
+ /* set the output_file variable */
+ return 1;
+}
+
int parse_export(string const& type, string const&, string& batch)
{
if (type.empty()) {
@@ -1134,7 +1139,12 @@ int parse_export(string const& type, string const&,
string& batch)
"--export switch"))<< endl;
exit(1);
}
- batch = "buffer-export " + type;
+ if (output_file != "") {
+ batch = "buffer-export-as " + type + output_file;
are you sure output_file has already been set at this point ? I'm not an
expert of this command-line parsing part of LyX, however I suspect
parse_output_file() might not have been called yet when you call
parse_export(), especially if the command-line is something like:
lyx -e ps --output-file=/path/to/myfile.ps
Also, on the side of the "backend", let me propose the attached patch,
that changes slightly the meaning of the first argument to
Buffer::doExport().
Apparently, filename with spaces are supported and work as well:
- when invoked from the mini-command: Alt-x buffer-export latex
/path/to/file name with space.tex
- when invoked via -x: lyx -x "buffer-export latex /path/to/file name
with space.tex"
So, if you can finish the support for the command-line option, I guess
we are done.
Bye,
T.
Index: src/Buffer.h
===================================================================
--- src/Buffer.h (revisione 39645)
+++ 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 39645)
+++ 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);
}