Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 07, 2012
Gunnar Völkel Implemented REPL history search for text before cursor.
Stepping through and searching REPL history share the same implementation.
0fe0296
Gunnar Völkel Added command, handler, keys for REPL history search. e46cdbb
View
5 ccw.core/plugin.properties
@@ -82,7 +82,10 @@ ccw.ui.repl.history.previous.name=Load previous command from REPL's history into
ccw.ui.repl.history.previous.description=Load previous command from REPL's history into REPL input area
ccw.ui.repl.history.next.name=Load next command from REPL's history into REPL input area
ccw.ui.repl.history.next.description=Load next command from REPL's history into REPL input area
-
+ccw.ui.repl.history.search.previous.name=Load previous command starting with the text before the cursor from REPL's history into REPL input area
+ccw.ui.repl.history.search.previous.description=Load previous command starting with the text before the cursor from REPL's history into REPL input area
+ccw.ui.repl.history.search.next.name=Load next command starting with the text before the cursor from REPL's history into REPL input area
+ccw.ui.repl.history.search.next.description=Load next command starting with the text before the cursor from REPL's history into REPL input area
preferencePage.clojure.name=Clojure
preferencePage.general.name=General
View
130 ccw.core/plugin.xml
@@ -465,6 +465,18 @@
</command>
<command
categoryId="org.eclipse.ui.category.edit"
+ description="%ccw.ui.repl.history.search.previous.description"
+ id="ccw.ui.repl.history.search.previous"
+ name="%ccw.ui.repl.history.search.previous.name">
+ </command>
+ <command
+ categoryId="org.eclipse.ui.category.edit"
+ description="%ccw.ui.repl.history.search.next.description"
+ id="ccw.ui.repl.history.search.next"
+ name="%ccw.ui.repl.history.search.next.name">
+ </command>
+ <command
+ categoryId="org.eclipse.ui.category.edit"
description="%ccw.ui.edit.text.clojure.comment.toggle.description"
id="ccw.ui.edit.text.clojure.comment.toggle"
name="%ccw.ui.edit.text.clojure.comment.toggle.name">
@@ -837,6 +849,27 @@
sequence="M4+P">
</key>
<key
+ commandId="ccw.ui.repl.history.search.previous"
+ contextId="ccw.ui.context.repl"
+ platform="win32"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+ARROW_RIGHT">
+ </key>
+ <key
+ commandId="ccw.ui.repl.history.search.previous"
+ contextId="ccw.ui.context.repl"
+ platform="gtk"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+ARROW_RIGHT">
+ </key>
+ <key
+ commandId="ccw.ui.repl.history.search.previous"
+ contextId="ccw.ui.context.repl"
+ platform="carbon"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M4+ARROW_RIGHT">
+ </key>
+ <key
commandId="ccw.ui.repl.history.next"
contextId="ccw.ui.context.repl"
platform="win32"
@@ -865,6 +898,27 @@
sequence="M4+N">
</key>
<key
+ commandId="ccw.ui.repl.history.search.next"
+ contextId="ccw.ui.context.repl"
+ platform="win32"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+ARROW_LEFT">
+ </key>
+ <key
+ commandId="ccw.ui.repl.history.search.next"
+ contextId="ccw.ui.context.repl"
+ platform="gtk"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+ARROW_LEFT">
+ </key>
+ <key
+ commandId="ccw.ui.repl.history.search.next"
+ contextId="ccw.ui.context.repl"
+ platform="carbon"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M4+ARROW_LEFT">
+ </key>
+ <key
commandId="ccw.ui.edit.text.clojure.comment.toggle"
contextId="ccw.ui.clojureEditorScope"
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
@@ -2278,6 +2332,82 @@
</activeWhen>
</handler>
<handler
+ commandId="ccw.ui.repl.history.search.previous">
+ <class
+ class="ccw.util.GenericExecutableExtension">
+ <parameter
+ name="factory"
+ value="ccw.util.factories/handler-factory">
+ </parameter>
+ <parameter
+ name="handler"
+ value="ccw.repl.view-helpers/history-backward-search">
+ </parameter>
+ </class>
+ <enabledWhen>
+ <with
+ variable="activeContexts">
+ <iterate
+ ifEmpty="false"
+ operator="or">
+ <equals
+ value="ccw.ui.context.repl">
+ </equals>
+ </iterate>
+ </with>
+ </enabledWhen>
+ <activeWhen>
+ <with
+ variable="activeContexts">
+ <iterate
+ ifEmpty="false"
+ operator="or">
+ <equals
+ value="ccw.ui.context.repl">
+ </equals>
+ </iterate>
+ </with>
+ </activeWhen>
+ </handler>
+ <handler
+ commandId="ccw.ui.repl.history.search.next">
+ <class
+ class="ccw.util.GenericExecutableExtension">
+ <parameter
+ name="factory"
+ value="ccw.util.factories/handler-factory">
+ </parameter>
+ <parameter
+ name="handler"
+ value="ccw.repl.view-helpers/history-forward-search">
+ </parameter>
+ </class>
+ <enabledWhen>
+ <with
+ variable="activeContexts">
+ <iterate
+ ifEmpty="false"
+ operator="or">
+ <equals
+ value="ccw.ui.context.repl">
+ </equals>
+ </iterate>
+ </with>
+ </enabledWhen>
+ <activeWhen>
+ <with
+ variable="activeContexts">
+ <iterate
+ ifEmpty="false"
+ operator="or">
+ <equals
+ value="ccw.ui.context.repl">
+ </equals>
+ </iterate>
+ </with>
+ </activeWhen>
+ </handler>
+ <handler
commandId="ccw.ui.edit.text.clojure.comment.toggle">
<class
class="ccw.util.GenericExecutableExtension">
View
99 ccw.core/src/clj/ccw/repl/view_helpers.clj
@@ -111,6 +111,59 @@
(CCWPlugin/logError (eval-failure-msg nil expr) t)
(log repl-view log-component (eval-failure-msg nil expr) :err))))
+
+(defn next-history-entry
+ [history position retained-input backward? filter-pred cursor-split-text]
+ (let [cnt (count history),
+ ; -1 <= position < count
+ position (if (< position -1) -1 position),
+ position (if (>= position cnt) (dec cnt) position),
+ entries (if backward?
+ ; seq of history entries backward from current position
+ (map vector
+ (range (inc position) cnt)
+ (rseq (if (= position -1)
+ history
+ (subvec history 0 (dec (- (count history) position))))))
+ ; seq of history entries forward from current position with retained input as last
+ (when-not (neg? position)
+ (concat
+ (map vector (range (dec position) -1 -1) (subvec history (- (count history) position)))
+ [[-1 retained-input]])))]
+ (first (filter #(filter-pred cursor-split-text (second %)) entries))))
+
+
+(defn get-text-split-by-cursor
+ [^StyledText input-widget]
+ (let [cursor-pos (.getCaretOffset input-widget)
+ length (.getCharCount input-widget)]
+ (cond
+ (zero? length)
+ nil
+ (zero? cursor-pos)
+ [nil (.getText input-widget)]
+ (= cursor-pos length)
+ [(.getText input-widget) nil]
+ :else
+ [(.getText input-widget 0 (dec cursor-pos)) (.getText input-widget cursor-pos (dec length))])))
+
+(defn search-history
+ [history history-position ^StyledText input-widget retained-input backward? modify-cursor filter-pred]
+ (when-not @retained-input
+ (reset! retained-input (.getText input-widget)))
+ (if-let [[next-position, entry] (next-history-entry @history @history-position @retained-input
+ backward? filter-pred (get-text-split-by-cursor input-widget))]
+ (do
+ (reset! history-position next-position)
+ (when (= @retained-input entry)
+ (reset! retained-input nil))
+ (let [cursor-pos (.getCaretOffset input-widget)]
+ (doto input-widget
+ (.setText entry)
+ (modify-cursor cursor-pos))))
+ (beep)))
+
+
(defn configure-repl-view
[repl-view log-panel repl-client session-id]
(let [[history retain-expr-fn] (history/get-history (-?> repl-view
@@ -120,28 +173,11 @@
; a bunch of atoms are just fine, since access to them is already
; serialized via the SWT event thread
history (atom history)
- current-step (atom -1)
+ history-position (atom -1)
retained-input (atom nil)
- history-action-fn
- (fn [history-shift]
- (swap! current-step history-shift)
- (cond
- (>= @current-step (count @history)) (do (swap! current-step dec) (beep))
- (neg? @current-step) (do (reset! current-step -1)
- (when @retained-input
- (doto input-widget
- (.setText @retained-input)
- cursor-at-end)
- (reset! retained-input nil)))
- :else (do
- (when-not @retained-input
- (reset! retained-input (.getText input-widget)))
- (doto input-widget
- (.setText (@history (dec (- (count @history) @current-step))))
- cursor-at-end))))
session-client (repl/client-session repl-client :session session-id)
responses-promise (promise)]
- (.setHistoryActionFn repl-view history-action-fn)
+ (.setHistoryActionFn repl-view (partial search-history history history-position input-widget retained-input))
;; TODO need to make client-session accept a single arg to avoid
;; dummy message sends
@@ -150,7 +186,7 @@
(comp (partial eval-expression repl-view log-panel session-client)
(fn [expr add-to-log?]
(reset! retained-input nil)
- (reset! current-step -1)
+ (reset! history-position -1)
(when add-to-log?
(swap! history #(subvec
; don't add duplicate expressions to the history
@@ -161,9 +197,24 @@
(retain-expr-fn expr))
expr))))
-(defn- load-history [event history-shift]
+(defn- load-history [event backward? modify-cursor filter-pred]
(let [repl-view (HandlerUtil/getActivePartChecked event)]
- ((.getHistoryActionFn repl-view) history-shift)))
+ ((.getHistoryActionFn repl-view) backward? modify-cursor filter-pred)))
+
+
+(defn move-cursor-to-end [input-widget _] (cursor-at-end input-widget))
+
+(defn restore-cursor [^StyledText input-widget prev-cursor-pos] (.setCaretOffset input-widget prev-cursor-pos))
+
+
+(defn history-previous [_ event] (load-history event true move-cursor-to-end (constantly true)))
+(defn history-next [_ event] (load-history event false move-cursor-to-end (constantly true)))
+
+
+(defn text-begin-matches?
+ [[text-begin] ^String history-entry]
+ (when text-begin
+ (.startsWith history-entry text-begin)))
-(defn history-previous [_ event] (load-history event inc))
-(defn history-next [_ event] (load-history event dec))
+(defn history-backward-search [_ event] (load-history event true restore-cursor text-begin-matches?))
+(defn history-forward-search [_ event] (load-history event false restore-cursor text-begin-matches?))

No commit comments for this range

Something went wrong with that request. Please try again.