about summary refs log tree commit diff
path: root/Completion
diff options
context:
space:
mode:
authorSven Wischnowsky <wischnow@users.sourceforge.net>2001-03-27 09:14:50 +0000
committerSven Wischnowsky <wischnow@users.sourceforge.net>2001-03-27 09:14:50 +0000
commit6d72dca54fbbf3e86807502288ace649f5fbe05c (patch)
tree92fac1ca5f8121f253fbe77662c1a3fd2d4bef08 /Completion
parentb0176cb54f2a7fdde6e4226e0691c88c1674af34 (diff)
downloadzsh-6d72dca54fbbf3e86807502288ace649f5fbe05c.tar.gz
zsh-6d72dca54fbbf3e86807502288ace649f5fbe05c.tar.xz
zsh-6d72dca54fbbf3e86807502288ace649f5fbe05c.zip
try to make _h_c_w smarter at the beginning and end of the list; avoid list-beeping if the old completion list is re-used (3752)
Diffstat (limited to 'Completion')
-rw-r--r--Completion/Commands/_history_complete_word53
1 files changed, 34 insertions, 19 deletions
diff --git a/Completion/Commands/_history_complete_word b/Completion/Commands/_history_complete_word
index 48adb34bc..c4c762393 100644
--- a/Completion/Commands/_history_complete_word
+++ b/Completion/Commands/_history_complete_word
@@ -50,36 +50,51 @@ _history_complete_word () {
     slice=$max
   fi
 
-  if [[ -n "$compstate[old_list]" &&
-        ( -n "$stop" || "$compstate[insert]" = menu ) ]] ; then
-    # array of matches is newest -> oldest (reverse of history order)
-    if [[ "$direction" == 'older' ]]; then
-      if [[ compstate[old_insert] -eq $_hist_menu_length ||
-            "$_hist_stop" == 'oldest' ]]; then
-        _hist_stop='oldest'
-        [[ "$stop" = verbose ]] &&
-          _message 'beginning of history reached'
-      elif [[ "$_hist_stop" == 'newest' ]]; then
-        zle -Rc
+  if [[ ( -n "$compstate[old_list]" ||
+          ( $LASTWIDGET = _history-complete-* && -n $_hist_stop ) ) &&
+        ( -n "$stop" || "$compstate[insert]" = menu ) ]]; then
+    if [[ "$direction" == older ]]; then
+      if [[ $_hist_stop = new ]]; then
+        PREFIX=$_hist_old_prefix
         _history_complete_word_gen_matches
-      else
+        compstate[insert]=2
+        _hist_stop=
+      elif [[ $_hist_stop = old ]]; then
+        PREFIX=$_hist_old_prefix
+        _history_complete_word_gen_matches
+        compstate[insert]=1
+        _hist_stop=
+      elif [[ compstate[old_insert] -lt _hist_menu_length ]]; then
         compstate[old_list]=keep
         (( compstate[insert] = compstate[old_insert] + 1 ))
+      else
+        _hist_stop=old
+        _message 'beginning of history reached'
+        return 1
       fi
     elif [[ "$direction" == 'newer' ]]; then
-      if [[ compstate[old_insert] -eq 1 || "$_hist_stop" == 'newest' ]]; then
-        _hist_stop='newest'
-        [[ "$stop" = verbose ]] && _message 'end of history reached'
-      elif [[ "$_hist_stop" == 'oldest' ]]; then
-        zle -Rc
+      if [[ $_hist_stop = old ]]; then
+        PREFIX=$_hist_old_prefix
         _history_complete_word_gen_matches
-      else
+        compstate[insert]=$(( $compstate[nmatches] - 1 ))
+        _hist_stop=
+      elif [[ $_hist_stop = new ]]; then
+        PREFIX=$_hist_old_prefix
+        _history_complete_word_gen_matches
+        compstate[insert]=$compstate[nmatches]
+        _hist_stop=
+      elif [[ compstate[old_insert] -gt 1 ]]; then
         compstate[old_list]=keep
         (( compstate[insert] = compstate[old_insert] - 1 ))
+      else
+        _hist_stop=new
+        _message 'end of history reached'
+        return 1
       fi
     fi
+    return 0
   else
-    _hist_stop=''
+    _hist_stop=
     _hist_old_prefix="$PREFIX"
     _history_complete_word_gen_matches
   fi