Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Proposed _history completer



Here is a first attempt at proposing a completer that completes words in
history.  This is the start of a replacement for the example in the compctl
manual that searches history if filenames don't match in the default
completion (compctl -D -f + -H 0 '').

This is a pruned down version of the _history_complete_word widget so
that it would behave as a completer function and not as a stand alone
widget.  Some of the behavior provided by the _history_complete_word
widget is lost, but the ability to include it as a completer should be
useful.  It might be useful to use with the predict widgets.

One benefit is that it is now possible to use the default styles that all the
completers use.  For example, matcher-list can be used with _history.

Future changes to this widget might include the ability to limit how much
of history is used for completion, like the old compctl -H flag. 
I think there is a lot of potential to be found in limiting history words to
similar contexts;  only history lines where the current command is used,
or previous values for the current option.   To do this might require
some changes to the zsh/parameter module to make this efficient.

It might be useful to use history as a way to filter completions from other
completers.  To first use completions that are already found in history.
Or the opposite, to eliminate choices that are found in the history.

-FR.


__________________________________________________
Do You Yahoo!?
Send online invitations with Yahoo! Invites.
http://invites.yahoo.com
--- zsh/Doc/Zsh/,compsys.yo	Thu Apr 20 01:04:57 2000
+++ zsh/Doc/Zsh/compsys.yo	Sun Apr 23 19:10:02 2000
@@ -2132,10 +2132,18 @@
 at all.
 
 In a different mode selected by the tt(completions) style, all
 em(completions) generated for the string on the line are inserted.
 )
+findex(_history)
+item(tt(_history))(
+Complete words from the shell's command  history.  This completer 
+uses the tt(remove-all-dups), and tt(sort) styles used by the
+tt(_history_complete_word) bindable command, see
+ifzman(the section `Completion System Configuration' above)\
+ifnzman(noderef(Completion System Configuration)).
+)
 findex(_list)
 item(tt(_list))(
 This completer allows one to delay the insertion of matches until
 completion is attempted a second time without the word on the line
 being changed. On the first attempt, only the list of matches will be
--- zsh/Completion/Core/,.distfiles	Wed Apr 19 17:48:28 2000
+++ zsh/Completion/Core/.distfiles	Sun Apr 23 19:24:54 2000
@@ -1,11 +1,11 @@
 DISTFILES_SRC='
     .distfiles
     _all_labels _alternative _approximate
     _call _compalso _complete _correct _description _expand
-    _file_descriptors _files _funcall _ignored _list _main_complete _match
-    _menu _multi_parts _message _next_label _normal _oldlist _options
+    _file_descriptors _files _funcall _history _ignored _list _main_complete
+    _match _menu _multi_parts _message _next_label _normal _oldlist _options
     _parameters _path_files _prefix _requested _sep_parts
     _set_options _setup _sort_tags _tags
     _unset_options _wanted
     compdump compinit compinstall
 '
--- /dev/null	Sun Apr 23 19:21:14 2000
+++ zsh/Completion/Core/_history	Sun Apr 23 19:26:09 2000
@@ -0,0 +1,31 @@
+#autoload
+
+#
+# Complete words from the history
+#
+# Code taken from _history_complete_words.
+#
+# Available styles:
+#
+#   :history-words:sort -- sort matches lexically (default is to sort by age)
+#   :history-words:remove-all-dups --
+#                          remove /all/ duplicate matches rather than just
+#                          consecutives
+
+  local opt expl 
+
+  if zstyle -t ":completion:${curcontext}:" remove-all-dups; then
+    opt=-
+  else
+    opt=-1
+  fi
+  if zstyle -t ":completion:${curcontext}:" sort; then
+    opt="${opt}J"
+  else
+    opt="${opt}V"
+  fi
+
+  # We skip the first element of historywords so the current word doesn't
+  # interfere with the completion
+  _wanted "$opt" history-words expl 'history word' \
+      compadd -Q - "${(@)historywords[2,-1]}"


Messages sorted by: Reverse Date, Date, Thread, Author