commit 11e679f73ecca718c61307973c3d67739354e1c7
Author: brokenclock <[email protected]>
Date: Tue Oct 14 21:55:04 2014 +0200
Add LFUN_SERVER_GET_STATISTICS command
This function can be used with the LyX server to obtain the word, character
or character+space count in the current document or selection.
diff --git a/lib/doc/LFUNs.lyx b/lib/doc/LFUNs.lyx
index b0ac9f4..0d9bb93 100644
--- a/lib/doc/LFUNs.lyx
+++ b/lib/doc/LFUNs.lyx
@@ -98,7 +98,7 @@ The LyX Team
\end_layout
\begin_layout Date
-2014-02-13
+2014-10-23
\end_layout
\begin_layout Section*
@@ -3076,6 +3076,22 @@ Origin lasgouttes, 14 Jan 2009
\end_layout
\begin_layout Subsection*
+separator-insert
+\end_layout
+\begin_layout Description
+Action Inserts an environment separator or paragraph break.
+\end_layout
+\begin_layout Description
+Syntax separator-insert [<ARG>]
+\end_layout
+\begin_layout Description
+Params <ARG>: <plain|parbreak> default: plain
+\end_layout
+\begin_layout Description
+Origin ef, 2 May 2014
+\end_layout
+
+\begin_layout Subsection*
set-graphics-group
\end_layout
\begin_layout Description
@@ -5321,6 +5337,37 @@ Syntax server-get-layout
\end_layout
\begin_layout Subsection*
+server-get-statistics
+\end_layout
+\begin_layout Description
+Action Returns the statistics (number of words and characters) in the document
or in the given selection.
+\end_layout
+\begin_layout Description
+Notion Note that this function gives the number of words/chars written, not
the number of characters which will be typeset.
+\end_layout
+\begin_layout Description
+Syntax server-get-statistics [<TYPE>]
+\end_layout
+\begin_layout Description
+Params <TYPE>: <words|chars|chars-space> The requested count; if not
specified, the three values are returned, separated by a space.
+\begin_inset Newline newline
+\end_inset
+
+words: count words.
+\begin_inset Newline newline
+\end_inset
+
+chars: count characters.
+\begin_inset Newline newline
+\end_inset
+
+chars-space: count characters and spaces.
+\end_layout
+\begin_layout Description
+Origin brokenclock, Oct 10 2014
+\end_layout
+
+\begin_layout Subsection*
server-get-xy
\end_layout
\begin_layout Description
@@ -5411,7 +5458,7 @@ Origin SLior, 11 Jun 2000
statistics
\end_layout
\begin_layout Description
-Action Count the statistics (number of words and characters) in the document
or in the given selection.
+Action Count the statistics (number of words and characters) in the document
or in the given selection and display it in a dialog box.
\end_layout
\begin_layout Description
Notion Note that this function gives the number of words/chars written, not
the number of characters which will be typeset.
diff --git a/src/FuncCode.h b/src/FuncCode.h
index 2ae820a..3bd0cd0 100644
--- a/src/FuncCode.h
+++ b/src/FuncCode.h
@@ -458,6 +458,7 @@ enum FuncCode
// 355
LFUN_SPELLING_CONTINUOUSLY, // vfr, 20130324
LFUN_SEPARATOR_INSERT, // ef 20140502
+ LFUN_SERVER_GET_STATISTICS, // brokenclock 20141010
LFUN_LASTACTION // end of the table
};
diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 175f68e..0efbb3c 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -3517,7 +3517,8 @@ void LyXAction::init()
/*!
* \var lyx::FuncCode lyx::LFUN_STATISTICS
* \li Action: Count the statistics (number of words and characters)
- in the document or in the given selection.
+ in the document or in the given selection and display it
+ in a dialog box.
* \li Notion: Note that this function gives the number of words/chars written,
not the number of characters which will be typeset.
* \li Syntax: statistics
@@ -3526,6 +3527,23 @@ void LyXAction::init()
*/
{ LFUN_STATISTICS, "statistics", ReadOnly, System },
/*!
+ * \var lyx::FuncCode lyx::LFUN_SERVER_GET_STATISTICS
+ * \li Action: Returns the statistics (number of words and characters)
+ in the document or in the given selection.
+ * \li Notion: Note that this function gives the number of words/chars written,
+ not the number of characters which will be typeset.
+ * \li Syntax: server-get-statistics [<TYPE>]
+ * \li Params: <TYPE>: <words|chars|chars-space> The requested count; if not
+ specified, the three values are returned, separated
+ by a space.\n
+ words: count words.\n
+ chars: count characters.\n
+ chars-space: count characters and spaces.
+ * \li Origin: brokenclock, Oct 10 2014
+ * \endvar
+ */
+ { LFUN_SERVER_GET_STATISTICS, "server-get-statistics",
ReadOnly, System },
+/*!
* \var lyx::FuncCode lyx::LFUN_COMPLETION_INLINE
* \li Action: Show the inline completion at the cursor position.
* \li Syntax: completion-inline
diff --git a/src/Text3.cpp b/src/Text3.cpp
index 79711f4..6bf3bc6 100644
--- a/src/Text3.cpp
+++ b/src/Text3.cpp
@@ -2391,6 +2391,33 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
needsUpdate = true;
break;
+ case LFUN_SERVER_GET_STATISTICS:
+ {
+ DocIterator from, to;
+ if (cur.selection()) {
+ from = cur.selectionBegin();
+ to = cur.selectionEnd();
+ } else {
+ from = doc_iterator_begin(cur.buffer());
+ to = doc_iterator_end(cur.buffer());
+ }
+
+ cur.buffer()->updateStatistics(from, to);
+ string const arg0 = cmd.getArg(0);
+ if (arg0 == "words") {
+
cur.message(convert<docstring>(cur.buffer()->wordCount()));
+ } else if (arg0 == "chars") {
+
cur.message(convert<docstring>(cur.buffer()->charCount(false)));
+ } else if (arg0 == "chars-space") {
+
cur.message(convert<docstring>(cur.buffer()->charCount(true)));
+ } else {
+
cur.message(convert<docstring>(cur.buffer()->wordCount()) + " "
+ +
convert<docstring>(cur.buffer()->charCount(false)) + " "
+ +
convert<docstring>(cur.buffer()->charCount(true)));
+ }
+ }
+ break;
+
default:
LYXERR(Debug::ACTION, "Command " << cmd << " not DISPATCHED by
Text");
cur.undispatched();
@@ -3109,6 +3136,7 @@ bool Text::getStatus(Cursor & cur, FuncRequest const &
cmd,
case LFUN_UNICODE_INSERT:
case LFUN_THESAURUS_ENTRY:
case LFUN_ESCAPE:
+ case LFUN_SERVER_GET_STATISTICS:
// these are handled in our dispatch()
enable = true;
break;