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

isearch-electric option #89

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ Scroll up `N` items of the `POPUP`. This won't wrap.
### Function: `popup-isearch`

popup-isearch popup &key cursor-color keymap callback help-delay
isearch-electric
=> boolean

Enter incremental search event loop of `POPUP`.
Expand Down Expand Up @@ -274,7 +275,8 @@ select an item of a list.
popup-menu* list &key point around width height margin margin-left
margin-right scroll-bar symbol parent parent-offset keymap
fallback help-delay nowait prompt isearch isearch-cursor-color
isearch-keymap isearch-callback initial-index => selected-value
isearch-keymap isearch-callback isearch-electric initial-index
=> selected-value

Show a popup menu of `LIST` at `POINT`. This function returns the value
of the selected item. Almost all arguments are same as `popup-create`
Expand Down Expand Up @@ -309,6 +311,9 @@ during event loop. The default value is `popup-isearch-keymap`.
calls `ISEARCH-CALLBACK`, if specified, after isearch finished or
isearch canceled. The arguments is whole filtered list of items.

If `ISEARCH-ELECTRIC` is non-nil popup will be closed when filtered
list contains 1 element.

If `INITIAL-INDEX` is non-nil, this is an initial index value for
`popup-select`. Only positive integer is valid.

Expand Down
32 changes: 24 additions & 8 deletions popup.el
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,8 @@ Pages up through POPUP."
(cursor-color popup-isearch-cursor-color)
(keymap popup-isearch-keymap)
callback
help-delay)
help-delay
isearch-electric)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you fix the indentation here? Probably should use spaces instead of tabs. Thanks!

"Start isearch on POPUP. This function is synchronized, meaning
event loop waits for quiting of isearch.

Expand All @@ -948,7 +949,10 @@ CALLBACK is a function taking one argument. `popup-isearch' calls
CALLBACK, if specified, after isearch finished or isearch
canceled. The arguments is whole filtered list of items.

HELP-DELAY is a delay of displaying helps."
HELP-DELAY is a delay of displaying helps.

If ISEARCH-ELECTRIC is set to non-nil, isearch will exit isearch
as soon as filtered list has 1 completion."
(let ((list (popup-original-list popup))
(pattern (or (popup-pattern popup) ""))
(old-cursor-color (frame-parameter (selected-frame) 'cursor-color))
Expand Down Expand Up @@ -986,7 +990,9 @@ HELP-DELAY is a delay of displaying helps."
(setq unread-command-events
(append (listify-key-sequence key) unread-command-events))
(cl-return nil)))
(popup-isearch-update popup pattern callback))))
(popup-isearch-update popup pattern callback)
(if (and isearch-electric (= 1 (length (popup-list popup))))
(cl-return nil)))))
(if old-cursor-color
(set-cursor-color old-cursor-color)))))

Expand Down Expand Up @@ -1180,6 +1186,7 @@ PROMPT is a prompt string when reading events during event loop."
isearch-cursor-color
isearch-keymap
isearch-callback
isearch-electric
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here too! Tabs to spaces! Thanks! ;)

&aux key binding)
(cl-block nil
(while (popup-live-p menu)
Expand All @@ -1188,8 +1195,11 @@ PROMPT is a prompt string when reading events during event loop."
:cursor-color isearch-cursor-color
:keymap isearch-keymap
:callback isearch-callback
:help-delay help-delay)
:help-delay help-delay
:isearch-electric isearch-electric)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here!

(keyboard-quit))
(if (and isearch-electric (= 1 (length (popup-list menu))))
(cl-return (popup-item-value-or-self (popup-selected-item menu))))
(setq key (popup-menu-read-key-sequence keymap prompt help-delay))
(setq binding (and key (lookup-key keymap key)))
(cond
Expand Down Expand Up @@ -1241,7 +1251,8 @@ PROMPT is a prompt string when reading events during event loop."
:cursor-color isearch-cursor-color
:keymap isearch-keymap
:callback isearch-callback
:help-delay help-delay))
:help-delay help-delay
:isearch-electric isearch-electric))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here!

((commandp binding)
(call-interactively binding))
(t
Expand Down Expand Up @@ -1309,13 +1320,14 @@ PROMPT is a prompt string when reading events during event loop."
(isearch-cursor-color popup-isearch-cursor-color)
(isearch-keymap popup-isearch-keymap)
isearch-callback
isearch-electric
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here!

initial-index
&aux menu event)
"Show a popup menu of LIST at POINT. This function returns a
value of the selected item. Almost arguments are same as
`popup-create' except for KEYMAP, FALLBACK, HELP-DELAY, PROMPT,
ISEARCH, ISEARCH-CURSOR-COLOR, ISEARCH-KEYMAP, and
ISEARCH-CALLBACK.
ISEARCH, ISEARCH-CURSOR-COLOR, ISEARCH-KEYMAP, ISEARCH-ELECTRIC
and ISEARCH-CALLBACK.

If KEYMAP is a keymap which is used when processing events during
event loop.
Expand Down Expand Up @@ -1345,6 +1357,9 @@ ISEARCH-CALLBACK is a function taking one argument. `popup-menu'
calls ISEARCH-CALLBACK, if specified, after isearch finished or
isearch canceled. The arguments is whole filtered list of items.

If ISEARCH-ELECTRIC is non-nil popup will be closed when filtered
list contains 1 element.

If `INITIAL-INDEX' is non-nil, this is an initial index value for
`popup-select'. Only positive integer is valid."
(and (eq margin t) (setq margin 1))
Expand Down Expand Up @@ -1385,7 +1400,8 @@ If `INITIAL-INDEX' is non-nil, this is an initial index value for
:isearch isearch
:isearch-cursor-color isearch-cursor-color
:isearch-keymap isearch-keymap
:isearch-callback isearch-callback)))
:isearch-callback isearch-callback
:isearch-electric isearch-electric)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And here!

(unless nowait
(popup-delete menu))))

Expand Down