]> git.lyx.org Git - features.git/commitdiff
Add LFUN_SERVER_GET_STATISTICS command
authorbrokenclock <stephane.mourey@impossible-exil.info>
Tue, 14 Oct 2014 19:55:04 +0000 (21:55 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 23 Oct 2014 14:06:42 +0000 (16:06 +0200)
This function can be used with the LyX server to obtain the word, character or character+space count in the current document or selection.

lib/doc/LFUNs.lyx
src/FuncCode.h
src/LyXAction.cpp
src/Text3.cpp

index b0ac9f469f38f64ebe277e9eeaac2283add09253..0d9bb938ddab95e58e015c884fe3573c96ef1758 100644 (file)
@@ -98,7 +98,7 @@ The LyX Team
 \end_layout
 
 \begin_layout Date
 \end_layout
 
 \begin_layout Date
-2014-02-13
+2014-10-23
 \end_layout
 
 \begin_layout Section*
 \end_layout
 
 \begin_layout Section*
@@ -3075,6 +3075,22 @@ Syntax selection-paste
 Origin lasgouttes, 14 Jan 2009
 \end_layout
 
 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 Subsection*
 set-graphics-group
 \end_layout
@@ -5320,6 +5336,37 @@ Action Returns the current layout (that is environment) name on the cursor posit
 Syntax server-get-layout
 \end_layout
 
 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 Subsection*
 server-get-xy
 \end_layout
@@ -5411,7 +5458,7 @@ Origin SLior, 11 Jun 2000
 statistics
 \end_layout
 \begin_layout Description
 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.
 \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.
index 2ae820a17147b18c11e267c382b57078ab6e1d44..3bd0cd0eef99ac7ee04c15c489a3756f3cc957b2 100644 (file)
@@ -458,6 +458,7 @@ enum FuncCode
        // 355
        LFUN_SPELLING_CONTINUOUSLY,     // vfr, 20130324
        LFUN_SEPARATOR_INSERT,          // ef 20140502
        // 355
        LFUN_SPELLING_CONTINUOUSLY,     // vfr, 20130324
        LFUN_SEPARATOR_INSERT,          // ef 20140502
+       LFUN_SERVER_GET_STATISTICS,     // brokenclock 20141010
        LFUN_LASTACTION                 // end of the table
 };
 
        LFUN_LASTACTION                 // end of the table
 };
 
index 175f68ee80b02aa5546164238a188e80e5dc7252..0efbb3c8e1eb9c5380aaa793dd9eb983cf51c65f 100644 (file)
@@ -3517,7 +3517,8 @@ void LyXAction::init()
 /*!
  * \var lyx::FuncCode lyx::LFUN_STATISTICS
  * \li Action: Count the statistics (number of words and characters)
 /*!
  * \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
  * \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
@@ -3525,6 +3526,23 @@ void LyXAction::init()
  * \endvar
  */
                { LFUN_STATISTICS, "statistics", ReadOnly, System },
  * \endvar
  */
                { 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.
 /*!
  * \var lyx::FuncCode lyx::LFUN_COMPLETION_INLINE
  * \li Action: Show the inline completion at the cursor position.
index 79711f43732769b8555e611328e9b74d0588ef3a..6bf3bc601f0f73ba972f114fe46b21a8ad30e7a6 100644 (file)
@@ -2391,6 +2391,33 @@ void Text::dispatch(Cursor & cur, FuncRequest & cmd)
                needsUpdate = true;
                break;
 
                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();
        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_UNICODE_INSERT:
        case LFUN_THESAURUS_ENTRY:
        case LFUN_ESCAPE:
+       case LFUN_SERVER_GET_STATISTICS:
                // these are handled in our dispatch()
                enable = true;
                break;
                // these are handled in our dispatch()
                enable = true;
                break;