On Sun, 2011-11-13 at 12:13 +0000, Ben Spencer wrote: > Hi Rodrigo, > > On Sat, Aug 27, 2011 at 11:03:40AM -0300, Rodrigo Lazo wrote: > > Now, windowlist command tries to match what I type with a window name, > > which is great, except that it has two problems: > > > > * `j` and `k` move-up and move-down the list, which is confusing. > > This has been discussed before. I believe the bindings were added > before menus were made searchable, and left in for backward > compatibility. You can disable them with: > > (define-key *menu-map* (kbd "j") nil) > (define-key *menu-map* (kbd "k") nil) > > We probably could remove them from the defaults: I haven't heard > anyone with a particularly strong opinion on the matter. > I think we should remove the "j" and "k" bindings because they violate the principle of least astonishment. It is probably really confusing (as a user) that every "normal" (alphanumeric) key adds to the search string, EXCEPT "j" and "k", which clear the search string and move the selection. > > > * Pressing Backspace inserts a `?` char, instead of deleting the > > preceding char. > > > > Fix for the backspace is pretty simple, at least in the way I've done it > > (not sure if it's the right way, though). > > There was a previous patch that did this in a slightly nicer way, by > making it a function that could be bound in *menu-map*: > > http://lists.nongnu.org/archive/html/stumpwm-devel/2011-03/txtROpg6gZmvP.txt > I have attached a patch that implements this feature. > ISTR there were some other issues with that patch, so it wasn't > applied, but that part seems ok and could be extracted. > > > Incidentally, the current-input slot should really use an adjustable > vector with a fill pointer (as in input.lisp) rather than copying > strings all over the place. This should be an easy fix if anyone > feels like doing it. > I have attached a patch which implements this as well. > > Ben > While testing my Backspace patch, I discovered a bug: pressing Page Up of Page Down with *menu-maximum-height* set to nil causes the error "Argument Y is not a number: NIL". A patch which fixes this issue is attached.
Krzysztof Drewniak -- X-Real-Email-With-Antispam: krzysdrewniak at gmail dot com pgp key on keyserver.ubuntu.com 2388E924
From ad1f12980cae77280a49ac1e6ef5d386f355b0f2 Mon Sep 17 00:00:00 2001 From: Krzysztof Drewniak <krzysdrewn...@gmail.com> Date: Sun, 13 Nov 2011 14:56:05 -0600 Subject: [PATCH 1/3] Repalce the current-input string in menu.lisp with a vector with a fill-pointer. --- menu.lisp | 25 ++++++++++++------------- 1 files changed, 12 insertions(+), 13 deletions(-) diff --git a/menu.lisp b/menu.lisp index dc8a3c8..c0b511b 100644 --- a/menu.lisp +++ b/menu.lisp @@ -54,7 +54,8 @@ m))) (defstruct menu-state - table prompt selected view-start view-end current-input) + table prompt selected view-start view-end + (current-input (make-array 10 :element-type 'character :adjustable t :fill-pointer 0))) (defun bound-check-menu (menu) "Adjust the menu view and selected item based @@ -85,34 +86,36 @@ on current view and new selection." (values (menu-state-view-start menu) (menu-state-view-end menu))))))))) +;;TODO: Refactor these? + (defun menu-up (menu) - (setf (menu-state-current-input menu) "") + (setf (fill-pointer (menu-state-current-input menu)) 0) (decf (menu-state-selected menu)) (bound-check-menu menu)) (defun menu-down (menu) - (setf (menu-state-current-input menu) "") + (setf (fill-pointer (menu-state-current-input menu)) 0) (incf (menu-state-selected menu)) (bound-check-menu menu)) (defun menu-scroll-up (menu) - (setf (menu-state-current-input menu) "") + (setf (fill-pointer (menu-state-current-input menu)) 0) (decf (menu-state-selected menu) *menu-scrolling-step*) (bound-check-menu menu)) (defun menu-scroll-down (menu) - (setf (menu-state-current-input menu) "") + (setf (fill-pointer (menu-state-current-input menu)) 0) (incf (menu-state-selected menu) *menu-scrolling-step*) (bound-check-menu menu)) (defun menu-page-up (menu) - (setf (menu-state-current-input menu) "") + (setf (fill-pointer (menu-state-current-input menu)) 0) (decf (menu-state-selected menu) *menu-maximum-height*) (let ((*menu-scrolling-step* *menu-maximum-height*)) (bound-check-menu menu))) (defun menu-page-down (menu) - (setf (menu-state-current-input menu) "") + (setf (fill-pointer (menu-state-current-input menu)) 0) (incf (menu-state-selected menu) *menu-maximum-height*) (let ((*menu-scrolling-step* *menu-maximum-height*)) (bound-check-menu menu))) @@ -145,10 +148,7 @@ backspace or F9), return it otherwise return nil" long as the user types lower-case characters." (let ((input-char (get-input-char key-seq))) (when input-char - (setf (menu-state-current-input menu) - (concatenate 'string - (menu-state-current-input menu) - (string input-char))) + (vector-push-extend input-char (menu-state-current-input menu)) (do* ((cur-pos 0 (1+ cur-pos)) (rest-elem (menu-state-table menu) (cdr rest-elem)) @@ -185,7 +185,6 @@ See *menu-map* for menu bindings." (menu (make-menu-state :table table :prompt prompt - :current-input "" :view-start (if menu-require-scrolling initial-selection 0) :view-end (if menu-require-scrolling (+ initial-selection *menu-maximum-height*) @@ -208,7 +207,7 @@ See *menu-map* for menu bindings." (incf highlight)) (unless (= (length menu-options) (menu-state-view-end menu)) (setf strings (nconc strings '("...")))) - (unless (string= (menu-state-current-input menu) "") + (unless (= (fill-pointer (menu-state-current-input menu)) 0) (setf strings (cons (format nil "Search: ~a" (menu-state-current-input menu)) -- 1.7.4.1
From b58f35aefb6fd80400a9aa53b89054bfecca3283 Mon Sep 17 00:00:00 2001 From: Krzysztof Drewniak <krzysdrewn...@gmail.com> Date: Sun, 13 Nov 2011 15:49:01 -0600 Subject: [PATCH 2/3] Fixed error when using PgUp/Down without a *menu-maximum-height* --- menu.lisp | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-) diff --git a/menu.lisp b/menu.lisp index c0b511b..5eddd92 100644 --- a/menu.lisp +++ b/menu.lisp @@ -109,16 +109,18 @@ on current view and new selection." (bound-check-menu menu)) (defun menu-page-up (menu) - (setf (fill-pointer (menu-state-current-input menu)) 0) - (decf (menu-state-selected menu) *menu-maximum-height*) - (let ((*menu-scrolling-step* *menu-maximum-height*)) - (bound-check-menu menu))) + (when *menu-maximum-height* ;;No scrolling = no page up/down + (setf (fill-pointer (menu-state-current-input menu)) 0) + (decf (menu-state-selected menu) *menu-maximum-height*) + (let ((*menu-scrolling-step* *menu-maximum-height*)) + (bound-check-menu menu)))) (defun menu-page-down (menu) - (setf (fill-pointer (menu-state-current-input menu)) 0) - (incf (menu-state-selected menu) *menu-maximum-height*) - (let ((*menu-scrolling-step* *menu-maximum-height*)) - (bound-check-menu menu))) + (when *menu-maximum-height* + (setf (fill-pointer (menu-state-current-input menu)) 0) + (incf (menu-state-selected menu) *menu-maximum-height*) + (let ((*menu-scrolling-step* *menu-maximum-height*)) + (bound-check-menu menu)))) (defun menu-finish (menu) -- 1.7.4.1
From a6e13143590bfb7ce9e62edc0b2ea79e2f2c3f88 Mon Sep 17 00:00:00 2001 From: Krzysztof Drewniak <krzysdrewn...@gmail.com> Date: Sun, 13 Nov 2011 17:04:09 -0600 Subject: [PATCH 3/3] The backspace key now functions correctly. A new function `menu-backspace' has been defined which removes a single character from the menu search string. The function `menu-backspace' is bound to DEL by default in *menu-map* . --- menu.lisp | 50 ++++++++++++++++++++++++++++++-------------------- 1 files changed, 30 insertions(+), 20 deletions(-) diff --git a/menu.lisp b/menu.lisp index 5eddd92..8169deb 100644 --- a/menu.lisp +++ b/menu.lisp @@ -48,6 +48,8 @@ (define-key m (kbd "SunPageDown") 'menu-page-down) (define-key m (kbd "J") 'menu-page-down) + (define-key m (kbd "DEL") 'menu-backspace) + (define-key m (kbd "C-g") 'menu-abort) (define-key m (kbd "ESC") 'menu-abort) (define-key m (kbd "RET") 'menu-finish) @@ -131,8 +133,8 @@ on current view and new selection." (throw :menu-quit nil)) (defun get-input-char (key) - "If @var{key} is a character suitable for menu completion (e.g. not -backspace or F9), return it otherwise return nil" + "If @var{key} is a character suitable for menu completion (e.g. +not backspace or F9), return it otherwise return nil" (let ((char (xlib:keysym->character *display* (key-keysym key)))) (if (or (key-mods-p key) (null char) (not (characterp char))) @@ -144,29 +146,37 @@ backspace or F9), return it otherwise return nil" (first element) element)) +(defun menu-backspace (menu) + (when (> (fill-pointer (menu-state-current-input menu)) 0) + (vector-pop (menu-state-current-input menu)) + (check-menu-complete menu nil))) + (defun check-menu-complete (menu key-seq) "If the use entered a key not mapped in @var{*menu-map}, check if - he's trying to type an entry's name. Match is case insensitive as - long as the user types lower-case characters." - (let ((input-char (get-input-char key-seq))) +he's trying to type an entry's name. Match is case insensitive as +long as the user types lower-case characters. If @var{key-seq} is +nil, some other function has manipulated the current-input and is +requesting a re-computation of the match." + (let ((input-char (and key-seq (get-input-char key-seq)))) (when input-char - (vector-push-extend input-char (menu-state-current-input menu)) + (vector-push-extend input-char (menu-state-current-input menu))) + (when (or input-char (not key-seq)) (do* ((cur-pos 0 (1+ cur-pos)) - (rest-elem (menu-state-table menu) - (cdr rest-elem)) - (cur-elem (car rest-elem) (car rest-elem)) - (cur-elem-name (menu-element-name cur-elem) (menu-element-name cur-elem)) - (current-input-length (length (menu-state-current-input menu))) - (match-regex (ppcre:create-scanner (menu-state-current-input menu) - :case-insensitive-mode - (string= (string-downcase (menu-state-current-input menu)) - (menu-state-current-input menu))))) - ((not cur-elem)) - (when (and (>= (length cur-elem-name) current-input-length) - (ppcre:scan match-regex cur-elem-name)) - (setf (menu-state-selected menu) cur-pos) + (rest-elem (menu-state-table menu) + (cdr rest-elem)) + (cur-elem (car rest-elem) (car rest-elem)) + (cur-elem-name (menu-element-name cur-elem) (menu-element-name cur-elem)) + (current-input-length (length (menu-state-current-input menu))) + (match-regex (ppcre:create-scanner (menu-state-current-input menu) + :case-insensitive-mode + (string= (string-downcase (menu-state-current-input menu)) + (menu-state-current-input menu))))) + ((not cur-elem)) + (when (and (>= (length cur-elem-name) current-input-length) + (ppcre:scan match-regex cur-elem-name)) + (setf (menu-state-selected menu) cur-pos) (bound-check-menu menu) - (return)))))) + (return)))))) (defun select-from-menu (screen table &optional prompt (initial-selection 0)) -- 1.7.4.1
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Stumpwm-devel mailing list Stumpwm-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/stumpwm-devel