Skip to content

Commit

Permalink
Allow setting default value via minibuffer-default (#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
clemera authored Jan 5, 2021
1 parent 8225104 commit 115a99a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ The format is based on [Keep a Changelog].
default is t) ([#261]).

### Enhancements
* The prompt gets selected when using `next-history-element` and the
prompt equals the default ([#323], [#324]).
* Computation of candidates is faster for `describe-variable` ([#312],
[#316], [#320], [#321]).
* Candidates of `completing-read-multiple` which are submitted by
Expand Down Expand Up @@ -66,6 +68,9 @@ The format is based on [Keep a Changelog].
they contain ([#266], [#302], [#318]).

### Bugs fixed
* `minibuffer-default` is now treated as the default when set, before
it would have no effect. When a list the car is used as default as
of now ([#324]).
* `selectrum-extend-current-candidate-highlight`,
`selectrum-show-indices`, `selectrum-right-margin-padding` and
`selectrum-multiline-display-settings` wouldn't use the local
Expand Down Expand Up @@ -155,6 +160,8 @@ The format is based on [Keep a Changelog].
[#318]: https://github.com/raxod502/selectrum/pull/318
[#320]: https://github.com/raxod502/selectrum/issues/320
[#321]: https://github.com/raxod502/selectrum/pull/321
[#323]: https://github.com/raxod502/selectrum/issues/323
[#324]: https://github.com/raxod502/selectrum/pull/324

## 3.0 (released 2020-10-20)
### Breaking changes
Expand Down
19 changes: 13 additions & 6 deletions selectrum.el
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,8 @@ the update."
(not (member selectrum--default-candidate
selectrum--refined-candidates)))
-1)
((and selectrum--init-p
((and (or selectrum--init-p
(eq this-command 'next-history-element))
(equal selectrum--default-candidate
(minibuffer-contents)))
-1)
Expand Down Expand Up @@ -1273,7 +1274,8 @@ TABLE defaults to `minibuffer-completion-table'. PRED defaults to
"Set up minibuffer for interactive candidate selection.
CANDIDATES is the list of strings that was passed to
`selectrum-read'. DEFAULT-CANDIDATE, if provided, is added to the
list and sorted first."
list and sorted first. If `minibuffer-default' is set it will
have precedence over DEFAULT-CANDIDATE."
(setq-local selectrum-active-p t)
(add-hook
'minibuffer-exit-hook #'selectrum--minibuffer-exit-hook nil 'local)
Expand All @@ -1297,10 +1299,15 @@ list and sorted first."
(funcall selectrum-preprocess-candidates-function
candidates))
(setq selectrum--total-num-candidates (length candidates))))
(setq selectrum--default-candidate
(if (and default-candidate (symbolp default-candidate))
(symbol-name default-candidate)
default-candidate))
;; If the default is added by setup hook it should have
;; precedence like with default completion.
(let ((default (or (car-safe minibuffer-default)
minibuffer-default
default-candidate)))
(setq selectrum--default-candidate
(if (and default (symbolp default))
(symbol-name default)
default)))
;; Make sure to trigger an "user input changed" event, so that
;; candidate refinement happens in `post-command-hook' and an index
;; is assigned.
Expand Down

0 comments on commit 115a99a

Please sign in to comment.