Skip to content

Commit

Permalink
Autocomplete actually works now. Sensitive to namepsace during autoco…
Browse files Browse the repository at this point in the history
…mplete
  • Loading branch information
Aria Haghighi committed Oct 27, 2010
1 parent 3d40bd0 commit 2694dce
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
55 changes: 47 additions & 8 deletions Support/bin/autocomplete.clj
Expand Up @@ -5,12 +5,51 @@
(clojure.core/require '[clojure.repl :as repl])
(clojure.core/load-file (clojure.core/str (io/file (cake/*env* "TM_BUNDLE_SUPPORT") "utils.clj")))

; (println "symbol:" (get-symbol-to-autocomplete))
; (println (ns-refers (file-ns)) "<br>")
(defn- get-completions []
(let [cur-symbol (get-symbol-to-autocomplete)]
(concat
(for [s (map (comp str first) (concat (ns-publics (file-ns)) (ns-refers (file-ns))))
:when (.startsWith s cur-symbol)] s))))
(defn- raw-symbol-completes [ns symb-prefix target-ns]
(let [possible (if target-ns
(ns-publics target-ns)
(concat (ns-publics ns) (ns-refers ns)))]
(for [symb possible
:let [name (-> symb first str)]
:when (.startsWith name symb-prefix)]
name)))

(defn- raw-ns-completes [ns ns-prefix]
(for [[alias-ns _] (ns-aliases ns)
:let [name (.toString alias-ns)]
:when (and (.startsWith name ns-prefix))]
name))

(defn- get-completions
([so-far]
(let [[_ ns-name var-name] (re-matches #"(?:([\w?_-]+)/)?([\w?_-]*)" so-far)
target-ns (when ns-name ((ns-aliases (file-ns)) (symbol ns-name)))]
#_(println "Complete:" (.toString target-ns))
(concat
(raw-symbol-completes (file-ns) var-name target-ns)
(when-not target-ns (raw-ns-completes (file-ns) var-name)))))
([] (get-completions (get-symbol-to-autocomplete))))

(println (string/join " " (get-completions)))
(println
(try
(string/join " " (get-completions))
(catch Exception _ "")))

(comment
(get-completions "repl/s")
(ns-resolve)
(ns-resolve (file-ns) (symbol "get-completions"))
(ns-aliases (file-ns))
(ns-refers)
(doc symbol)
(.toString ((ns-aliases (file-ns)) (symbol "repl")))

(raw-ns-completes (file-ns) "re")
(-> get-completions .getClass .getMethods)
(raw-symbol-completes (file-ns) "re" "")
(va (second (first (ns-publics (file-ns)))))
(ns-interns (file-ns))
(ns-refers (file-ns))
(ns-map (file-ns))
(.toString (ffirst (ns-aliases (file-ns))))
)
15 changes: 10 additions & 5 deletions Support/utils.clj
Expand Up @@ -167,11 +167,16 @@

(defn get-symbol-to-autocomplete []
(let [#^String line (-> "TM_CURRENT_LINE" cake/*env* escape-str)
stop (dec (last (carret-info)))]
(loop [index stop]
(cond (zero? index) (.substring line 0 stop)
(not (symbol-char? (.charAt line index))) (.substring line (inc index) (inc stop))
:else (recur (dec index))))))
stop (dec (last (carret-info)))]
#_(println (carret-info))
(loop [index stop]
(let [ch (.charAt line index)]
#_(println "index:" index "char:" ch"<br>")
(cond
(zero? index) (.trim (.substring line 0 (inc stop)))
(or (nil? ch) (not (symbol-char? (.charAt line index))))
(.trim (.substring line (inc index) (inc stop)))
:else (recur (dec index)))))))


(defn get-current-symbol-str
Expand Down

0 comments on commit 2694dce

Please sign in to comment.