Skip to content

Commit

Permalink
add double click grep results to load buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostandthemachine committed Aug 30, 2012
1 parent 98e5782 commit 3f1877a
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 63 deletions.
1 change: 1 addition & 0 deletions build.xml
Expand Up @@ -23,6 +23,7 @@
<resourcefileset dir="resources">
<include name="default.clj" />
<include name="themes/*" />
<include name="english_dic.zip" />
</resourcefileset>
</jarbundler>
</target>
Expand Down
2 changes: 1 addition & 1 deletion project.clj
@@ -1,7 +1,7 @@
(defproject sketchpad "0.0.1-SNAPSHOT"
:description "A light weight IDE for programming with Overtone and Clojure"
:main sketchpad.core
:resource-paths ["resources"] ; non-code files included in classpath/jar
:resource-paths ["resources" "resources/english_dic.zip"] ; non-code files included in classpath/jar
:dependencies [[org.clojure/clojure "1.4.0"]
[seesaw "1.4.2"]
[clooj "0.3.4.2-SNAPSHOT"]
Expand Down
33 changes: 19 additions & 14 deletions src/sketchpad/auto_complete/auto_complete.clj
Expand Up @@ -126,7 +126,12 @@ more than one line, and if used with a text component using a
(defonce fuzzy-provider (org.fife.ui.autocomplete.DefaultCompletionProvider. ))
(defonce fuzzy-ac (org.fife.ui.autocomplete.AutoCompletion. fuzzy-provider))

(defn not-sufix?
(defn- not-sufix?
[f suffix-vec]
(let [suffix (last (clojure.string/split (.getName f) #"\."))]
(not (nil? (some #(= suffix %) suffix-vec)))))

(defn- in-inclusions?
[f suffix-vec]
(let [suffix (last (clojure.string/split (.getName f) #"\."))]
(not (nil? (some #(= suffix %) suffix-vec)))))
Expand All @@ -136,19 +141,19 @@ more than one line, and if used with a text component using a
(let [project-name (last (clojure.string/split project-path #"/"))]
(when (and
(not (= (.getName f) ".DS_Store"))
(not (not-sufix? f config/fuzzy-file-type-exclusions))
(let [path-split (clojure.string/split (.getAbsolutePath f) (java.util.regex.Pattern/compile project-name) 2)]
(.addCompletion fuzzy-provider
(ShorthandCompletion. fuzzy-provider
(str (.getName f))
(str "{"
":file " "\"" (last path-split) "\""
" "
":project " "\"" (first path-split) project-name "\""
" "
":absolute-path " "\"" (.getAbsolutePath f) "\""
"}")
(str (last path-split)))))))))
(in-inclusions? f config/fuzzy-file-type-inclusions))
(let [path-split (clojure.string/split (.getAbsolutePath f) (java.util.regex.Pattern/compile project-name) 2)]
(.addCompletion fuzzy-provider
(ShorthandCompletion. fuzzy-provider
(str (.getName f))
(str "{"
":file " "\"" (last path-split) "\""
" "
":project " "\"" (first path-split) project-name "\""
" "
":absolute-path " "\"" (.getAbsolutePath f) "\""
"}")
(str (last path-split))))))))

(defn add-files-to-fuzzy-complete
[project-path]
Expand Down
10 changes: 10 additions & 0 deletions src/sketchpad/buffer/grep.clj
@@ -0,0 +1,10 @@
(ns sketchpad.buffer.grep
(:require [clojure.java.shell :as shell]
[sketchpad.state.state :as state]))

(defn grep-files
"Grep the current projects or a given path."
([search-term]
(:out (apply shell/sh "grep" "-nir" "-I" search-term (keys @(:projects @state/app)))))
([search-term & opts]
(:out (apply shell/sh "grep" "-nir" "-I" search-term opts))))
10 changes: 5 additions & 5 deletions src/sketchpad/buffer/spell_check.clj
Expand Up @@ -2,13 +2,13 @@
(:require [sketchpad.config.config :as config])
(:import (org.fife.ui.rsyntaxtextarea.spell SpellingParser)))

(defonce dic-resource (clojure.java.io/resource "english_dic.zip"))
(defonce dic-resource (clojure.java.io/resource "english_dic.zip"))

(defonce english-dic-zip (clojure.java.io/file dic-resource))
(defonce english-dic-zip (clojure.java.io/file dic-resource))

(defonce english-spell-checker (SpellingParser/createEnglishSpellingParser english-dic-zip true))
(do
(config/apply-spell-checker-prefs! english-spell-checker))
(defonce english-spell-checker (SpellingParser/createEnglishSpellingParser english-dic-zip true))
(do
(config/apply-spell-checker-prefs! english-spell-checker))


(defn add-english-spell-checker
Expand Down
18 changes: 11 additions & 7 deletions src/sketchpad/buffer/token.clj
Expand Up @@ -27,7 +27,7 @@
([] (line-token (tab/current-text-area)))
([text-area]
(let [list-from-line (token-list-for-line text-area)
token-list (atom [(.getLexeme list-from-line)])]
token-list (atom [])]
(loop [t list-from-line]
(when-not (nil? (.getNextToken t))
(swap! token-list (fn [tl] (conj tl (.getLexeme t))))
Expand All @@ -36,16 +36,20 @@

(defn- file-exists?
[possible-path]
(let [f (clojure.java.io/file possible-path)]
(.exists f)))
(if-not (nil? possible-path)
(let [f (clojure.java.io/file possible-path)]
(.exists f))
false))

(defn- is-number?
[possible-number]
(=
(type (load-string possible-number))
java.lang.Long))
(if-not (nil? possible-number)
(=
(type (load-string possible-number))
java.lang.Long)
false))

(defn- can-be-opened?
(defn can-be-opened?
[line-tokens]
(and
(file-exists? (first line-tokens))
Expand Down
1 change: 1 addition & 0 deletions src/sketchpad/config/config.clj
Expand Up @@ -498,6 +498,7 @@ You never have to change the opaque property yourself; it is always done for you
{:underline-color spell-checker-underline-color})

(def fuzzy-file-type-exclusions ["dll" "class" "Ds_Store" "jpeg" "png" "tiff" "psd" "swf" "so" "scx" "pdf" "svg" "jnilib" "dylib"])
(def fuzzy-file-type-inclusions [ "markdown" "md" "c" "java" "txt" "tex" "clj" "html" "xml" "js"])
(def fuzzy-buffer-pref-handlers
{:buffer-theme text-area-theme
:font font})
Expand Down
16 changes: 14 additions & 2 deletions src/sketchpad/editor/buffer.clj
Expand Up @@ -125,15 +125,27 @@
@proj)]
open-project-path))))

(defn- bring-buffer-to-front
[file-path]
(let [buffer (first (filter #(= (.getAbsolutePath (clojure.java.io/file file-path)) (.getAbsolutePath @(:file % ))) (vals (tab/current-buffers))))]
(tab/show-buffer buffer)
buffer))

(defn- buffer-already-open?
[file-path]
(not (nil? (some #(= (.getAbsolutePath (clojure.java.io/file file-path)) (.getAbsolutePath @(:file % ))) (vals (tab/current-buffers))))))

(defn open-buffer [file-path project-path]
(seesaw/invoke-later
(if (buffer-already-open? file-path)
(bring-buffer-to-front file-path)
(let [project (sketchpad.project/project-from-path project-path)
buffer (editor.build/project-buffer-tab project-path)]
(load-file-into-buffer project buffer file-path)
(init-buffer-tab-state buffer)
(sketchpad.project/add-buffer-to-project project-path buffer)
(sketchpad.project/add-buffer-to-app buffer)
(tab/show-buffer buffer))))
(tab/show-buffer buffer)
buffer)))

(defn blank-clj-buffer!
([] (blank-clj-buffer! nil))
Expand Down
2 changes: 1 addition & 1 deletion src/sketchpad/menu/file.clj
Expand Up @@ -37,7 +37,7 @@
"Open a file."
([]
(seesaw.core/invoke-later
(let [open-path (choose-file :filters [["Folders" #(.isDirectory %)]
(when-let [open-path (choose-file :filters [["Folders" #(.isDirectory %)]
(file-filter "All files" (constantly true))]
:success-fn (fn [fc file] (.getAbsolutePath file)))]
(editor.buffer/open-buffer open-path ".sketchpad-tmp")))))
Expand Down
19 changes: 9 additions & 10 deletions src/sketchpad/menu/source.clj
@@ -1,5 +1,4 @@
(ns sketchpad.menu.source
(:use [clojure.java.shell])
(:require [seesaw.core :as seesaw]
[seesaw.keystroke :as keystroke]
[sketchpad.buffer.action :as buffer.action]
Expand All @@ -8,6 +7,7 @@
[sketchpad.repl.app.util :as app.util]
[sketchpad.repl.project-repl :as project-repl]
[sketchpad.help.help :as help]
[sketchpad.buffer.grep :as buffer.grep]
[sketchpad.tree.utils :as tree.utils]
[sketchpad.buffer.token :as token]
[sketchpad.buffer.spell-check :as spell-check]
Expand Down Expand Up @@ -61,19 +61,18 @@
(spell-check/remove-english-spell-checker text-area)
(.repaint text-area)))

(defn grep-files
"Grep the current projects or a given path."
([search-term]
(:out (apply sh "grep" "-nir" "-I" search-term (keys @(:projects @state/app)))))
([search-term & opts]
(:out (apply sh "grep" "-nir" "-I" search-term opts))))
(defonce last-grep-cmd (atom ""))

(defn append-function-string
[s curosor-offset]
(sketchpad.repl.print/append-command s curosor-offset)
(toggle-repl-if-needed)
(tab/focus-application-repl))

(defn grep-cmd
"Focus the editor REPL and create a search function."
([]
(sketchpad.repl.print/append-command (str "(grep \"\")") -2)
(toggle-repl-if-needed)
(tab/focus-application-repl)))
(append-function-string (str "(grep \"\")") -2)))

(defn increase-font-size
"Increase the curren buffer font size."
Expand Down
36 changes: 30 additions & 6 deletions src/sketchpad/repl/app/repl.clj
Expand Up @@ -22,11 +22,15 @@
[clojure.java.io :as io]
[sketchpad.project.project :as sketchpad.project]
[sketchpad.config.config :as config]
[sketchpad.editor.buffer :as buffer]
[sketchpad.buffer.search :as search]
[sketchpad.buffer.grep :as buffer.grep]
[sketchpad.buffer.action :as buffer.action]
[sketchpad.editor.ui :as editor.ui]
[sketchpad.wrapper.rtextscrollpane :as sp]
[sketchpad.wrapper.rsyntaxtextarea :as wrapper.rsyntaxtextarea]
[sketchpad.state.state :as state]
[sketchpad.buffer.token :as token]
[sketchpad.auto-complete.auto-complete :as auto-complete]
[sketchpad.input.default :as input.default]
[clojure.tools.nrepl :as repl]
Expand Down Expand Up @@ -173,11 +177,30 @@
(let [num-tabs (tab-count repl-tabbed-panel)]
(when (> 0 num-tabs)
(swap! state/app assoc :doc-title-atom (current-repl)))))))
;
; (defn- repl-double-click-handler
; [text-area e]
; (println (token/accum-token-list
; (


(defn- double-click?
[e]
(= (.getClickCount e) 2))

(defn repl-double-click-handler
[text-area e]
(when (double-click? e)
(let [line-str (apply str (token/line-token text-area))
line-seq (clojure.string/split line-str #"\:")]
(when (token/can-be-opened? line-seq)
(invoke-later
(let [buffer (buffer/open-buffer (first line-seq) ".sketchpad-tmp")]
(search/search (get-in buffer [:component :text-area]) (last line-seq))
(let [selection-end (.getSelectionEnd text-area)]
(doto text-area
(.setSelectionStart selection-end)
(.setSelectionEnd selection-end)))))))))

(defn attach-repl-mouse-click-handler
[repl]
(let [text-area (get-in repl [:component :text-area])]
(listen text-area :mouse-clicked (partial repl-double-click-handler text-area))))

(defn init-repl-tabbed-panel [repl-tabbed-panel repl]
(let [text-area (get-in repl [:component :text-area])
Expand All @@ -191,7 +214,7 @@
(config! scroller :background config/app-color)
(auto-complete/install-auto-completion repl)
(config/apply-repl-prefs! text-area)
(send-to-application-repl text-area "(require 'sketchpad.user)\n(in-ns 'sketchpad.user)")))
(send-to-application-repl text-area "(require 'sketchpad.user)\n\t\t(in-ns 'sketchpad.user)")))

(defn repl-tabbed-panel
[]
Expand All @@ -202,6 +225,7 @@
application-repl (repl.app.component/application-repl-component)]
(init-repl-tabbed-panel repl-tabbed-panel application-repl)
(attach-tab-change-handler repl-tabbed-panel)
(attach-repl-mouse-click-handler application-repl)
(swap! state/app conj (gen-map
repl-tabbed-panel
application-repl))
Expand Down
34 changes: 17 additions & 17 deletions src/sketchpad/user.clj
Expand Up @@ -2,28 +2,28 @@
(:refer-clojure :exclude [find replace])
(:use [seesaw meta dev]
[seesaw.core :exclude [height width]]
[clojure.repl]
[clojure.java.shell]
[sketchpad.config.config]
[clojure.repl]
[clojure.java.shell]
[sketchpad.config.config]
[sketchpad.tree.tree]
[sketchpad.buffer.action]
[sketchpad.util.brackets]
[sketchpad.buffer.token]
[sketchpad.system.desktop]
[sketchpad.auto-complete.template])
[sketchpad.auto-complete.template])
(:require [sketchpad.util.tab :as tab]
[sketchpad.wrapper.rsyntaxtextarea :as rsta]
[sketchpad.core :as core]
[sketchpad.wrapper.gutter :as gutter]
[sketchpad.menu.source :as source]
[sketchpad.wrapper.rsyntaxtextarea :as rsta]
[sketchpad.core :as core]
[sketchpad.wrapper.gutter :as gutter]
[sketchpad.buffer.search :as search]
[sketchpad.project.project :as project]
[sketchpad.tree.utils :as tree.utils]
[sketchpad.project.form :as project.form]
[clojure.pprint :as pprint]
[clojure.stacktrace :as stack-trace]
[seesaw.dev :as seesaw.dev]
[clojure.java.io :as io]
[sketchpad.project.project :as project]
[sketchpad.tree.utils :as tree.utils]
[sketchpad.project.form :as project.form]
[clojure.pprint :as pprint]
[clojure.stacktrace :as stack-trace]
[seesaw.dev :as seesaw.dev]
[clojure.java.io :as io]
[sketchpad.buffer.grep :as buffer.grep]
[clojure.string :as string])
(:import (org.fife.ui.rsyntaxtextarea RSyntaxTextAreaEditorKit)
(org.fife.ui.rtextarea RTextAreaEditorKit)
Expand Down Expand Up @@ -366,8 +366,8 @@

(defn grep
"Grep the current projects or a given the given paths."
([search-term] (source/grep-files search-term))
([search-term & args] (source/grep-files search-term args)))
([search-term] (buffer.grep/grep-files search-term))
([search-term & args] (buffer.grep/grep-files search-term args)))


(defn app-repl
Expand Down

0 comments on commit 3f1877a

Please sign in to comment.