From b83b428c5cc48043cb625844b87e94acbc194ba1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= <flashcode@flashtux.org>
Date: Tue, 7 Nov 2023 07:22:01 +0100
Subject: core: add incremental search in commands history (issue #2040)

Changes:

- move key ctrl+r to ctrl+s
- add key ctrl+r to search in commands history
- add option `search_history` in command `/input`
- add key context "histsearch"
- add option weechat.look.buffer_search_history
- add buffer variables "text_search_direction", "text_search_history" and "text_search_ptr_history"
---
 doc/en/weechat_user.en.adoc | 58 +++++++++++++++++++++++++++++++++++++++------
 1 file changed, 51 insertions(+), 7 deletions(-)

(limited to 'doc/en/weechat_user.en.adoc')

diff --git a/doc/en/weechat_user.en.adoc b/doc/en/weechat_user.en.adoc
index 41dc69b73..a6f4a506c 100644
--- a/doc/en/weechat_user.en.adoc
+++ b/doc/en/weechat_user.en.adoc
@@ -914,11 +914,30 @@ Bar _input_ has following default items:
 | Item         | Example                                      | Description
 | input_prompt | `[@Flashy(i)]`                               | Input prompt, for irc: nick and modes (mode "+i" means invisible on libera).
 | away         | `(away)`                                     | Away indicator.
-| input_search | `[Search (~ str,msg)]`                       | Search indicator ("`~`": case insensitive, "`==`": case sensitive, "`str`": search string, "`regex`": search regular expression, "`msg`": search in messages, "`pre`": search in prefixes, "`pre\|msg`": search in prefixes and messages).
+| input_search | `[Search lines (~ str,msg)]`                 | Search indicator (see below)
 | input_paste  | `[Paste 7 lines ? [ctrl-y] Yes [ctrl-n] No]` | Question to user for pasting lines.
 | input_text   | `hi peter!`                                  | Input text.
 |===
 
+There are two search modes:
+
+* search in lines, for example `[Search lines (~ str,msg)]`, with the following info:
+** `~`: case insensitive
+** `==`: case sensitive
+** `str`: search string
+** `regex`: search regular expression
+** `msg`: search in messages
+** `pre`: search in prefixes
+** `pre\|msg`: search in prefixes and messages.
+* search in commands history, for example `[Search command (~ str,local)]`,
+  with the following info:
+** `~`: case insensitive
+** `==`: case sensitive
+** `str`: search string
+** `regex`: search regular expression
+** `local`: search in buffer local history
+** `global`: search in global history.
+
 Bar _nicklist_ has following default items:
 
 [width="100%",cols="^3,^3,9",options="header"]
@@ -1613,7 +1632,8 @@ They can be changed and new ones can be added with the <<command_weechat_key,/ke
 [width="100%",cols="^.^3,.^8,.^5",options="header"]
 |===
 | Key                            | Description | Command
-| kbd:[Ctrl+r]                   | Search for text in buffer history (see <<key_bindings_search_context,keys for search context>>). | `+/input search_text_here+`
+| kbd:[Ctrl+r]                   | Search for text in commands history (see <<key_bindings_histsearch_context,keys for context "histsearch">>). | `+/input search_history+`
+| kbd:[Ctrl+s]                   | Search for text in buffer lines (see <<key_bindings_search_context,keys for context "search">>). | `+/input search_text_here+`
 | kbd:[Ctrl+s], kbd:[Ctrl+u]     | Set unread marker on all buffers. | `+/allbuf /buffer set unread+`
 | kbd:[Ctrl+x]                   | Switch current buffer if buffers are merged with same number, for example switch to another IRC server buffer. | `+/buffer switch+`
 | kbd:[Alt+x]                    | Zoom on merged buffer (kbd:[Alt+x] again: display all merged buffers). | `+/buffer zoom+`
@@ -1716,23 +1736,47 @@ They can be changed and new ones can be added with the <<command_weechat_key,/ke
 [[key_bindings_search_context]]
 === Search context
 
-These keys are used in context "search" (when kbd:[Ctrl+r] is pressed to search
-text in buffer).
+These keys are used in context "search" (when kbd:[Ctrl+s] is pressed to search
+text in buffer lines).
 
 [width="100%",cols="^.^3,.^8,.^5",options="header"]
 |===
 | Key            | Description | Command
-| kbd:[Ctrl+r]   | Switch search type: string (default), regular expression. | `+/input search_switch_regex+`
+| kbd:[Ctrl+x]   | Switch search type: string (default), regular expression. | `+/input search_switch_regex+`
 | kbd:[Alt+c]    | Switch exact case for search. | `+/input search_switch_case+`
 | kbd:[Tab]      | Switch search in: messages (default), prefixes, prefixes + messages. | `+/input search_switch_where+`
-| kbd:[↑]        | Search previous line. | `+/input search_previous+`
-| kbd:[↓]        | Search next line. | `+/input search_next+`
+| kbd:[Ctrl+r] +
+  kbd:[↑]        | Search previous line. | `+/input search_previous+`
+| kbd:[Ctrl+s] +
+  kbd:[↓]        | Search next line. | `+/input search_next+`
 | kbd:[Enter] +
   kbd:[Ctrl+j] +
   kbd:[Ctrl+m]   | Stop search at current position. | `+/input search_stop_here+`
 | kbd:[Ctrl+q]   | Stop search and reset scroll to pre-text search state. | `+/input search_stop+`
 |===
 
+[[key_bindings_histsearch_context]]
+=== History search context
+
+These keys are used in context "histsearch" (when kbd:[Ctrl+r] is pressed to
+search text in commands history).
+
+[width="100%",cols="^.^3,.^8,.^5",options="header"]
+|===
+| Key            | Description | Command
+| kbd:[Ctrl+x]   | Switch search type: string (default), regular expression. | `+/input search_switch_regex+`
+| kbd:[Alt+c]    | Switch exact case for search. | `+/input search_switch_case+`
+| kbd:[Tab]      | Switch search in: buffer local history (default), global history. | `+/input search_switch_where+`
+| kbd:[Ctrl+r] +
+  kbd:[↑]        | Search in previous (older) history entries. | `+/input search_previous+`
+| kbd:[Ctrl+s] +
+  kbd:[↓]        | Search in next (newer) history entries. | `+/input search_next+`
+| kbd:[Enter] +
+  kbd:[Ctrl+j] +
+  kbd:[Ctrl+m]   | Stop search and use matching input. | `+/input search_stop_here+`
+| kbd:[Ctrl+q]   | Stop search and restore input to its initial value. | `+/input search_stop+`
+|===
+
 [[key_bindings_cursor_context]]
 === Cursor context
 
-- 
cgit v1.2.3

