Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic filtering callback support for popup-isearch w/example filter by docstring #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 37 additions & 7 deletions popup.el
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,11 @@ KEYMAP is a keymap that will be put on the popup contents."
(when (< current-column column)
;; Extend short buffer lines by popup prefix (line of spaces)
(setq prefix (make-string
(+ (if (= current-column 0)
(- window-hscroll (current-column))
0)
(+
(if (= current-column 0)
0
;(- window-hscroll (current-column))
0)
(- column current-column))
? )))

Expand Down Expand Up @@ -872,6 +874,30 @@ KEYMAP is a keymap that will be put on the popup contents."
(<= 32 char)
(<= char 126)))

(defun popup-isearch-filter-list-by-doc (pattern list)
(loop with regexp = (regexp-quote pattern)
for item in list
for docstring = (popup-item-documentation item)
do

(unless (stringp item)
(setq item (popup-item-propertize (popup-x-to-string item)
'value item)))

if (and docstring (string-match regexp docstring))
collect
(let ((beg 0)
(end (length item)))
(alter-text-property 0 (length item) 'face
(lambda (prop)
(unless (eq prop 'popup-isearch-match)
prop))
item)
(put-text-property beg end
'face 'popup-isearch-match
item)
item)))

(defun popup-isearch-filter-list (pattern list)
(loop with regexp = (regexp-quote pattern)
for item in list
Expand All @@ -898,11 +924,14 @@ KEYMAP is a keymap that will be put on the popup contents."
(propertize pattern 'face 'isearch-fail)
pattern)))

(defun popup-isearch-update (popup pattern &optional callback)
(defun popup-isearch-update (popup pattern &optional callback filter)
(setf (popup-cursor popup) 0
(popup-scroll-top popup) 0
(popup-pattern popup) pattern)
(let ((list (popup-isearch-filter-list pattern (popup-original-list popup))))
(unless (functionp filter)
(setq filter 'popup-isearch-filter-list))

(let ((list (funcall filter pattern (popup-original-list popup))))
(popup-set-filtered-list popup list)
(if callback
(funcall callback list)))
Expand All @@ -913,7 +942,8 @@ KEYMAP is a keymap that will be put on the popup contents."
(cursor-color popup-isearch-cursor-color)
(keymap popup-isearch-keymap)
callback
help-delay)
help-delay
filter)
"Start isearch on POPUP. This function is synchronized, meaning
event loop waits for quiting of isearch.

Expand Down Expand Up @@ -960,7 +990,7 @@ HELP-DELAY is a delay of displaying helps."
(setq unread-command-events
(append (listify-key-sequence key) unread-command-events))
(return nil)))
(popup-isearch-update popup pattern callback))))
(popup-isearch-update popup pattern callback filter))))
(if old-cursor-color
(set-cursor-color old-cursor-color)))))

Expand Down