From 02748416722ffe4b99ced0570ff8b2cf8cbdbd9c Mon Sep 17 00:00:00 2001 From: cage Date: Sat, 3 Oct 2020 21:08:55 +0200 Subject: [PATCH] - added searching in command's help. --- etc/init.lisp | 4 ++++ src/keybindings.lisp | 29 ++++++++++++++++++++--------- src/line-oriented-window.lisp | 3 ++- src/package.lisp | 2 ++ src/program-events.lisp | 10 ++++++++++ src/ui-goodies.lisp | 10 ++++++++++ 6 files changed, 48 insertions(+), 10 deletions(-) diff --git a/etc/init.lisp b/etc/init.lisp index ddebcf4..5f38933 100644 --- a/etc/init.lisp +++ b/etc/init.lisp @@ -131,6 +131,10 @@ (define-key "?" #'print-quick-help) +(define-key "C-h h" #'print-quick-help) + +(define-key "C-h a" #'apropos-help) + (define-key "!" #'gemini-search) (define-key ">" #'open-gemini-address) diff --git a/src/keybindings.lisp b/src/keybindings.lisp index 685a505..79b1db3 100644 --- a/src/keybindings.lisp +++ b/src/keybindings.lisp @@ -477,7 +477,7 @@ and `make-blocking-list-dialog-window') showing the full docstring for a command bg fg))) -(defun print-help (main-window) +(defun print-help (main-window &key (regex ".*")) "Generate an help text for the focused window and main window" (multiple-value-bind (header-bg header-fg attribute-header) (swconf:quick-help-header-colors) @@ -502,7 +502,13 @@ and `make-blocking-list-dialog-window') showing the full docstring for a command (alpha-b-p nil) (t - (string< text-a text-b)))))))) + (string< text-a text-b))))))) + (make-filter-help-text (scanner) + (lambda (a) + (scan scanner + (if (stringp a) + a + (tui:tui-string->chars-string a)))))) (when-let* ((focused-keybindings (main-window:focused-keybindings main-window)) (global-help (sort-help (key-paths *global-keymap*))) (header-focused (colorize-header (_ "Focused window keys"))) @@ -516,10 +522,15 @@ and `make-blocking-list-dialog-window') showing the full docstring for a command focused-help (list global-header-fields) global-help)) - (let ((all-lines (mapcar #'help-fields-get-text - fields))) - (line-oriented-window:make-blocking-list-dialog-window specials:*main-window* - fields - all-lines - #'help-expand - (_ "Quick help"))))))) + (handler-case + (let* ((scanner (create-scanner regex :case-insensitive-mode t)) + (all-lines (remove-if-not (make-filter-help-text scanner) + (mapcar #'help-fields-get-text + fields)))) + (line-oriented-window:make-blocking-list-dialog-window specials:*main-window* + fields + all-lines + #'help-expand + (_ "Quick help"))) + (error () + (ui:error-message (_ "Invalid regular expression")))))))) diff --git a/src/line-oriented-window.lisp b/src/line-oriented-window.lisp index 3350cc5..be03451 100644 --- a/src/line-oriented-window.lisp +++ b/src/line-oriented-window.lisp @@ -328,7 +328,8 @@ this exact quantity wold go beyond the length or rows or zero." "Draw a window with a scrollable list of entries, pressing enter will fire the `callback' function (with the selected field from `all-fields' and text from `text-line'. This window is fitten into `screen' sizes." - (assert (length= all-fields text-lines)) + (assert (>= (length all-fields) + (length text-lines))) (let* ((low-level-window (make-blocking-croatoan-window :enable-function-keys t)) (window-width (max (+ 4 (length title)) diff --git a/src/package.lisp b/src/package.lisp index 615be25..3d5c71c 100644 --- a/src/package.lisp +++ b/src/package.lisp @@ -1260,6 +1260,7 @@ :chat-change-label-event :chat-create-event :search-link-event + :help-apropos-event :function-event :dispatch-program-events :add-pagination-status-event @@ -2135,6 +2136,7 @@ :focus-to-tags-window :focus-to-conversations-window :print-quick-help + :apropos-help :move-message-tree :change-folder :change-timeline diff --git a/src/program-events.lisp b/src/program-events.lisp index b7059c6..1978bd7 100644 --- a/src/program-events.lisp +++ b/src/program-events.lisp @@ -1166,6 +1166,16 @@ (regex regex)) object (line-oriented-window:search-row window regex))) +(defclass help-apropos-event (program-event) + ((regex + :initform nil + :initarg :regex + :accessor regex))) + +(defmethod process-event ((object help-apropos-event)) + (with-accessors ((regex regex)) object + (keybindings:print-help specials:*main-window* :regex regex))) + ;;;; general usage (defclass function-event (program-event) ()) diff --git a/src/ui-goodies.lisp b/src/ui-goodies.lisp index 72bb959..39bebdd 100644 --- a/src/ui-goodies.lisp +++ b/src/ui-goodies.lisp @@ -523,6 +523,16 @@ Metadata includes: "Print a quick help" (keybindings:print-help *main-window*)) +(defun apropos-help () + "Print a command's documentation matching a regular expression." + (flet ((on-input-complete (regex) + (let ((event (make-instance 'help-apropos-event + :regex regex))) + (push-event event)))) + (ask-string-input #'on-input-complete + :prompt (_ "Search for commands (regexp): ") + :complete-fn #'complete:complete-always-empty))) + (defun move-message-tree () "Move messages tree" (flet ((on-input-complete (new-folder)