[LyX/master] Introduce InputGlobal (#12087)
Juergen Spitzmueller
spitz at lyx.org
Tue Jan 26 07:42:38 UTC 2021
commit 76eae4572e802d32a89afb4a3a89781b58a79108
Author: Juergen Spitzmueller <spitz at lyx.org>
Date: Tue Jan 26 08:42:39 2021 +0100
Introduce InputGlobal (#12087)
This is a variant of Input for layout files that only searches build
and system directories and thus allows "InputGlobal name.inc" in a user
file name.inc that attempts to modify its global counterpart.
---
lib/doc/Customization.lyx | 113 +++++++++++++++++++++++++++++++++++++++++-
lib/doc/de/Customization.lyx | 91 +++++++++++++++++++++++++++++++++-
lib/scripts/layout2layout.py | 7 ++-
src/TextClass.cpp | 16 +++++-
src/support/filetools.cpp | 14 +++--
src/support/filetools.h | 6 ++-
6 files changed, 231 insertions(+), 16 deletions(-)
diff --git a/lib/doc/Customization.lyx b/lib/doc/Customization.lyx
index f1df441..fcfc513 100644
--- a/lib/doc/Customization.lyx
+++ b/lib/doc/Customization.lyx
@@ -1,5 +1,5 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
-\lyxformat 601
+\lyxformat 605
\begin_document
\begin_header
\save_transient_properties true
@@ -109,7 +109,7 @@ logicalmkup
\branch OutDated
\selected 0
\filename_suffix 0
-\color #f5fae7
+\color #f5fae7 #0a0518
\end_branch
\index Index
\shortcut idx
@@ -10375,6 +10375,115 @@ stdclass.inc
\end_inset
, which contains most of the basic layouts.
+\change_inserted -712698321 1611646803
+
+\end_layout
+
+\begin_layout Description
+
+\change_inserted -712698321 1611646804
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1611646837
+InputGlobal
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1611646804
+<filename>
+\end_layout
+
+\end_inset
+
+] is a variant of the
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1611646804
+Input
+\end_layout
+
+\end_inset
+
+ command which does not look for files in the user directory.
+ This allows to create a file
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1611646804
+name.layout
+\end_layout
+
+\end_inset
+
+ or
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1611646804
+name.inc
+\end_layout
+
+\end_inset
+
+ in the user directory which includes a global file with the same name via
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1611646853
+InputGlobal name
+\end_layout
+
+\end_inset
+
+ or
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1611646855
+InputGlobal name.inc
+\end_layout
+
+\end_inset
+
+, respectively (with
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+
+\change_inserted -712698321 1611646804
+Input
+\end_layout
+
+\end_inset
+
+, the file would recursively include itself).
+ This way, you can modify global files without having to completely copy
+ them.
+\change_unchanged
+
\end_layout
\begin_layout Description
diff --git a/lib/doc/de/Customization.lyx b/lib/doc/de/Customization.lyx
index 49ef3ef..38e3378 100644
--- a/lib/doc/de/Customization.lyx
+++ b/lib/doc/de/Customization.lyx
@@ -1,5 +1,5 @@
#LyX 2.4 created this file. For more info see https://www.lyx.org/
-\lyxformat 600
+\lyxformat 605
\begin_document
\begin_header
\save_transient_properties true
@@ -117,7 +117,7 @@ logicalmkup
\branch OutDated
\selected 0
\filename_suffix 0
-\color #faf0e6
+\color background background
\end_branch
\index Stichwortverzeichnis
\shortcut idx
@@ -8267,6 +8267,93 @@ stdclass.inc
status collapsed
\begin_layout Plain Layout
+InputGlobal
+\end_layout
+
+\end_inset
+
+ [
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+<Dateiname>
+\end_layout
+
+\end_inset
+
+] ist eine Variante des Befehls
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+Input
+\end_layout
+
+\end_inset
+
+, die nicht nach Dateien im Benutzerverzeichnis sucht.
+ Das erlaubt es Ihnen, im Benutzerverzeichnis eine Datei
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+name.layout
+\end_layout
+
+\end_inset
+
+ oder
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+name.inc
+\end_layout
+
+\end_inset
+
+ anzulegen, die mit
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+InputGlobal name
+\end_layout
+
+\end_inset
+
+ bzw.
+
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+InputGlobal name.inc
+\end_layout
+
+\end_inset
+
+ eine globale Datei desselben Namens einbindet (mit
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
+Input
+\end_layout
+
+\end_inset
+
+ würde die Datei sich selbst einbinden).
+ Damit können Sie globale Dateien modifizieren, ohne sie komplett kopieren
+ zu müssen.
+\end_layout
+
+\begin_layout Description
+\begin_inset Flex Code
+status collapsed
+
+\begin_layout Plain Layout
InsetLayout
\end_layout
diff --git a/lib/scripts/layout2layout.py b/lib/scripts/layout2layout.py
index cc20a35..c38721a 100644
--- a/lib/scripts/layout2layout.py
+++ b/lib/scripts/layout2layout.py
@@ -11,7 +11,7 @@
# This script will update a .layout file to current format
# The latest layout format is also defined in src/TextClass.cpp
-currentFormat = 90
+currentFormat = 91
# Incremented to format 4, 6 April 2007, lasgouttes
@@ -307,6 +307,9 @@ currentFormat = 90
# Incremented to format 90, 11 December 2020 by spitz
# Use semantic label colors
+# Incremented to format 91, 25 January 2021 by spitz
+# InputGlobal tag
+
# Do not forget to document format change in Customization
# Manual (section "Declaring a new text class").
@@ -557,7 +560,7 @@ def convert(lines, end_format):
i += 1
continue
- if 87 <= format <= 90:
+ if 87 <= format <= 91:
# nothing to do.
i += 1
continue
diff --git a/src/TextClass.cpp b/src/TextClass.cpp
index 785c7a9..80cb6f8 100644
--- a/src/TextClass.cpp
+++ b/src/TextClass.cpp
@@ -59,7 +59,7 @@ namespace lyx {
// You should also run the development/tools/updatelayouts.py script,
// to update the format of all of our layout files.
//
-int const LAYOUT_FORMAT = 90; // spitz: semantic label colors
+int const LAYOUT_FORMAT = 91; // spitz: InputGlobal method
// Layout format for the current lyx file format. Controls which format is
@@ -165,6 +165,7 @@ enum TextClassTags {
TC_OUTPUTTYPE = 1,
TC_OUTPUTFORMAT,
TC_INPUT,
+ TC_INPUT_GLOBAL,
TC_STYLE,
TC_MODIFYSTYLE,
TC_PROVIDESTYLE,
@@ -249,6 +250,7 @@ LexerKeyword textClassTags[] = {
{ "htmltocsection", TC_HTMLTOCSECTION },
{ "ifcounter", TC_IFCOUNTER },
{ "input", TC_INPUT },
+ { "inputglobal", TC_INPUT_GLOBAL },
{ "insetlayout", TC_INSETLAYOUT },
{ "leftmargin", TC_LEFTMARGIN },
{ "maxcitenames", TC_MAXCITENAMES },
@@ -432,6 +434,7 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
bool modifystyle = false;
bool providestyle = false;
bool ifcounter = false;
+ bool only_global = false;
switch (static_cast<TextClassTags>(le)) {
@@ -459,6 +462,9 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
}
break;
+ case TC_INPUT_GLOBAL:
+ only_global = true;
+ // fall through
case TC_INPUT: // Include file
if (lexrc.next()) {
FileName tmp;
@@ -466,9 +472,13 @@ TextClass::ReturnValues TextClass::read(Lexer & lexrc, ReadType rt)
if (!path().empty() && (prefixIs(inc, "./") ||
prefixIs(inc, "../")))
tmp = fileSearch(path(), inc, "layout");
- else
+ else {
+ // InputGlobal only searches in the system and
+ // build directories. This allows to reuse and
+ // modify files in the user directory.
tmp = libFileSearch("layouts", inc,
- "layout");
+ "layout", must_exist, only_global);
+ }
if (tmp.empty()) {
lexrc.printError("Could not find input file: " + inc);
diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp
index 16e6da4..cbbc2dd 100644
--- a/src/support/filetools.cpp
+++ b/src/support/filetools.cpp
@@ -335,12 +335,16 @@ FileName const fileSearch(string const & path, string const & name,
// 2) build_lyxdir (if not empty)
// 3) system_lyxdir
FileName const libFileSearch(string const & dir, string const & name,
- string const & ext, search_mode mode)
+ string const & ext, search_mode mode,
+ bool const only_global)
{
- FileName fullname = fileSearch(addPath(package().user_support().absFileName(), dir),
- name, ext, mode);
- if (!fullname.empty())
- return fullname;
+ FileName fullname;
+ if (!only_global) {
+ fullname = fileSearch(addPath(package().user_support().absFileName(), dir),
+ name, ext, mode);
+ if (!fullname.empty())
+ return fullname;
+ }
if (!package().build_support().empty())
fullname = fileSearch(addPath(package().build_support().absFileName(), dir),
diff --git a/src/support/filetools.h b/src/support/filetools.h
index 6cb3019..dd47ba1 100644
--- a/src/support/filetools.h
+++ b/src/support/filetools.h
@@ -118,12 +118,14 @@ bool isBinaryFile(FileName const & filename);
-# user_lyxdir
-# build_lyxdir (if not empty)
-# system_lyxdir
- The third parameter `ext' is optional.
+ \p onlyglobal determines whether user_lyxdir should be included.
+ ext, search_mode and onlyglobal are optional.
*/
FileName const libFileSearch(std::string const & dir,
std::string const & name,
std::string const & ext = std::string(),
- search_mode mode = must_exist);
+ search_mode mode = must_exist,
+ bool const onlyglobal = false);
/** Same as libFileSearch(), but tries first to find an
internationalized version of the file by prepending $LANG_ to the
More information about the lyx-cvs
mailing list