Skip to content

Commit

Permalink
le-clojure.el (lispy-clojure-complete-at-point): Remove dependency on…
Browse files Browse the repository at this point in the history
… compliment

Re #615
  • Loading branch information
abo-abo committed Jan 3, 2022
1 parent a2e5398 commit ca14d62
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 47 deletions.
26 changes: 1 addition & 25 deletions le-clojure.el
Expand Up @@ -563,31 +563,7 @@ Besides functions, handles specials, keywords, maps, vectors and sets."
(setq cands (all-completions (lispy--string-dwim bnd) cands)))
(list (car bnd) (cdr bnd) cands)))
((eq (lispy--clojure-process-type) 'cljs)
nil)
((save-excursion
(lispy--out-backward 2 t)
(looking-at "(import"))
(let* ((prefix (save-excursion
(lispy--out-backward 1 t)
(forward-char)
(thing-at-point 'symbol t)))
(cands (read (lispy--eval-clojure-cider-noerror
(format
"(lispy.clojure/complete %S)"
prefix))))
(len (1+ (length prefix)))
(candsa (mapcar (lambda (s) (substring s len)) cands)))
(when (> (cdr bnd) (car bnd))
(setq candsa (all-completions (lispy--string-dwim bnd) candsa)))
(list (car bnd) (cdr bnd) candsa)))
(t
(let* ((prefix (lispy--string-dwim bnd))
(cands (read (lispy--eval-clojure-cider-noerror
(format
"(lispy.clojure/complete %S)"
prefix)))))
(when cands
(list (car bnd) (cdr bnd) cands))))))))))
nil)))))))

(defun lispy--eval-clojure-cider-noerror (e-str)
(condition-case nil
Expand Down
37 changes: 15 additions & 22 deletions lispy-clojure.clj
Expand Up @@ -21,11 +21,12 @@
(:require [clojure.repl :as repl]
[clojure.pprint]
[clojure.java.io :as io]
[clojure.string :as str])
(:use [cemerick.pomegranate :only (add-dependencies)])
(:import (java.io File LineNumberReader InputStreamReader
PushbackReader FileInputStream)
(clojure.lang RT Reflector)))
[clojure.string :as str]
[cemerick.pomegranate :refer [add-dependencies]])
(:import
(java.io File LineNumberReader InputStreamReader
PushbackReader FileInputStream)
(clojure.lang RT)))

(defn use-package [name version]
(add-dependencies
Expand All @@ -37,17 +38,15 @@
(defn expand-file-name [name dir]
(. (io/file dir name) getCanonicalPath))

(use-package 'compliment "0.3.11")
(require '[compliment.core :as compliment])

(use-package 'me.raynes/fs "1.4.6")
(require '[me.raynes.fs :as fs])

(defmacro xcond [& clauses]
(defmacro xcond
"Common Lisp style `cond'.
It's more structured than `cond', thus exprs that use it are lot more
malleable to refactoring."
[& clauses]
(when clauses
(let [clause (first clauses)]
(if (= (count clause) 1)
Expand Down Expand Up @@ -246,7 +245,7 @@ malleable to refactoring."
(let [[_do & forms] (dest bindings)
[defs out] (partition-by map? forms)]
`(let ~(vec (mapcat (fn [[_ n v]] [n v]) defs))
~@(if (not= *ns* nspc)
~@(when (not= *ns* nspc)
`((in-ns '~(ns-name nspc))))
~@(map
(fn [x]
Expand Down Expand Up @@ -323,7 +322,7 @@ malleable to refactoring."
(or
(resolve sym)
(first (keep #(ns-resolve % sym) (all-ns)))
(if-let [val (try (load-string (str sym)) (catch Exception e))]
(when-let [val (try (load-string (str sym)) (catch Exception _e))]
(list 'variable (str val)))))]

[(keyword? sym) 'keyword]
Expand Down Expand Up @@ -352,7 +351,7 @@ malleable to refactoring."
(xcond
((= 'special rsym)
(->> (with-out-str
(eval (list 'clojure.repl/doc sym)))
(eval (list #'repl/doc sym)))
(re-find #"\(.*\)")
read-string rest
(map str)
Expand Down Expand Up @@ -413,7 +412,7 @@ malleable to refactoring."
(and
(reader= (first a) (first b))
(reader= (rest a) (rest b)))))
(catch Exception e
(catch Exception _e
(= a b))))

(defn position [x coll equality]
Expand Down Expand Up @@ -468,9 +467,8 @@ malleable to refactoring."
(= 'defn (first expr))
file line)
(let [arglist-pos (first (keep-indexed
(fn [i x] (if (or
(vector? x)
(list? x)) i))
(fn [i x] (when (or (vector? x) (list? x))
i))
expr))
expr-head (take arglist-pos expr)
expr-tail (drop arglist-pos expr)
Expand Down Expand Up @@ -509,7 +507,7 @@ malleable to refactoring."
(java.io.StringReader. s))]
(loop [res []]
(if-let [x (try (read reader)
(catch Exception e))]
(catch Exception _e))]
(recur (conj res x))
res))))

Expand Down Expand Up @@ -563,11 +561,6 @@ malleable to refactoring."
(let [m (meta v)]
(str v "\n" (:arglists m) "\n" (:doc m))))))))

(defn complete [prefix]
(compliment/completions
prefix
{:context :same :plain-candidates true}))

(defn run-lispy-tests []
(let [dd (fs/parent (:file (meta #'use-package)))
fname (java.io.File. dd "lispy-clojure-test.clj")]
Expand Down

0 comments on commit ca14d62

Please sign in to comment.