**Not quite ready. Needs documentation and good run through. Will update at later time.**
The attached patch is a consolidation of bugs/patches
[ 1525665 ] help has problems with
[ 1531560 ] recursive history warning instead of error
[ 1534367 ] too much expansion in FindHelp
This patch also solves another just-found bug. In a couple places is this construct:
if (!END_OF_COMMAND && equals(c_token,"?")) {
static char *search_str = NULL; /* string from command line to search for */
/\* find and show the entries \*/ c\_token++; m\_capture\(&search\_str, c\_token, c\_token\); /\* reallocates memory \*/
But note that if there is nothing following the ? the code continues and m_capture is done on an invalid c_token. Often this passes fine, but depending on the memory attempting to access there could be a segfault.
Egad! This is worse than I thought. The following is also an infinite loop:
plot x; history !plot
I've changed things to suit, but oh what a headache shuffling the history around makes when it comes to searching and retrieving. (And I'm not sure if shuffling the history is that beneficial... hi !# is hard to keep track of if the numbers keep changing. Anyway... shuffling it is. It would be easy to turn this off.)
I believe I have a solid concept now for recursive history. Rather than trying to do a "what if this, and then that, and then that..." sort of thing (which undoubtedly fails) there is a recursion history (based on dynarray) and if ever gnuplot finds itself running a history line it already has run, it complaines. Here is some sample output.
Terminal type set to 'x11'
gnuplot> plot x
gnuplot> history
1 plot x
2 history
gnuplot> hist !hist
Executing:
history
1 plot x
2 history
3 hist !hist
gnuplot> hist !hist
Executing:
hist !hist
^
recursive history
gnuplot> hist !1
Executing:
plot x
gnuplot> plot x*x; hist !plot
Executing:
plot x
gnuplot> plot x*x; hist !plot
Executing:
plot x*x; hist !plot
gnuplot> plot x*x; hist !plot
^
recursive history
gnuplot>
patch for many files
Logged In: YES
user_id=704782
Originator: YES
OK, ready to go. Here are some commands to illustrate:
help user-defined var
help gnuplot-defined var
help se sty li
help set term post
help set ter post
history
hist !hist
hist !hist
hist !2
File Added: helphist_djs_4jun2007.patch
patch for command.c, help.c and history.c
flexibility for all and use of readline bindings
Logged In: YES
user_id=704782
Originator: YES
New patch attached. Very robust with couple added features. Type
help history
help set history
"set history" will set a few options that can be over-ridden locally. E.g.,
set history condensed
will generally display the history stack in condensed format; however,
history full
will override that.
Here is something really neat, and nothing kludge-like about it from the perspective of readline. When "set history condensed" is active, the up/down arrows will now also scan through only unique history entries. Here is the elegant way to do it. Simply write a routine like
static int gp_get_condensed_next_history(int count, int key) {
/* Look for the previous unique command */
HIST_ENTRY **the_list = history_list();
int i_hist = where_history() + 1;
for (; i_hist < history_length; i_hist++) {
if (the_list[i_hist]->data == NULL)
break;
}
/* Advance to found unique entry */
if (i_hist < history_length)
return rl_get_next_history(i_hist - where_history(), key);
else
return 0;
}
and then bind that function to the downarrow key sequence. When not in condensed mode, bind the keys back to the original rl_get_next_history().
There is some flexibility with what we could do (e.g., bind the condensed up/down to other keys) but we'll see what feedback we get.
I've also made the non GNU-readline version behave similarly.
File Added: helphist_djs_5jun2007.patch
three history display modes
Logged In: YES
user_id=704782
Originator: YES
OK, here's an update that I think is ready. Works for both
./configure --with-readline=builtin
and
./configure --with-readline=gnu
and
./configure --disable-history-file
Nothing is automatically discarded from stack, but there are three display modes "set hist full", "set hist ignoredups" and "set hist condensed".
Dan
File Added: helphist_djs_9jun2007.patch
Logged In: YES
user_id=31505
Originator: NO
The patch is fine with me.
However, I propose some changes for the docs:
1.
Change
set history {<int>} {numbered|quiet} {condensed|ignoredups|full}
to
set history {<int>}
{condensed|ignoredups|full}
{numbered|quiet}
2. The first 2 opts are related to storing,
while the "numbered" option changes the display style.
Thus move this as the last paragraph:
For displaying the history, the option `quiet` will suppress numbers alongside the commands, which
is useful for mouse copy and paste.
3. Put at the end of ?set history and ?history, respectively:
See also `history`.
See also `set history`.
4. "Note: the command `set history` is only available when gnuplot has been
configured with the GNU readline or its own history feature."
I think you cannot compile gnuplot with any other readline ... thus I guess this note is not necessary.
Changes to documentation only
Logged In: YES
user_id=704782
Originator: YES
Changes made as suggested with addition of line:
Command line history may be controlled with several options described below.
Several of these options may be overridden by similar qualifiers in the
history command.
Syntax:
set history {<int>}
[etc]
File Added: helphist_djs_10jun2007.patch
"set his 0" means do not overwrite history file
Logged In: YES
user_id=704782
Originator: YES
The change here (11jun2007) is that "set his 0" means to not overwrite the history file on exit. I've altered the following two items in documentation:
The value <int> indicates the value of history size when leaving gnuplot. It
is used for truncating the history to at most that many lines. The default
is 666. A value of 0 means the history file is not overwritten.
`unset history` will set history operation to: no history truncation at exit
and thus allow indefinite number of lines, `condensed`, and `numbered`.
In the second paragraph above I removed the phrase "default", because default is 666 according to previous behavior, not unlimited.
There is one other change. I disabled the code of builtin version for history_add() that truncates the history list internally. This makes builtin version consistent with behavior for the GNU readline version.
File Added: helphist_djs_11jun2007.patch
Logged In: YES
user_id=1333817
Originator: NO
> 4. "Note: the command `set history` is only available when gnuplot
> has been configured with the GNU readline or its own history
> feature."
> I think you cannot compile gnuplot with any other readline ...
> thus I guess this note is not necessary.
You can compile with --without-readline, and then this note makes full sense.
synchronize with CVS
Logged In: YES
user_id=704782
Originator: YES
synch with CVS, no changes
File Added: helphist_djs_21jun2007.patch
Logged In: YES
user_id=31505
Originator: NO
The patch seems to be finalized. I propose to move it to cvs.
Logged In: YES
user_id=704782
Originator: YES
An update to synchronize with CVS. Also, I commented out a test for "help" search that would declare a mismatch if there were more words in the key than search "abbreviations" entered by the user.
File Added: helphist_djs_12jul2008.patch
update for CVS and comment out mismatch for too many abbreviations
Logged In: YES
user_id=235620
Originator: NO
Thank you for looking at this again. The help and history commands do seem to have serious problems.
My preferences:
Disable the history shuffling. I hate it when a command I used previously is no longer available because I've already edited+reused it once. Once a command is entered in the history list, it should stay there at that position forever.
Forbid recursive history commands: When considering lines in the history file, just skip any line that contains "hist" as either the first token or the first after a ";".
Logged In: YES
user_id=704782
Originator: YES
> Disable the history shuffling.
There are now modes for setting this. (See "help set history" and "help history" after the patch.) I too did not like the shuffling, so internally gnuplot always saves the complete list in the order in which commands were typed. Changing the mode does nothing to effect the internal list.
The modes are simply for the manner in which the list is displayed. One of the modes ("condensed") displays the list in a fashion that makes it appear to be shuffling because it only displays the most recent instance of similar commands. Petr wanted to retain this mode. But nowhere in the help do I say the word "shuffling" because that would be most confusing.
Whether "full", "ignoredups" or "condensed" is the default is a matter of discussion for the list. I have no preference.
There is also the addition of numbers for ease of recalling and executing a command in history. The oldest command is 1, etc. so that the number associated with the command does not change.
As for recursive history, I recall having that pretty solid. Whenever a previously called command comes around a second time, there is an error. I always seemed to run into trouble when trying to selectively ignore a "hist" at the start of a line. It seems easier to recognize the search is in an infinite loop when the search is occurring (which covers all bases) rather than trying to predict that an infinite loop is going to occur (and possibly forgetting some strange combination).
By "ignore" you mean break out of whatever process is occurring? Or simply skip any "hist" command and execute the rest. E.g.,
plot x; hist
hist; plot x
would both simply "plot x"? Would that require some special conditional code as part of the parser? Plus, I don't know if we want people thinking too much "if I recall a command here, then the hist will be ignored, etc."
Well, give the recursive-prevent a try. I don't think it is possible to get any kind of infinite loop anymore.
File Added: helphist_djs_24jul2008.patch
update for CVS
Help search simplification
Logged In: YES
user_id=704782
Originator: YES
Made some help-search mods to better match current behavior. In some ways it's a simplification and removes the variable for "exact word matches". Substrings are assumed to be higher level in the hierarchy and win, e.g., "commands" wins over "commands raise" and the help doc for "commands" is displayed.
File Added: helphist_djs_30jul2008.patch
Logged In: YES
user_id=704782
Originator: YES
Eh, still not quite right. In this new patched I introduced a function strsubstr() that will give better nuance comparing pairs of words at a time to determine the hierarchy relationship of two strings str1 and str2.
File Added: helphist_djs_31jul2008.patch
New routine strsubstr(str1,str2) for help search