mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Introduce index-tag-all lfun
This is a convenience function for indexing. It adds a copy of the index inset under cursor after any word in the buffer that is equal (case-insensitively) to the word preceding the index inset. The function can be easily used to generate bad indexes (and I warn about that in the UserGuide), but if used with care, it can also be extremely convenient.
This commit is contained in:
parent
c52808ce1a
commit
3bbce7f24a
@ -142,6 +142,9 @@
|
|||||||
|
|
||||||
* spelling-remove-local removes words for a given language from the document's local
|
* spelling-remove-local removes words for a given language from the document's local
|
||||||
spelling dictionary.
|
spelling dictionary.
|
||||||
|
|
||||||
|
* index-tag-all adds a copy of the index entry under cursor to after all occurrences of the
|
||||||
|
word that precedes the index inset.
|
||||||
|
|
||||||
* inset-insert-copy inserts the inset's content (in ToC pane) at the position of the cursor.
|
* inset-insert-copy inserts the inset's content (in ToC pane) at the position of the cursor.
|
||||||
|
|
||||||
|
@ -9621,12 +9621,14 @@ Verbatim
|
|||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Verbatim
|
\begin_layout Verbatim
|
||||||
|
|
||||||
This is Verbatim.
|
This is Verbatim.
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Verbatim
|
\begin_layout Verbatim
|
||||||
\noindent
|
\noindent
|
||||||
\align block
|
\align block
|
||||||
|
|
||||||
The following 2 lines are empty:
|
The following 2 lines are empty:
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
@ -9639,6 +9641,7 @@ The following 2 lines are empty:
|
|||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Verbatim
|
\begin_layout Verbatim
|
||||||
|
|
||||||
Almost everything is allowed in Verbatim:"%&$§#~'`
|
Almost everything is allowed in Verbatim:"%&$§#~'`
|
||||||
\backslash
|
\backslash
|
||||||
}][{|
|
}][{|
|
||||||
@ -9662,6 +9665,7 @@ Verbatim
|
|||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Verbatim*
|
\begin_layout Verbatim*
|
||||||
|
|
||||||
This is Verbatim*.
|
This is Verbatim*.
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
@ -35407,31 +35411,46 @@ type "icon"
|
|||||||
arg "index-insert"
|
arg "index-insert"
|
||||||
\end_inset
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\change_inserted -712698321 1667668430
|
||||||
|
(but see section
|
||||||
|
\begin_inset space ~
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset CommandInset ref
|
||||||
|
LatexCommand ref
|
||||||
|
reference "subsec:Convenience-Functions-Index"
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
for some advanced methods)
|
||||||
|
\change_unchanged
|
||||||
.
|
.
|
||||||
A
|
A
|
||||||
\change_inserted -712698321 1667110584
|
\change_inserted -712698321 1667665903
|
||||||
collapsible inset
|
collapsible inset
|
||||||
\change_unchanged
|
\change_unchanged
|
||||||
|
|
||||||
\change_deleted -712698321 1667110543
|
\change_deleted -712698321 1667110543
|
||||||
box
|
box
|
||||||
\change_inserted -712698321 1667110812
|
\change_inserted -712698321 1667665903
|
||||||
with green label
|
with green label
|
||||||
\change_unchanged
|
\change_unchanged
|
||||||
is inserted
|
is inserted
|
||||||
\change_inserted -712698321 1667110886
|
\change_inserted -712698321 1667665903
|
||||||
; this
|
; this
|
||||||
\change_unchanged
|
\change_unchanged
|
||||||
|
|
||||||
\change_deleted -712698321 1667110903
|
\change_deleted -712698321 1667110903
|
||||||
contain
|
contain
|
||||||
\change_inserted -712698321 1667110904
|
\change_inserted -712698321 1667665903
|
||||||
holds
|
holds
|
||||||
\change_deleted -712698321 1667110872
|
\change_deleted -712698321 1667110872
|
||||||
ing
|
ing
|
||||||
\change_unchanged
|
\change_unchanged
|
||||||
the text that appears in the index
|
the text that appears in the index
|
||||||
\change_inserted -712698321 1667112993
|
\change_inserted -712698321 1667665903
|
||||||
(if you read this in \SpecialChar LyX
|
(if you read this in \SpecialChar LyX
|
||||||
, see the
|
, see the
|
||||||
\begin_inset Quotes eld
|
\begin_inset Quotes eld
|
||||||
@ -35445,11 +35464,11 @@ Index generation
|
|||||||
\change_unchanged
|
\change_unchanged
|
||||||
.
|
.
|
||||||
The word where the cursor is in
|
The word where the cursor is in
|
||||||
\change_inserted -712698321 1667112984
|
\change_inserted -712698321 1667665903
|
||||||
,
|
,
|
||||||
\change_unchanged
|
\change_unchanged
|
||||||
or the currently highlighted text
|
or the currently highlighted text
|
||||||
\change_inserted -712698321 1667112984
|
\change_inserted -712698321 1667665903
|
||||||
,
|
,
|
||||||
\change_unchanged
|
\change_unchanged
|
||||||
is proposed by \SpecialChar LyX
|
is proposed by \SpecialChar LyX
|
||||||
@ -35458,7 +35477,7 @@ Index generation
|
|||||||
the
|
the
|
||||||
\change_unchanged
|
\change_unchanged
|
||||||
index entry
|
index entry
|
||||||
\change_inserted -712698321 1667112984
|
\change_inserted -712698321 1667665903
|
||||||
(i.
|
(i.
|
||||||
\begin_inset space \thinspace{}
|
\begin_inset space \thinspace{}
|
||||||
\end_inset
|
\end_inset
|
||||||
@ -37422,6 +37441,114 @@ reference "subsec:TeX-Code-Boxes"
|
|||||||
|
|
||||||
\end_layout
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Subsection
|
||||||
|
|
||||||
|
\change_inserted -712698321 1667669398
|
||||||
|
\begin_inset CommandInset label
|
||||||
|
LatexCommand label
|
||||||
|
name "subsec:Convenience-Functions-Index"
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
Convenience Functions for Index Handling
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
|
||||||
|
\change_inserted -712698321 1667669552
|
||||||
|
Indexing a document can be a tedious task, since you often have to insert
|
||||||
|
the same index entry multiple times in order to refer to passages at different
|
||||||
|
pages.
|
||||||
|
This is not only time-consuming, but also error-prone; e.
|
||||||
|
\begin_inset space \thinspace{}
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
g., you have to remember how exactly an inset entry has been inserted to
|
||||||
|
avoid redundant entries.
|
||||||
|
\SpecialChar LyX
|
||||||
|
provides some functions to ease the task.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
|
||||||
|
\change_inserted -712698321 1667669398
|
||||||
|
First, if you want to add an entry which you already used before, you can
|
||||||
|
open the outliner via
|
||||||
|
\family sans
|
||||||
|
View\SpecialChar menuseparator
|
||||||
|
Outline Pane
|
||||||
|
\family default
|
||||||
|
(see section
|
||||||
|
\begin_inset space ~
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
|
||||||
|
\begin_inset CommandInset ref
|
||||||
|
LatexCommand ref
|
||||||
|
reference "subsec:The-Outliner"
|
||||||
|
|
||||||
|
\end_inset
|
||||||
|
|
||||||
|
), select the
|
||||||
|
\family sans
|
||||||
|
Index Entries
|
||||||
|
\family default
|
||||||
|
section (it is convenient to have this open while indexing anyway), scroll
|
||||||
|
to the entry in question (if you check
|
||||||
|
\family sans
|
||||||
|
Sort
|
||||||
|
\family default
|
||||||
|
, it will be more easier), then
|
||||||
|
\emph on
|
||||||
|
right
|
||||||
|
\emph default
|
||||||
|
-click on the entry and select
|
||||||
|
\family sans
|
||||||
|
Insert Copy at Cursor Position
|
||||||
|
\family default
|
||||||
|
from the context menu.
|
||||||
|
This will do just what it says: it will insert a copy of that index inset
|
||||||
|
at the position where the cursor is.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
|
\begin_layout Standard
|
||||||
|
|
||||||
|
\change_inserted -712698321 1667669772
|
||||||
|
Second, \SpecialChar LyX
|
||||||
|
also provides a semi-automated solution to index a word.
|
||||||
|
If you right-click on an index entry inset, you can select from the context
|
||||||
|
menu
|
||||||
|
\family sans
|
||||||
|
Index All Occurrences of this Word
|
||||||
|
\family default
|
||||||
|
.
|
||||||
|
This will search the whole document (only single documents, not master
|
||||||
|
and child documents) and insert a copy of this index inset after each occurrenc
|
||||||
|
e of the word that precedes the inset.
|
||||||
|
Note that casing of the word does not matter, but only full words in the
|
||||||
|
same grammatical form are considered (so if
|
||||||
|
\emph on
|
||||||
|
table
|
||||||
|
\emph default
|
||||||
|
is the word before the index entry,
|
||||||
|
\emph on
|
||||||
|
Table
|
||||||
|
\emph default
|
||||||
|
will be considered as well, but not
|
||||||
|
\emph on
|
||||||
|
tables
|
||||||
|
\emph default
|
||||||
|
).
|
||||||
|
Please take care to not overuse this function and to carefully check the
|
||||||
|
result afterwards.
|
||||||
|
Remember, a good index does not simply list all occurrences of a given
|
||||||
|
word in a specific document (that is a concordance rather), but only relevant
|
||||||
|
occurrences! So as convenient as this function might seem, it is suitable
|
||||||
|
especially for particular cases.
|
||||||
|
With others, you will have more work with removing again falsely inserted
|
||||||
|
entries than you would have with manually inserting them at the right place.
|
||||||
|
\end_layout
|
||||||
|
|
||||||
\begin_layout Subsection
|
\begin_layout Subsection
|
||||||
Index
|
Index
|
||||||
\change_deleted -712698321 1667120869
|
\change_deleted -712698321 1667120869
|
||||||
|
@ -633,6 +633,8 @@ Menuset
|
|||||||
Menu "context-index"
|
Menu "context-index"
|
||||||
IndicesContext
|
IndicesContext
|
||||||
Separator
|
Separator
|
||||||
|
Item "Index All Occurrences of this Word|W" "index-tag-all"
|
||||||
|
Separator
|
||||||
OptItem "Single Page (No Page Range)|P" "inset-modify changeparam range none"
|
OptItem "Single Page (No Page Range)|P" "inset-modify changeparam range none"
|
||||||
OptItem "Start Page Range|t" "inset-modify changeparam range start"
|
OptItem "Start Page Range|t" "inset-modify changeparam range start"
|
||||||
OptItem "End Page Range|E" "inset-modify changeparam range end"
|
OptItem "End Page Range|E" "inset-modify changeparam range end"
|
||||||
|
@ -38,6 +38,7 @@
|
|||||||
#include "MetricsInfo.h"
|
#include "MetricsInfo.h"
|
||||||
#include "Paragraph.h"
|
#include "Paragraph.h"
|
||||||
#include "Session.h"
|
#include "Session.h"
|
||||||
|
#include "texstream.h"
|
||||||
#include "Text.h"
|
#include "Text.h"
|
||||||
#include "TextMetrics.h"
|
#include "TextMetrics.h"
|
||||||
#include "TexRow.h"
|
#include "TexRow.h"
|
||||||
@ -47,6 +48,7 @@
|
|||||||
#include "insets/InsetCitation.h"
|
#include "insets/InsetCitation.h"
|
||||||
#include "insets/InsetCommand.h" // ChangeRefs
|
#include "insets/InsetCommand.h" // ChangeRefs
|
||||||
#include "insets/InsetGraphics.h"
|
#include "insets/InsetGraphics.h"
|
||||||
|
#include "insets/InsetIndex.h"
|
||||||
#include "insets/InsetRef.h"
|
#include "insets/InsetRef.h"
|
||||||
#include "insets/InsetText.h"
|
#include "insets/InsetText.h"
|
||||||
|
|
||||||
@ -1760,6 +1762,78 @@ void BufferView::dispatch(FuncRequest const & cmd, DispatchResult & dr)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case LFUN_INDEX_TAG_ALL: {
|
||||||
|
Inset * ins = cur.nextInset();
|
||||||
|
if (!ins || ins->lyxCode() != INDEX_CODE)
|
||||||
|
// not at index inset
|
||||||
|
break;
|
||||||
|
|
||||||
|
// clone the index inset
|
||||||
|
InsetIndex * cins =
|
||||||
|
new InsetIndex(static_cast<InsetIndex &>(*cur.nextInset()));
|
||||||
|
// In order to avoid duplication, we compare the
|
||||||
|
// LaTeX output if we find another index inset after
|
||||||
|
// the word
|
||||||
|
odocstringstream oilatex;
|
||||||
|
otexstream oits(oilatex);
|
||||||
|
OutputParams rp(&cur.buffer()->params().encoding());
|
||||||
|
ins->latex(oits, rp);
|
||||||
|
cap::copyInsetToTemp(cur, cins);
|
||||||
|
|
||||||
|
// move backwards into preceding word
|
||||||
|
// skip over other index insets
|
||||||
|
cur.backwardPosIgnoreCollapsed();
|
||||||
|
while (true) {
|
||||||
|
if (cur.inset().lyxCode() == INDEX_CODE)
|
||||||
|
cur.pop_back();
|
||||||
|
else if (cur.prevInset() && cur.prevInset()->lyxCode() == INDEX_CODE)
|
||||||
|
cur.backwardPosIgnoreCollapsed();
|
||||||
|
else
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (!cur.inTexted()) {
|
||||||
|
// Nothing to do here.
|
||||||
|
setCursorFromInset(ins);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Get word or selection
|
||||||
|
cur.text()->selectWord(cur, WHOLE_WORD);
|
||||||
|
docstring const searched_string = cur.selectionAsString(false);
|
||||||
|
// Start from the beginning
|
||||||
|
lyx::dispatch(FuncRequest(LFUN_BUFFER_BEGIN));
|
||||||
|
while (findOne(this, searched_string,
|
||||||
|
false,// case sensitive
|
||||||
|
true,// match whole word only
|
||||||
|
true,// forward
|
||||||
|
false,//find deleted
|
||||||
|
false,//check wrap
|
||||||
|
false,// auto-wrap
|
||||||
|
false,// instant
|
||||||
|
false// only selection
|
||||||
|
)) {
|
||||||
|
cur.clearSelection();
|
||||||
|
Inset * ains = cur.nextInset();
|
||||||
|
if (ains && ains->lyxCode() == INDEX_CODE) {
|
||||||
|
// We have an index inset.
|
||||||
|
// Check whether it has the same
|
||||||
|
// LaTeX content and move on if so.
|
||||||
|
odocstringstream filatex;
|
||||||
|
otexstream fits(filatex);
|
||||||
|
ains->latex(fits, rp);
|
||||||
|
if (oilatex.str() == filatex.str())
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Paste the inset and possibly continue
|
||||||
|
cap::pasteFromTemp(cursor(), cursor().buffer()->errorList("Paste"));
|
||||||
|
}
|
||||||
|
// Go back to start position.
|
||||||
|
setCursorFromInset(ins);
|
||||||
|
dr.screenUpdate(cur.result().screenUpdate());
|
||||||
|
if (cur.result().needBufferUpdate())
|
||||||
|
dr.forceBufferUpdate();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
case LFUN_MARK_OFF:
|
case LFUN_MARK_OFF:
|
||||||
cur.clearSelection();
|
cur.clearSelection();
|
||||||
dr.setMessage(from_utf8(N_("Mark off")));
|
dr.setMessage(from_utf8(N_("Mark off")));
|
||||||
|
@ -503,6 +503,8 @@ enum FuncCode
|
|||||||
LFUN_BRANCH_SYNC_ALL, // sanda 20220415
|
LFUN_BRANCH_SYNC_ALL, // sanda 20220415
|
||||||
LFUN_INDEXMACRO_INSERT, // spitz 20220220
|
LFUN_INDEXMACRO_INSERT, // spitz 20220220
|
||||||
LFUN_INSET_INSERT_COPY, // spitz 20221101
|
LFUN_INSET_INSERT_COPY, // spitz 20221101
|
||||||
|
LFUN_INDEX_TAG_ALL, // spitz 20221105
|
||||||
|
// 395
|
||||||
LFUN_LASTACTION // end of the table
|
LFUN_LASTACTION // end of the table
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1975,6 +1975,17 @@ void LyXAction::init()
|
|||||||
*/
|
*/
|
||||||
{ LFUN_INDEX_INSERT, "index-insert", Noop, Edit },
|
{ LFUN_INDEX_INSERT, "index-insert", Noop, Edit },
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* \var lyx::FuncCode lyx::LFUN_INDEX_TAG_ALL
|
||||||
|
* \li Action: Tags all occurrences of the word before the cursor with the
|
||||||
|
* index inset at cursor.
|
||||||
|
* \li Notion: It automatically takes the word on the cursor position.
|
||||||
|
* \li Syntax: index-tag-all
|
||||||
|
* \li Origin: spitz, 5 Nov 2022
|
||||||
|
* \endvar
|
||||||
|
*/
|
||||||
|
{ LFUN_INDEX_TAG_ALL, "index-tag-all", AtPoint, Edit },
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \var lyx::FuncCode lyx::LFUN_INDEX_PRINT
|
* \var lyx::FuncCode lyx::LFUN_INDEX_PRINT
|
||||||
* \li Action: Inserts list of Index entries on a new page.
|
* \li Action: Inserts list of Index entries on a new page.
|
||||||
|
@ -46,6 +46,7 @@ class InsetArgument;
|
|||||||
class InsetCollapsible;
|
class InsetCollapsible;
|
||||||
class InsetCommand;
|
class InsetCommand;
|
||||||
class InsetGraphics;
|
class InsetGraphics;
|
||||||
|
class InsetIndex;
|
||||||
class InsetIterator;
|
class InsetIterator;
|
||||||
class InsetLayout;
|
class InsetLayout;
|
||||||
class InsetList;
|
class InsetList;
|
||||||
@ -146,6 +147,8 @@ public:
|
|||||||
virtual InsetCommand const * asInsetCommand() const { return nullptr; }
|
virtual InsetCommand const * asInsetCommand() const { return nullptr; }
|
||||||
/// is this inset based on the InsetArgument class?
|
/// is this inset based on the InsetArgument class?
|
||||||
virtual InsetArgument const * asInsetArgument() const { return nullptr; }
|
virtual InsetArgument const * asInsetArgument() const { return nullptr; }
|
||||||
|
/// is this inset based on the InsetIndex class?
|
||||||
|
virtual InsetIndex const * asInsetIndex() const { return nullptr; }
|
||||||
/// is this inset based on the InsetGraphics class?
|
/// is this inset based on the InsetGraphics class?
|
||||||
virtual InsetGraphics * asInsetGraphics() { return nullptr; }
|
virtual InsetGraphics * asInsetGraphics() { return nullptr; }
|
||||||
/// is this inset based on the InsetGraphics class?
|
/// is this inset based on the InsetGraphics class?
|
||||||
|
@ -692,6 +692,9 @@ bool InsetIndex::getStatus(Cursor & cur, FuncRequest const & cmd,
|
|||||||
case LFUN_INDEXMACRO_INSERT:
|
case LFUN_INDEXMACRO_INSERT:
|
||||||
return macrosPossible(cmd.getArg(0));
|
return macrosPossible(cmd.getArg(0));
|
||||||
|
|
||||||
|
case LFUN_INDEX_TAG_ALL:
|
||||||
|
return true;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return InsetCollapsible::getStatus(cur, cmd, flag);
|
return InsetCollapsible::getStatus(cur, cmd, flag);
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,8 @@ public:
|
|||||||
const InsetIndexParams& params() const { return params_; }
|
const InsetIndexParams& params() const { return params_; }
|
||||||
///
|
///
|
||||||
int rowFlags() const override { return CanBreakBefore | CanBreakAfter; }
|
int rowFlags() const override { return CanBreakBefore | CanBreakAfter; }
|
||||||
|
///
|
||||||
|
InsetIndex const * asInsetIndex() const override { return this; }
|
||||||
private:
|
private:
|
||||||
///
|
///
|
||||||
bool hasSettings() const override;
|
bool hasSettings() const override;
|
||||||
|
Loading…
Reference in New Issue
Block a user