On Wednesday, 31 January 2018 15.53.41 WET Jean-Marc Lasgouttes wrote:
> Le 31/01/2018 à 16:29, José Abílio Matos a écrit :
> > My idea, in the last message, was for lyx2lyx to add the -lyxXX suffix
> > to the file name by default when called with the --backup option.
> > 
> > E.g.
> > 
> > lyx2lyx --backup myfile.lyx would result in the original file to be
> > called myfile-lyxXX.lyx (where XX is version).
> 
> myfile-lyxXX.lyx~, please.
> 
> JMarc

How about the following patch?

PS: Ignore the last chunk as it is a simple white space change and unrelated to 
this.

Regards,
-- 
José Abílio
diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index 7cabe6fce1..a16322dd9a 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -137,6 +137,10 @@ int const LYX_FORMAT = LYX_FORMAT_LYX;
 typedef map<string, bool> DepClean;
 typedef map<docstring, pair<InsetLabel const *, Buffer::References> > RefCache;
 
+struct Version_file_format {
+	string version;
+	int format;
+};
 } // namespace
 
 
@@ -1327,14 +1331,41 @@ Buffer::ReadStatus Buffer::convertLyXFormat(FileName const & fn,
 
 
 FileName Buffer::getBackupName() const {
+	vector<Version_file_format> const file_formats = {
+	  {"23", 544},
+	  {"22", 508},
+	  {"21", 474},
+	  {"20", 413},
+	  {"16", 345},
+	  {"15", 276},
+	  {"14", 245},
+	  {"13", 221},
+	  {"12", 220},
+	  {"1163", 218},
+	  {"116", 217},
+	  {"115", 216},
+	  {"11", 215},
+	  {"010", 210},
+	  {"006", 200}
+	};
+
 	FileName const & fn = fileName();
 	string const fname = fn.onlyFileNameWithoutExt();
 	string const fext  = fn.extension() + "~";
 	string const fpath = lyxrc.backupdir_path.empty() ?
 		fn.onlyPath().absFileName() :
 		lyxrc.backupdir_path;
-	string const fform = convert<string>(d->file_format);
-	string const backname = fname + "-lyxformat-" + fform;
+	string const current_version = convert<string>(lyx_version_major) + convert<string>(lyx_version_minor);
+
+	string original_version = current_version;
+	for (const auto & ver: file_formats) {
+		if (d->file_format > ver.format) {
+			break;
+		}
+		original_version = ver.version;
+	}
+
+	string const backname = fname + "-lyx" + original_version;
 	FileName backup(addName(fpath, addExtension(backname, fext)));
 
 	// limit recursion, just in case
@@ -4710,7 +4741,7 @@ void Buffer::updateBuffer(UpdateScope scope, UpdateType utype) const
 		// cache was invalid, although we didn't find that out until now. So we
 		// have to do it all again.
 		// That said, the only thing we really need to do is update the citation
-		// labels. Nothing else will have changed. So we could create a new 
+		// labels. Nothing else will have changed. So we could create a new
 		// UpdateType that would signal that fact, if we needed to do so.
 		parit = cbuf.par_iterator_begin();
 		updateBuffer(parit, utype);

Reply via email to