Skip to content

Commit

Permalink
Provide an ability to customize sort-order
Browse files Browse the repository at this point in the history
As requested in trptcolin/reply#153.
  • Loading branch information
alexander-yakushev committed Aug 5, 2014
1 parent 7cf7453 commit b10b817
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/compliment/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,25 @@ through functions defined here."
candidates))

(defn completions
"Returns a list of completions for the given prefix. Optional
context (can be nil) should be a Lisp form from where the completion
was initiated, having prefix replaced with `__prefix__` symbol."
"Returns a list of completions for the given prefix. Optional context (can be
nil) should be a string with Lisp form from where the completion was initiated,
having prefix replaced with `__prefix__` symbol. Optional sort-order can be
either :by-length or :by-name."
([prefix context-str]
(completions prefix *ns* context-str))
(completions prefix *ns* context-str :by-length))
([prefix ns context-str]
(let [ctx (cache-context context-str)]
(completions prefix ns context-str :by-length))
([prefix ns context-str sort-order]
(let [ctx (cache-context context-str)
sort-fn (if (= sort-order :by-name)
sort sort-by-length)]
(-> (for [[_ {:keys [candidates enabled]}] (all-sources)
:when enabled
:let [cands (candidates prefix ns ctx)]
:when cands]
cands)
flatten
sort-by-length))))
sort-fn))))

(defn documentation
"Returns a documentation string that describes the given symbol."
Expand Down

0 comments on commit b10b817

Please sign in to comment.