Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add double click grep results to load buffer

  • Loading branch information...
commit 3f1877a46f9929d97f58a6ead137428812b64249 1 parent 98e5782
@ghostandthemachine authored
View
1  build.xml
@@ -23,6 +23,7 @@
<resourcefileset dir="resources">
<include name="default.clj" />
<include name="themes/*" />
+ <include name="english_dic.zip" />
</resourcefileset>
</jarbundler>
</target>
View
2  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"]
View
33 src/sketchpad/auto_complete/auto_complete.clj
@@ -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)))))
@@ -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]
View
10 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))))
View
10 src/sketchpad/buffer/spell_check.clj
@@ -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
View
18 src/sketchpad/buffer/token.clj
@@ -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))))
@@ -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))
View
1  src/sketchpad/config/config.clj
@@ -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})
View
16 src/sketchpad/editor/buffer.clj
@@ -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))
View
2  src/sketchpad/menu/file.clj
@@ -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")))))
View
19 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]
@@ -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]
@@ -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."
View
36 src/sketchpad/repl/app/repl.clj
@@ -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]
@@ -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])
@@ -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
[]
@@ -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))
View
34 src/sketchpad/user.clj
@@ -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)
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.