Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
clemera committed Aug 8, 2020
1 parent b592bc9 commit ea42453
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
5 changes: 1 addition & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,19 +156,16 @@ The format is based on [Keep a Changelog].
[#138]: https://github.com/raxod502/selectrum/pull/138
[#139]: https://github.com/raxod502/selectrum/issues/139
[#140]: https://github.com/raxod502/selectrum/pull/140
<<<<<<< HEAD
[#156]: https://github.com/raxod502/selectrum/pull/156
=======
[#146]: https://github.com/raxod502/selectrum/issues/146
[#151]: https://github.com/raxod502/selectrum/issues/151
[#152]: https://github.com/raxod502/selectrum/pull/152
[#154]: https://github.com/raxod502/selectrum/pull/154
[#156]: https://github.com/raxod502/selectrum/pull/156
[#157]: https://github.com/raxod502/selectrum/issues/157
[#159]: https://github.com/raxod502/selectrum/issues/159
[#160]: https://github.com/raxod502/selectrum/pull/160
[#161]: https://github.com/raxod502/selectrum/pull/161
[#163]: https://github.com/raxod502/selectrum/pull/163
>>>>>>> master

## 2.0 (released 2020-07-18)
### Breaking changes
Expand Down
66 changes: 31 additions & 35 deletions selectrum.el
Original file line number Diff line number Diff line change
Expand Up @@ -1167,9 +1167,7 @@ list). A null or non-positive ARG inserts the candidate corresponding to
(delete-region (point) selectrum--end-of-input-marker))
(let* ((candidate (nth index
selectrum--refined-candidates))
(full
(or (get-text-property 0 'selectrum--candidate-insert candidate)
(selectrum--get-full candidate))))
(full (selectrum--get-full candidate)))
(insert full)
(unless (eq t minibuffer-history-variable)
(add-to-history minibuffer-history-variable full))
Expand Down Expand Up @@ -1402,10 +1400,17 @@ The symbol is used to identify COLLECTION in
(defun selectrum--locate-library-transformer (collection)
"Return table for COLLECTION.
See `selectrum-locate-library' in
`selectrum--completing-read-handler-alist'."
`selectrum--completing-read-handler-alist' and
`selectrum--get-collection-name'."
(lambda (string pred flag)
(if (eq flag t)
(selectrum--locate-library-completions)
(delete-dups
(selectrum--get-candidates-from-table
collection
(lambda (cand)
(and (or (not pred)
(funcall pred cand))
(not (directory-name-p cand))))))
(funcall collection string pred flag))))

(defvar org-last-tags-completion-table)
Expand Down Expand Up @@ -1819,10 +1824,11 @@ For large enough N, return PATH unchanged."
(string-match regexp path)
(match-string 0 path))))

(defun selectrum--locate-library-completions ()
"Get list of candidates for library completions.
SUFFIXES defaults to the value returned by
`find-library-suffixes'."
;;;###autoload
(defun selectrum-read-library-name ()
"Read and return a library name.
Similar to `read-library-name' except it handles `load-path'
shadows correctly."
(eval-and-compile
(require 'find-func))
(let ((suffix-regexp (concat (regexp-opt (find-library-suffixes)) "\\'"))
Expand Down Expand Up @@ -1856,36 +1862,26 @@ SUFFIXES defaults to the value returned by
(when (or (= num-components max-components)
(= (length paths) (length abbrev-paths)))
(let ((candidate-paths
(mapcar
(lambda (path)
(let ((name (file-name-base
(file-name-sans-extension path))))
(propertize
name
'selectrum-candidate-display-prefix
(file-name-directory
(file-name-sans-extension
(selectrum--trailing-components
num-components path)))
'fixedcase 'literal
'selectrum--candidate-insert name
'selectrum-candidate-full path)))
paths)))
(mapcar (lambda (path)
(propertize
(file-name-base
(file-name-sans-extension path))
'selectrum-candidate-display-prefix
(file-name-directory
(file-name-sans-extension
(selectrum--trailing-components
num-components path)))
'fixedcase 'literal
'selectrum--lib-path path))
paths)))
(setq lst (nconc candidate-paths lst)))
(cl-return)))
(cl-incf num-components)))))
table)
lst))

;;;###autoload
(defun selectrum-read-library-name ()
"Read and return a library name.
Similar to `read-library-name' except it handles `load-path'
shadows correctly."
(selectrum-read
"Library name: "
(selectrum--locate-library-completions)
:require-match t :may-modify-candidates t))
(get-text-property
0 'selectrum--lib-path
(selectrum-read
"Library name: " lst :require-match t :may-modify-candidates t))))

(defun selectrum-repeat ()
"Repeat the last command that used Selectrum, and try to restore state."
Expand Down

0 comments on commit ea42453

Please sign in to comment.