From 5c2d04999619f8b8890d931e28c133212ce20fd0 Mon Sep 17 00:00:00 2001 From: Guillaume Munch Date: Sun, 20 Dec 2015 16:37:29 +0000 Subject: [PATCH] Add \save_transient_properties parameter (#9841) Increment LyX format to 504. With this new parameter, the user can indicate that some other parameters that are frequently switched must not be recorded in the file (as if they were a setting specific to the user or transient, rather than a document setting). This will play nicer with version control systems. See the discussion, e.g.: http://thread.gmane.org/gmane.editors.lyx.devel/157824/focus=157993 (third solution mentioned) TODO: * The interface remains to be set up. We cannot change this setting from LyX for now. * If save_transient_properties is false, we should read the user setting as a per-user-per-document (session) setting (e.g. like the cursor position). * Once the above is done, we can treat \justification the same way (but it would be even better if \justification was moved to lyxrc). --- development/FORMAT | 7 +++++++ lib/lyx2lyx/LyX.py | 3 ++- lib/lyx2lyx/lyx_2_2.py | 21 ++++++++++++++++++++- src/Buffer.cpp | 6 ++++-- src/BufferParams.cpp | 18 +++++++++++++++--- src/BufferParams.h | 5 ++++- src/tex2lyx/Preamble.cpp | 2 ++ src/tex2lyx/Preamble.h | 1 + src/version.h | 4 ++-- 9 files changed, 57 insertions(+), 10 deletions(-) diff --git a/development/FORMAT b/development/FORMAT index c4d9b4d02f..cbd5064bfb 100644 --- a/development/FORMAT +++ b/development/FORMAT @@ -11,6 +11,13 @@ adjustments are made to tex2lyx and bugs are fixed in lyx2lyx. ----------------------- +2015-12-20 Guillaume Munch + * Format incremented to 504 + New parameter "\save_transient_properties". When set to false, various + settings are no longer written to the file (only with a default + value). These include for now \tracking_changes and \output_changes. + Bug 9841. + 2015-11-24 Uwe Stöhr * Format incremented to 503 No new parameters. diff --git a/lib/lyx2lyx/LyX.py b/lib/lyx2lyx/LyX.py index d9ad0d6e41..6bc0fb6f7c 100644 --- a/lib/lyx2lyx/LyX.py +++ b/lib/lyx2lyx/LyX.py @@ -80,12 +80,13 @@ format_relation = [("0_06", [200], minor_versions("0.6" , 4)), ("1_1_6_3", [218], ["1.1", "1.1.6.3","1.1.6.4"]), ("1_2", [220], minor_versions("1.2" , 4)), ("1_3", [221], minor_versions("1.3" , 7)), + # Note that range(i,j) is up to j *excluded*. ("1_4", list(range(222,246)), minor_versions("1.4" , 5)), ("1_5", list(range(246,277)), minor_versions("1.5" , 7)), ("1_6", list(range(277,346)), minor_versions("1.6" , 10)), ("2_0", list(range(346,414)), minor_versions("2.0" , 8)), ("2_1", list(range(414,475)), minor_versions("2.1" , 0)), - ("2_2", list(range(475,504)), minor_versions("2.2" , 0)) + ("2_2", list(range(475,505)), minor_versions("2.2" , 0)) ] #################################################################### diff --git a/lib/lyx2lyx/lyx_2_2.py b/lib/lyx2lyx/lyx_2_2.py index 5a639cd239..53614206f6 100644 --- a/lib/lyx2lyx/lyx_2_2.py +++ b/lib/lyx2lyx/lyx_2_2.py @@ -2184,6 +2184,23 @@ def revert_verbatim_star(document): revert_verbatim(document, True) +def convert_save_props(document): + " Add save_transient_properties parameter. " + i = find_token(document.header, '\\origin', 0) + if i == -1: + document.warning("Malformed lyx document: Missing '\\origin'.") + return + document.header.insert(i, '\\save_transient_properties true') + + +def revert_save_props(document): + " Remove save_transient_properties parameter. " + i = find_token(document.header, "\\save_transient_properties", 0) + if i == -1: + return + del document.header[i] + + ## # Conversion hub # @@ -2221,10 +2238,12 @@ convert = [ [500, []], [501, [convert_fontsettings]], [502, []], - [503, []] + [503, []], + [504, [convert_save_props]] ] revert = [ + [503, [revert_save_props]], [502, [revert_verbatim_star]], [501, [revert_solution]], [500, [revert_fontsettings]], diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 54a1ee4ac9..37dcbca014 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2765,12 +2765,14 @@ void Buffer::dispatch(FuncRequest const & func, DispatchResult & dr) break; case LFUN_CHANGES_TRACK: - undo().recordUndoBufferParams(CursorData()); + if (params().save_transient_properties) + undo().recordUndoBufferParams(CursorData()); params().track_changes = !params().track_changes; break; case LFUN_CHANGES_OUTPUT: - undo().recordUndoBufferParams(CursorData()); + if (params().save_transient_properties) + undo().recordUndoBufferParams(CursorData()); params().output_changes = !params().output_changes; if (params().output_changes) { bool dvipost = LaTeXFeatures::isAvailable("dvipost"); diff --git a/src/BufferParams.cpp b/src/BufferParams.cpp index 618aed3d3a..382d1f928b 100644 --- a/src/BufferParams.cpp +++ b/src/BufferParams.cpp @@ -369,6 +369,7 @@ BufferParams::BufferParams() biblio_style = "plain"; use_bibtopic = false; use_indices = false; + save_transient_properties = true; track_changes = false; output_changes = false; use_default_options = true; @@ -673,6 +674,8 @@ string BufferParams::readToken(Lexer & lex, string const & token, frontend::Alert::warning(_("Document class not available"), msg, true); } + } else if (token == "\\save_transient_properties") { + lex >> save_transient_properties; } else if (token == "\\origin") { lex.eatLine(); origin = lex.getString(); @@ -1015,6 +1018,9 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const // The top of the file is written by the buffer. // Prints out the buffer info into the .lyx file given by file + os << "\\save_transient_properties " + << convert(save_transient_properties) << '\n'; + // the document directory (must end with a path separator) // realPath() is used to resolve symlinks, while addPath(..., "") // ensures a trailing path separator. @@ -1273,9 +1279,15 @@ void BufferParams::writeFile(ostream & os, Buffer const * buf) const } } - os << "\\tracking_changes " << convert(track_changes) << '\n' - << "\\output_changes " << convert(output_changes) << '\n' - << "\\html_math_output " << html_math_output << '\n' + os << "\\tracking_changes " + << (save_transient_properties ? convert(track_changes) : "false") + << '\n'; + + os << "\\output_changes " + << (save_transient_properties ? convert(output_changes) : "false") + << '\n'; + + os << "\\html_math_output " << html_math_output << '\n' << "\\html_css_as_file " << html_css_as_file << '\n' << "\\html_be_strict " << convert(html_be_strict) << '\n'; diff --git a/src/BufferParams.h b/src/BufferParams.h index 79af8f21a6..caae01dfec 100644 --- a/src/BufferParams.h +++ b/src/BufferParams.h @@ -381,11 +381,14 @@ public: bool use_bibtopic; /// Split the index? bool use_indices; - /// revision tracking for this buffer ? + /// Save trensient properties? + bool save_transient_properties; + /// revision tracking for this buffer ? (this is a transient property) bool track_changes; /** This param decides whether change tracking marks should be used * in output (irrespective of how these marks are actually defined; * for instance, they may differ for DVI and PDF generation) + * This is a transient property. */ bool output_changes; /// diff --git a/src/tex2lyx/Preamble.cpp b/src/tex2lyx/Preamble.cpp index 01587cc02d..05c3c406f6 100644 --- a/src/tex2lyx/Preamble.cpp +++ b/src/tex2lyx/Preamble.cpp @@ -536,6 +536,7 @@ Preamble::Preamble() : one_language(true), explicit_babel(false), h_secnumdepth = "3"; h_shortcut[0] = "idx"; h_spacing = "single"; + h_save_transient_properties = "true"; h_suppress_date = "false"; h_textclass = "article"; h_tocdepth = "3"; @@ -1102,6 +1103,7 @@ bool Preamble::writeLyXHeader(ostream & os, bool subdoc, string const & outfiled << "\\lyxformat " << LYX_FORMAT << '\n' << "\\begin_document\n" << "\\begin_header\n" + << "\\save_transient_properties " << h_save_transient_properties << "\n" << "\\origin " << origin << "\n" << "\\textclass " << h_textclass << "\n"; string const raw = subdoc ? empty_string() : h_preamble.str(); diff --git a/src/tex2lyx/Preamble.h b/src/tex2lyx/Preamble.h index 1c3fe66f23..a8bf4ee059 100644 --- a/src/tex2lyx/Preamble.h +++ b/src/tex2lyx/Preamble.h @@ -191,6 +191,7 @@ private: std::string h_shortcut[99]; std::string h_spacing; std::string h_suppress_date; + std::string h_save_transient_properties; std::string h_textclass; std::string h_tocdepth; std::string h_tracking_changes; diff --git a/src/version.h b/src/version.h index fff8c5a078..3f571d14f1 100644 --- a/src/version.h +++ b/src/version.h @@ -32,8 +32,8 @@ extern char const * const lyx_version_info; // Do not remove the comment below, so we get merge conflict in // independent branches. Instead add your own. -#define LYX_FORMAT_LYX 503 // uwestoehr: support for verbatim* environment -#define LYX_FORMAT_TEX2LYX 503 +#define LYX_FORMAT_LYX 504 // gm: add save_transient_properties parameter +#define LYX_FORMAT_TEX2LYX 504 #if LYX_FORMAT_TEX2LYX != LYX_FORMAT_LYX #ifndef _MSC_VER -- 2.39.2