From 0c8c16c0011b163a32903713c1aeb78933e0ab3f Mon Sep 17 00:00:00 2001 From: Noah Bogart <noah.bogart@hey.com> Date: Fri, 26 Apr 2024 17:16:32 -0400 Subject: [PATCH 1/3] (fix) Fix or silence all existing clj-kondo errors --- .clj-kondo/config.edn | 5 ++ src/clooj/brackets.clj | 2 +- src/clooj/core.clj | 135 +++++++++++++++++++------------------- src/clooj/help.clj | 9 ++- src/clooj/indent.clj | 34 +++++----- src/clooj/repl/main.clj | 5 +- src/clooj/repl/remote.clj | 13 ++-- src/clooj/search.clj | 2 +- src/clooj/settings.clj | 118 +++++++++++++++------------------ src/clooj/utils.clj | 82 +++++++++++------------ 10 files changed, 200 insertions(+), 205 deletions(-) create mode 100644 .clj-kondo/config.edn diff --git a/.clj-kondo/config.edn b/.clj-kondo/config.edn new file mode 100644 index 0000000..8bc6951 --- /dev/null +++ b/.clj-kondo/config.edn @@ -0,0 +1,5 @@ +{:linters {:unused-binding {:level :off} + :unused-import {:level :off} + :unused-namespace {:level :off}} + :lint-as {clooj.utils/when-lets clojure.core/let} + :output {:linter-name true}} diff --git a/src/clooj/brackets.clj b/src/clooj/brackets.clj index 102702f..dee7597 100644 --- a/src/clooj/brackets.clj +++ b/src/clooj/brackets.clj @@ -47,7 +47,7 @@ (loop [t text pos 0 stack nil errs nil] (let [c (first t) ;this char new-stack (process-bracket-stack stack c pos) - e (if (mismatched-brackets (ffirst stack) c) + e (when (mismatched-brackets (ffirst stack) c) (list (first stack) [c pos])) new-errs (if e (concat errs e) errs)] (if (next t) diff --git a/src/clooj/core.clj b/src/clooj/core.clj index 81f9a45..9f990ce 100644 --- a/src/clooj/core.clj +++ b/src/clooj/core.clj @@ -16,8 +16,8 @@ (javax.swing.tree DefaultMutableTreeNode DefaultTreeModel TreePath TreeSelectionModel) (java.awt Insets Rectangle Window) - (java.awt.event AWTEventListener FocusAdapter - MouseAdapter WindowAdapter + (java.awt.event AWTEventListener FocusAdapter + MouseAdapter WindowAdapter ActionListener KeyAdapter) (java.awt AWTEvent Color Font GridLayout Toolkit) (java.net URL) @@ -26,7 +26,7 @@ (java.io File FileReader StringReader BufferedWriter OutputStreamWriter FileOutputStream) (org.fife.ui.rsyntaxtextarea RSyntaxTextArea SyntaxConstants - TokenMakerFactory) + TokenMakerFactory) (org.fife.ui.rtextarea RTextScrollPane)) (:require [clojure.set] [clooj.repl.main :as repl] @@ -55,7 +55,7 @@ (extend-type RSyntaxTextArea DynamicWordHighlighter (addWordToHighlight [word token-type])) - + (defn make-rsyntax-text-area [] (let [tmf (TokenMakerFactory/getDefaultInstance) token-maker (.getTokenMaker tmf "text/clojure") @@ -67,7 +67,7 @@ token-type)))] (.. rsta getDocument (setTokenMakerFactory tmf)) rsta)) - + (defn make-text-area [wrap] (doto (RSyntaxTextArea.) (.setAnimateBracketMatching false) @@ -90,8 +90,8 @@ ;; settings (def default-settings - (merge - (zipmap [:font-name :font-size] + (merge + (zipmap [:font-name :font-size] (cond (utils/is-mac) ["Monaco" 11] (utils/is-win) ["Courier New" 12] :else ["Monospaced" 12])) @@ -107,39 +107,37 @@ (utils/read-value-from-prefs utils/clooj-prefs "settings")))) (defn save-settings [settings] - (utils/write-value-to-prefs - utils/clooj-prefs + (utils/write-value-to-prefs + utils/clooj-prefs "settings" settings)) (defn apply-settings [app settings] - - (defn set-line-wrapping [text-area mode] - (.setLineWrap text-area mode)) - - (defn set-font - [app font-name size] - (let [f (Font. font-name Font/PLAIN size)] - (utils/awt-event - (dorun (map #(.setFont (app %) f) - [:doc-text-area :repl-in-text-area - :repl-out-text-area :arglist-label - :search-text-area :help-text-area - :completion-list]))))) - - (set-line-wrapping - (:doc-text-area app) - (:line-wrap-doc settings)) - (set-line-wrapping - (:repl-in-text-area app) - (:line-wrap-repl-in settings)) - (set-line-wrapping - (:repl-out-text-area app) - (:line-wrap-repl-out settings)) - - (set-font app - (:font-name settings) - (:font-size settings)) + (letfn [(set-line-wrapping [text-area mode] + (.setLineWrap text-area mode)) + (set-font + [app font-name size] + (let [f (Font. font-name Font/PLAIN size)] + (utils/awt-event + (dorun (map #(.setFont (app %) f) + [:doc-text-area :repl-in-text-area + :repl-out-text-area :arglist-label + :search-text-area :help-text-area + :completion-list])))))] + + (set-line-wrapping + (:doc-text-area app) + (:line-wrap-doc settings)) + (set-line-wrapping + (:repl-in-text-area app) + (:line-wrap-repl-in settings)) + (set-line-wrapping + (:repl-out-text-area app) + (:line-wrap-repl-out settings)) + + (set-font app + (:font-name settings) + (:font-size settings))) (reset! (:settings app) settings) (save-settings settings)) @@ -206,7 +204,7 @@ (highlighting/highlight-brackets text-comp good-enclosures bad-brackets))))) (catch Throwable t (utils/awt-event (.printStackTrace t)))))) (when ns - (send-off arglist-agent + (send-off arglist-agent (fn [old-pos] (try (let [pos (@caret-position text-comp)] @@ -215,7 +213,7 @@ (help/arglist-from-caret-pos app ns text pos)] (utils/awt-event (.setText (:arglist-label app) arglist-text))))) (catch Throwable t (utils/awt-event (.printStackTrace t))))))))) - + ;; highlighting (defn activate-caret-highlighter [app] @@ -245,7 +243,7 @@ ;; temp files (defn dump-temp-doc [app orig-f txt] - (try + (try (when orig-f (let [orig (.getAbsolutePath orig-f) f (.getAbsolutePath (project/get-temp-file orig-f))] @@ -268,7 +266,7 @@ (dump-temp-doc app f txt)) pos) (catch Throwable t (utils/awt-event (.printStackTrace t)))))))) - + (defn setup-temp-writer [app] (let [text-comp (:doc-text-area app)] (utils/add-text-change-listener text-comp @@ -283,7 +281,7 @@ last-dot (.lastIndexOf name ".") suffix (.substring name (inc last-dot))] suffix)) - + (defn text-file? [f] (not (some #{(file-suffix f)} ["jar" "class" "dll" "jpg" "png" "bmp"]))) @@ -310,7 +308,7 @@ (not= f @(app :file)) (text-file? f)) (restart-doc app f)))))))))) - + ;; build gui (defn make-scroll-pane [text-area] @@ -322,7 +320,7 @@ (doto (:search-close-button app) (.setVisible false) (.setBorder nil) - (.addActionListener + (.addActionListener (reify ActionListener (actionPerformed [_ _] (search/stop-find app))))) (let [sta (doto (app :search-text-area) @@ -343,7 +341,7 @@ (.addWindowListener f (proxy [WindowAdapter] [] (windowClosing [_] - (save-caret-position app) + (save-caret-position app) (System/exit 0)))))) (def no-project-txt @@ -358,20 +356,19 @@ (select the File > New menu), or b. open an existing file (click on it in the tree at left).") - + (def no-file-txt "To edit source code you need to either: <br> - 1. create a new file + 1. create a new file (select menu <b>File > New...</b>)<br> 2. edit an existing file by selecting one at left.</html>") -(defn move-caret-to-line [textarea] +(defn move-caret-to-line "Move caret to choosen line" - - (defn current-line [] - (inc (.getLineOfOffset textarea (.getCaretPosition textarea)))) - - (let [line-str (utils/ask-value "Line number:" "Go to Line") + [textarea] + (let [current-line (fn [] + (inc (.getLineOfOffset textarea (.getCaretPosition textarea)))) + line-str (utils/ask-value "Line number:" "Go to Line") line-num (Integer. (if (or (nil? line-str) (nil? (re-find #"\d+" line-str))) (current-line) @@ -396,13 +393,13 @@ (utils/attach-action-keys comp ["cmd1 EQUALS" #(grow-font app)] ["cmd1 shift EQUALS" #(grow-font app)] - ["cmd1 PLUS" #(grow-font app)] + ["cmd1 PLUS" #(grow-font app)] ["cmd2 MINUS" #(.toBack (:frame app))] ["cmd2 PLUS" #(.toFront (:frame app))] ["cmd2 EQUALS" #(.toFront (:frame app))] ["cmd1 shift O" #(open-project app)] ["cmd1 K"#(.setText (app :repl-out-text-area) "")])) - + (defn on-window-activation [win fun] (.addWindowListener win (proxy [WindowAdapter] [] @@ -587,7 +584,7 @@ (.read text-area rdr nil)) (.discardAllEdits text-area) (.setText doc-label (str "Source Editor \u2014 " (.getPath file))) - (.setEditable text-area true) + (.setEditable text-area true) (.setSyntaxEditingStyle text-area (let [file-name (.getName file-to-open)] (if (or (.endsWith file-name ".clj") @@ -597,7 +594,7 @@ (do (.setText text-area no-project-txt) (.setText doc-label (str "Source Editor (No file selected)")) (.setEditable text-area false))) - + (indent/setup-autoindent text-area) (reset! (app :file) file) (load-caret-position app) @@ -628,7 +625,7 @@ :description \"FIXME: write description\" :dependencies [[org.clojure/clojure \"1.5.1\"]]) ")) - + (defn specify-source [project-dir title default-namespace] (when-let [namespace (JOptionPane/showInputDialog nil "Please enter a fully-qualified namespace" @@ -644,7 +641,7 @@ the-dir (File. project-dir dirstring)] (.mkdirs the-dir) [(File. the-dir (str name ".clj")) namespace]))) - + (defn create-file [app project-dir default-namespace] (when-let [[file namespace] (specify-source project-dir "Create a source file" @@ -674,7 +671,7 @@ "Unable to create project." "Oops" JOptionPane/ERROR_MESSAGE) (.printStackTrace e))))) - + (defn rename-file [app] (when-let [old-file @(app :file)] (let [tree (app :docs-tree) @@ -707,20 +704,20 @@ (defn revert-file [app] (when-let [f @(:file app)] (let [temp-file (project/get-temp-file f)] - (when (.exists temp-file)) + (when (.exists temp-file) (let [path (.getAbsolutePath f)] (when (utils/confirmed? "Revert the file? This cannot be undone." path) (.delete temp-file) (project/update-project-tree (:docs-tree app)) - (restart-doc app f)))))) + (restart-doc app f))))))) (defn- dir-rank [dir] (get {"src" 0 "test" 1 "lib" 2} (.getName dir) 100)) (defn- find-file [project-path relative-file-path] (let [classpath-dirs (sort-by dir-rank < (utils/get-directories (File. project-path))) - file-candidates (map - #(File. (str (.getAbsolutePath %) File/separatorChar relative-file-path)) + file-candidates (map + #(File. (str (.getAbsolutePath %) File/separatorChar relative-file-path)) classpath-dirs)] (first (filter #(and (.exists %) (.isFile %)) file-candidates)))) @@ -728,9 +725,9 @@ (let [text-comp (:doc-text-area app) pos (.getCaretPosition text-comp) text (.getText text-comp) - src-file (:file (meta (do (help/token-from-caret-pos ns text pos) nil))) + src-file (:file (meta (do (help/token-from-caret-pos text pos) nil))) line (:line (meta (do (find-ns (symbol ns)) - (help/token-from-caret-pos ns text pos) nil))) + (help/token-from-caret-pos text pos) nil))) project-path (first (project/get-selected-projects app)) file (find-file project-path src-file)] (when (and file line) @@ -764,7 +761,7 @@ ["Indent lines" "I" "cmd1 CLOSE_BRACKET" #(utils/indent (:doc-text-area app))] ["Unindent lines" "D" "cmd1 OPEN_BRACKET" #(utils/unindent (:doc-text-area app))] ["Name search/docs" "S" "TAB" #(help/show-tab-help app (help/find-focused-text-pane app) inc)] - ["Go to line..." "G" "cmd1 L" #(move-caret-to-line (:doc-text-area app))] + ["Go to line..." "G" "cmd1 L" #(move-caret-to-line (:doc-text-area app))] ;["Go to definition" "G" "cmd1 D" #(goto-definition (repl/get-file-ns app) app)] ) (utils/add-menu menu-bar "REPL" "R" @@ -787,8 +784,8 @@ ["Decrease font size" nil "cmd1 MINUS" #(shrink-font app)] ["Settings" nil nil #(settings/show-settings-window app apply-settings)]))) - - + + (defn add-visibility-shortcut [app] (let [shortcuts [(map utils/get-keystroke ["cmd2 EQUALS" "cmd2 PLUS"])]] (.. Toolkit getDefaultToolkit @@ -818,7 +815,7 @@ (help/setup-tab-help (app :repl-in-text-area) app) (doall (map #(project/add-project app %) (project/load-project-set))) (let [frame (app :frame)] - (utils/persist-window-shape utils/clooj-prefs "main-window" frame) + (utils/persist-window-shape utils/clooj-prefs "main-window" frame) (utils/enable-mac-fullscreen frame) (.setVisible frame true) (on-window-activation frame #(project/update-project-tree (app :docs-tree)))) diff --git a/src/clooj/help.clj b/src/clooj/help.clj index f159565..dea4357 100644 --- a/src/clooj/help.clj +++ b/src/clooj/help.clj @@ -72,7 +72,7 @@ (defn get-var-maps [project-path classpath] (make-var-super-map - (mapcat vars/analyze-clojure-source + (mapcat #(vars/analyze-clojure-source "clj" %) (concat (get-sources-from-jars project-path classpath) (get-sources-from-clj-files classpath))))) @@ -256,7 +256,7 @@ others (match-items token-pat2 items) ;collaj-items (or (try (collaj/raw-data token) (catch Throwable _))) ] - (concat best others (comment collaj-items)))) + (concat best others #_collaj-items))) (defn show-completion-list [{:keys [completion-list repl-split-pane @@ -358,8 +358,7 @@ (utils/get-text-str text-comp) (.getCaretPosition text-comp)) len (- stop start)] - (when (and (not (empty? new-token)) (-> app :completion-list - .getModel .getSize pos?)) + (when (and (seq new-token) (-> app :completion-list .getModel .getSize pos?)) (.. text-comp getDocument (replace start len new-token nil)))))) @@ -397,4 +396,4 @@ (.ensureIndexIsVisible l (.getSelectedIndex l)) (show-help-text app (.getSelectedValue l)))))) (utils/on-click 2 #(when-let [text-pane (find-focused-text-pane app)] - (update-token app text-pane))))) + (update-token app text-pane (get-list-token app)))))) diff --git a/src/clooj/indent.clj b/src/clooj/indent.clj index 6aa6186..93a82f3 100644 --- a/src/clooj/indent.clj +++ b/src/clooj/indent.clj @@ -11,7 +11,7 @@ ;(defn t [] (@clooj.core/current-app :doc-text-area)) -(def special-tokens +(def special-tokens ["def" "defn" "defmacro" "let" "for" "loop" "doseq" "if" "when" "binding" "case" "definline" "defmacro" "condp" "when-let" "if-let" "fn" "proxy" "reify" "when-first" "defmethod" "defmulti" "defn-" "defprotocol" @@ -22,7 +22,7 @@ (defn first-token [txt] (second (re-find #"\((.+?)\s" txt))) - + (defn second-token-pos [txt] (when-let [x (re-find #".+?\s" (string/trimr (first (.split #"\r?\n" txt))))] (.length x))) @@ -46,26 +46,26 @@ (compute-indent-size text-comp bracket-pos) (+ col (condp = bracket - \( (left-paren-indent-size (.. text-comp getDocument (getText - bracket-pos - (- offset bracket-pos)))) + \( (left-paren-indent-size (.. text-comp getDocument + (getText bracket-pos + (- offset bracket-pos)))) \\ 0 \[ 1 \{ 1 \" 1 - 1))))))) ;" + 1))))))) (defn fix-indent [text-comp line] (let [start (.getLineStartOffset text-comp line) end (.getLineEndOffset text-comp line) document (.getDocument text-comp) - line-text (.getText document start (- end start))] - (let [old-indent-size (count (re-find #"\A\ +" line-text))] - (when-let [new-indent-size (compute-indent-size text-comp start)] - (let [delta (- new-indent-size old-indent-size)] - (if (pos? delta) - (.insertString document start (apply str (repeat delta " ")) nil) - (.remove document start (- delta)))))))) + line-text (.getText document start (- end start)) + old-indent-size (count (re-find #"\A\ +" line-text))] + (when-let [new-indent-size (compute-indent-size text-comp start)] + (let [delta (- new-indent-size old-indent-size)] + (if (pos? delta) + (.insertString document start (apply str (repeat delta " ")) nil) + (.remove document start (- delta))))))) (defn fix-indent-selected-lines [text-comp] - (utils/awt-event + (utils/awt-event (dorun (map #(fix-indent text-comp %) (utils/get-selected-lines text-comp))))) @@ -74,7 +74,7 @@ (apply str "\n" (repeat indent-size " ")))) (defn setup-autoindent [text-comp] - (utils/attach-action-keys text-comp + (utils/attach-action-keys text-comp ["cmd1 BACK_SLASH" #(fix-indent-selected-lines text-comp)] ; "cmd1 \" ["cmd1 CLOSE_BRACKET" #(utils/indent text-comp)] ; "cmd1 ]" ["cmd1 OPEN_BRACKET" #(utils/unindent text-comp)]) ; "cmd1 [" @@ -83,9 +83,9 @@ (proxy [DocumentFilter] [] (replace [fb offset len text attrs] (.replace - fb offset len + fb offset len (condp = text - "\n" (auto-indent-str text-comp offset) + "\n" (auto-indent-str text-comp offset) text) attrs)) (remove [fb offset len] diff --git a/src/clooj/repl/main.clj b/src/clooj/repl/main.clj index 96fa094..35c15ab 100644 --- a/src/clooj/repl/main.clj +++ b/src/clooj/repl/main.clj @@ -25,6 +25,7 @@ [clooj.protocols :as protocols] [clooj.utils :as utils])) +#_{:clj-kondo/ignore [:use]} (use 'clojure.java.javadoc) (def repl-history {:items (atom nil) :pos (atom 0)}) @@ -234,8 +235,8 @@ txt caret-pos))))) submit #(when-let [txt (.getText ta-in)] - (do (send-to-repl app txt false) - (.setText ta-in ""))) + (send-to-repl app txt false) + (.setText ta-in "")) at-top #(zero? (.getLineOfOffset ta-in (get-caret-pos))) at-bottom #(= (.getLineOfOffset ta-in (get-caret-pos)) (.getLineOfOffset ta-in (.. ta-in getText length))) diff --git a/src/clooj/repl/remote.clj b/src/clooj/repl/remote.clj index a6ac005..47b3279 100644 --- a/src/clooj/repl/remote.clj +++ b/src/clooj/repl/remote.clj @@ -4,7 +4,10 @@ ; arthuredelstein@gmail.com (ns clooj.repl.remote - (:import (java.io StringReader))) + (:import (java.io StringReader)) + (:require + [clojure.main :as m] + [clojure.pprint :as pp])) (def silence (atom false)) @@ -28,7 +31,7 @@ [(StringReader. (str "(do " text ")"))] (getLineNumber [] (+ -1 line (proxy-super getLineNumber)))))) - + (defn eval-code-at "Evaluate some text as code, as though it were located in a given file at a particular line number." @@ -40,7 +43,7 @@ "Starts a REPL (for nesting in a primitive REPL) that prints nicely and suppresses silent evaluations." [] - (clojure.main/repl + (m/repl :print (fn [x] (if @silence (do @@ -48,5 +51,5 @@ (println)) (if (var? x) (println x) - (clojure.pprint/pprint x)))) - :prompt #(do (clojure.main/repl-prompt) (.flush *out*)))) \ No newline at end of file + (pp/pprint x)))) + :prompt #(do (m/repl-prompt) (.flush *out*)))) diff --git a/src/clooj/search.clj b/src/clooj/search.clj index d3ab9fb..4592030 100644 --- a/src/clooj/search.clj +++ b/src/clooj/search.clj @@ -86,7 +86,7 @@ (.setVisible case-checkbox true) (.setVisible regex-checkbox true) (.setVisible close-button true) - (if (not (empty? sel-text)) + (when (seq sel-text) (.setText sta sel-text)))) (defn stop-find [app] diff --git a/src/clooj/settings.clj b/src/clooj/settings.clj index 38b8503..0de00f6 100644 --- a/src/clooj/settings.clj +++ b/src/clooj/settings.clj @@ -4,10 +4,10 @@ ; arthuredelstein@gmail.com (ns clooj.settings - (:import + (:import (javax.swing JFrame JTabbedPane JLabel JPanel JComboBox Box - JTextField JTextArea + JTextField JTextArea BoxLayout SpringLayout JButton JCheckBox) (java.awt Font GraphicsEnvironment Dimension) @@ -32,7 +32,7 @@ (.addDocumentListener (.getDocument tf) (reify DocumentListener - (insertUpdate [_ e] + (insertUpdate [_ e] (change-fun (.getText tf))) (removeUpdate [_ e] (change-fun (.getText tf))) @@ -44,90 +44,81 @@ (.addItemListener (reify ItemListener (itemStateChanged [_ e] - (change-fun - (= - (.getStateChange e) + (change-fun + (= + (.getStateChange e) ItemEvent/SELECTED))))))) (defn font-panel [] - - - (def graphics-object - (memoize (fn [] (.createGraphics - (BufferedImage. 1 1 BufferedImage/TYPE_INT_ARGB))))) - - (def monospaced? - (fn [font] - (let [g (graphics-object) - m (.getFontMetrics g font)] - (apply == (map #(.charWidth m %) [\m \n \. \M \-]))))) - - (defn get-all-font-names [] - (.. GraphicsEnvironment - getLocalGraphicsEnvironment - getAvailableFontFamilyNames)) - - (defn get-all-fonts-12 [] - (map #(Font. % Font/PLAIN 12) (get-all-font-names))) - - (defn get-monospaced-font-names [] - (map #(.getName %) (filter monospaced? (get-all-fonts-12)))) - - (defn get-necessary-fonts [] - (if (:show-only-monospaced-fonts @settings) - (get-monospaced-font-names) - (get-all-font-names))) - (let [example-text-area (doto (JTextArea. + (let [graphics-object (delay (.createGraphics + (BufferedImage. 1 1 BufferedImage/TYPE_INT_ARGB))) + monospaced? (fn [font] + (let [g @graphics-object + m (.getFontMetrics g font)] + (apply == (map #(.charWidth m %) [\m \n \. \M \-])))) + get-all-font-names (fn [] + (.. GraphicsEnvironment + getLocalGraphicsEnvironment + getAvailableFontFamilyNames)) + get-all-fonts-12 (fn [] + (map #(Font. % Font/PLAIN 12) (get-all-font-names))) + get-monospaced-font-names (fn [] + (map #(.getName %) (filter monospaced? (get-all-fonts-12)))) + get-necessary-fonts (fn [] + (if (:show-only-monospaced-fonts @settings) + (get-monospaced-font-names) + (get-all-font-names))) + example-text-area (doto (JTextArea. "abcdefghijklmnopqrstuvwxyz 0123456789 (){}[]\nABCDEFGHIJKLMNOPQRSTUVWXYZ +-*/= .,;:!? #&$%@|^") (.setFont (Font. (:font-name @settings) Font/PLAIN (:font-size @settings)))) - example-pane (doto (JPanel. (SpringLayout.)) + example-pane (doto (JPanel. (SpringLayout.)) (.add example-text-area)) font-box (combo-box (get-necessary-fonts) (:font-name @settings) - #(do + #(do (swap! settings assoc :font-name %) - (.setFont - example-text-area + (.setFont + example-text-area (Font. % Font/PLAIN (:font-size @settings))))) size-box (combo-box (range 5 49) (:font-size @settings) - #(do + #(do (swap! settings assoc :font-size %) - (.setFont - example-text-area + (.setFont + example-text-area (Font. (:font-name @settings) Font/PLAIN %)))) monospaced-check-box (check-box "Show only monospaced fonts" (:show-only-monospaced-fonts @settings) #(do - (swap! settings + (swap! settings assoc :show-only-monospaced-fonts %) - (doto font-box - (.setModel - (.getModel + (doto font-box + (.setModel + (.getModel (JComboBox. - (into-array + (into-array (get-necessary-fonts))))) (.setSelectedItem (:font-name @settings))))) controls-pane (JPanel.) font-pane (JPanel.)] (utils/constrain-to-parent example-text-area :n 20 :w 15 :s -15 :e -15) - + (doto controls-pane (.setLayout (BoxLayout. controls-pane BoxLayout/X_AXIS)) - (.add (Box/createRigidArea (Dimension. 20 0))) + (.add (Box/createRigidArea (Dimension. 20 0))) (.add (JLabel. "Font:")) - (.add (Box/createRigidArea (Dimension. 25 0))) + (.add (Box/createRigidArea (Dimension. 25 0))) (.add font-box) - (.add (Box/createRigidArea (Dimension. 25 0))) + (.add (Box/createRigidArea (Dimension. 25 0))) (.add (JLabel. "Size:")) - (.add (Box/createRigidArea (Dimension. 25 0))) + (.add (Box/createRigidArea (Dimension. 25 0))) (.add size-box) (.add (Box/createHorizontalGlue))) - + (doto font-pane (.setLayout (BoxLayout. font-pane BoxLayout/Y_AXIS)) (.add controls-pane) @@ -138,19 +129,19 @@ (let [options-pane (JPanel.)] (doto options-pane (.setLayout (BoxLayout. options-pane BoxLayout/Y_AXIS)) - (.add (check-box - "Wrap lines in source editor" + (.add (check-box + "Wrap lines in source editor" (:line-wrap-doc @settings) #(swap! settings assoc :line-wrap-doc %))) - (.add (check-box - "Wrap lines in repl output" + (.add (check-box + "Wrap lines in repl output" (:line-wrap-repl-out @settings) #(swap! settings assoc :line-wrap-repl-out %))) - (.add (check-box - "Wrap lines in repl input" + (.add (check-box + "Wrap lines in repl input" (:line-wrap-repl-in @settings) #(swap! settings assoc :line-wrap-repl-in %)))))) - + (defmacro tabs [& elements] `(doto (JTabbedPane.) ~@(map #(list '.addTab (first %) (second %)) elements))) @@ -161,7 +152,7 @@ y (+ (.y bounds) (/ (.height bounds) 2)) settings-frame (JFrame. "Settings") button-pane (JPanel.)] - + (doto button-pane (.setLayout (BoxLayout. button-pane BoxLayout/X_AXIS)) (.add (utils/create-button "OK" #(do @@ -169,7 +160,7 @@ (.dispose settings-frame)))) (.add (utils/create-button "Apply" #(apply-fn app @settings))) (.add (utils/create-button "Cancel" #(.dispose settings-frame)))) - + (doto settings-frame (.setDefaultCloseOperation JFrame/DISPOSE_ON_CLOSE) (.setLayout (BoxLayout. (.getContentPane settings-frame) BoxLayout/Y_AXIS)) @@ -180,9 +171,8 @@ ["Editor options" (editor-options-panel)])) (.add (Box/createRigidArea (Dimension. 0 25))) (.add button-pane)))) - - - + + (defn show-settings-window [app apply-fn] (reset! settings @(:settings app)) (.show (make-settings-window app apply-fn))) diff --git a/src/clooj/utils.clj b/src/clooj/utils.clj index 843d847..579310a 100644 --- a/src/clooj/utils.clj +++ b/src/clooj/utils.clj @@ -4,9 +4,8 @@ ; arthuredelstein@gmail.com (ns clooj.utils - (:require [clojure.string :as string :only (join split)]) - (:import (java.util UUID) - (java.awt FileDialog Point Window) + (:require [clojure.string :as string]) + (:import (java.awt FileDialog Point Window) (java.awt.event ActionListener MouseAdapter) (java.util.prefs Preferences) (java.security MessageDigest) @@ -14,8 +13,8 @@ File FilenameFilter BufferedReader InputStreamReader ObjectInputStream ObjectOutputStream - OutputStream Writer PrintStream) - (javax.swing AbstractAction JButton JFileChooser JMenu JMenuBar JMenuItem BorderFactory + OutputStream PrintStream) + (javax.swing AbstractAction JButton JFileChooser JMenu JMenuItem BorderFactory JOptionPane JSplitPane KeyStroke SpringLayout SwingUtilities) (javax.swing.event CaretListener DocumentListener UndoableEditListener) (javax.swing.undo UndoManager))) @@ -34,7 +33,7 @@ (assert (<= 2 n)) (if (= 2 n) `(when-let ~bindings ~@body) - (let [[a b] (map vec (split-at 2 bindings))] + (let [[a b] (map vec (split-at 2 bindings))] `(when-let ~a (when-lets ~b ~@body)))))) (defn count-while [pred coll] @@ -46,7 +45,7 @@ (defmacro awt-event [& body] `(SwingUtilities/invokeLater (fn [] (try ~@body - (catch Throwable t# + (catch Throwable t# (.printStackTrace t#)))))) (defmacro gen-map [& args] @@ -61,7 +60,7 @@ (catch Throwable _ nil))) ;; preferences - + ;; define a UUID for clooj preferences (def clooj-prefs (.. Preferences userRoot (node "clooj") (node "c6833c87-9631-44af-af83-f417028ea7aa"))) @@ -69,7 +68,7 @@ (defn partition-str [n s] (let [l (.length s)] (for [i (range 0 l n)] - (.substring s i (Math/min l (+ (int i) (int n))))))) + (.substring s i (Math/min l (+ (int i) (int n))))))) (def pref-max-bytes (* 3/4 Preferences/MAX_VALUE_LENGTH)) @@ -86,25 +85,25 @@ "Reads a pure clojure data structure from Preferences object." [prefs key] (when-not (.endsWith key "/") - (let [node (. prefs node key)] - (let [s (apply str - (for [i (range (count (. node keys)))] - (.get node (str i) nil)))] - (when (and s (pos? (.length s))) (read-string s)))))) + (let [node (.node prefs key) + s (apply str + (for [i (range (count (. node keys)))] + (.get node (str i) nil)))] + (when (and s (pos? (.length s))) (read-string s))))) (defn write-obj-to-prefs "Writes a java object to a Preferences object." [prefs key obj] (let [bos (ByteArrayOutputStream.) os (ObjectOutputStream. bos) - node (. prefs node key)] + node (.node prefs key)] (.writeObject os obj) (. node putByteArray "0" (.toByteArray bos)))) (defn read-obj-from-prefs "Reads a java object from a Preferences object." [prefs key] - (let [node (. prefs node key) + (let [node (.node prefs key) bis (ByteArrayInputStream. (. node getByteArray "0" nil)) os (ObjectInputStream. bis)] (.readObject os))) @@ -112,7 +111,7 @@ ;; identify OS (defn get-os [] - (.. System (getProperty "os.name") toLowerCase)) + (string/lower-case (.getProperty System "os.name"))) (def is-win (memoize #(not (neg? (.indexOf (get-os) "win"))))) @@ -132,7 +131,7 @@ :s SpringLayout/SOUTH :e SpringLayout/EAST}] (.. comp1 getParent getLayout - (putConstraint (edges edge1) comp1 + (putConstraint (edges edge1) comp1 dist (edges edge2) comp2)))) (defn put-constraints [comp & args] @@ -167,8 +166,9 @@ (defn get-caret-coords [text-comp] (get-coords text-comp (.getCaretPosition text-comp))) -(defn add-text-change-listener [text-comp f] +(defn add-text-change-listener "Executes f whenever text is changed in text component." + [text-comp f] (.addDocumentListener (.getDocument text-comp) (reify DocumentListener @@ -180,7 +180,7 @@ (let [d (.getDocument text-comp)] (doseq [l (.getDocumentListeners d)] (.removeDocumentListener d l)))) - + (defn get-text-str [text-comp] (let [doc (.getDocument text-comp)] (.getText doc 0 (.getLength doc)))) @@ -245,12 +245,12 @@ (remove-from-selected-row-headers text-comp ";")) (defn toggle-comment [text-comp] - (if (= (.getText (.getDocument text-comp) + (if (= (.getText (.getDocument text-comp) (first (get-selected-line-starts text-comp)) 1) ";") (uncomment-out text-comp) (comment-out text-comp))) - + (defn indent [text-comp] (when (.isFocusOwner text-comp) (insert-in-selected-row-headers text-comp " "))) @@ -262,7 +262,7 @@ ;; other gui (defn make-split-pane [comp1 comp2 horizontal divider-size resize-weight] - (doto (JSplitPane. (if horizontal JSplitPane/HORIZONTAL_SPLIT + (doto (JSplitPane. (if horizontal JSplitPane/HORIZONTAL_SPLIT JSplitPane/VERTICAL_SPLIT) true comp1 comp2) (.setResizeWeight resize-weight) @@ -289,7 +289,7 @@ (let [im (.getInputMap component) am (.getActionMap component) input-event (get-keystroke input-key) - parent-action (if-let [tag (.get im input-event)] + parent-action (when-let [tag (.get im input-event)] (.get am tag)) child-action (proxy [AbstractAction] [] @@ -298,13 +298,13 @@ (action-fn) (when parent-action (.actionPerformed parent-action e))))) - uuid (.. UUID randomUUID toString)] + uuid (str (random-uuid))] (.put im input-event uuid) (.put am uuid child-action))) (defn attach-child-action-keys [comp & items] - (doall (map #(apply attach-child-action-key comp %) items))) + (run! #(apply attach-child-action-key comp %) items)) (defn attach-action-key "Maps an input-key on a swing component to an action-fn." @@ -315,10 +315,10 @@ (defn attach-action-keys "Maps input keys to action-fns." [comp & items] - (doall (map #(apply attach-action-key comp %) items))) - + (run! #(apply attach-action-key comp %) items)) + ;; buttons - + (defn create-button [text fn] (doto (JButton. text) (.addActionListener @@ -329,7 +329,7 @@ (defn add-menu-item ([menu item-name key-mnemonic key-accelerator response-fn] - (let [menu-item (JMenuItem. item-name)] + (let [menu-item (JMenuItem. item-name)] (when key-accelerator (.setAccelerator menu-item (get-keystroke key-accelerator))) (when (and (not (is-mac)) key-mnemonic) @@ -342,7 +342,7 @@ ([menu item] (condp = item :sep (.addSeparator menu)))) - + (defn add-menu "Each item-tuple is a vector containing a menu item's text, mnemonic key, accelerator key, and the function @@ -351,7 +351,7 @@ (let [menu (JMenu. title)] (when (and (not (is-mac)) key-mnemonic) (.setMnemonic menu (.getKeyCode (get-keystroke key-mnemonic)))) - (doall (map #(apply add-menu-item menu %) item-tuples)) + (run! #(apply add-menu-item menu %) item-tuples) (.add menu-bar menu) menu)) @@ -374,8 +374,8 @@ (reify UndoableEditListener (undoableEditHappened [this evt] (.addEdit undoMgr (.getEdit evt)))))) (attach-action-keys text-area - ["cmd1 Z" #(if (.canUndo undoMgr) (.undo undoMgr))] - ["cmd1 shift Z" #(if (.canRedo undoMgr) (.redo undoMgr))]))) + ["cmd1 Z" #(when (.canUndo undoMgr) (.undo undoMgr))] + ["cmd1 shift Z" #(when (.canRedo undoMgr) (.redo undoMgr))]))) ;; file handling @@ -390,7 +390,7 @@ (.setVisible true)) d (.getDirectory dialog) n (.getFile dialog)] - (if (and d n) + (when (and d n) (File. d n)))) ;doesn't work with Java 7 -- see version below @@ -416,10 +416,10 @@ (doto fc (.setFileSelectionMode JFileChooser/DIRECTORIES_ONLY) (.setDialogTitle title) (.setCurrentDirectory (if last-open-dir (File. last-open-dir) nil))) - (if (= JFileChooser/APPROVE_OPTION (.showOpenDialog fc parent)) + (when (= JFileChooser/APPROVE_OPTION (.showOpenDialog fc parent)) (.getSelectedFile fc)))) - + (defn get-directories [path] (filter #(and (.isDirectory %) (not (.startsWith (.getName %) "."))) @@ -485,7 +485,7 @@ (try (set-shape components (read-value-from-prefs prefs name)) (catch Exception e))) - + (defn confirmed? [question title] (= JOptionPane/YES_OPTION (JOptionPane/showConfirmDialog @@ -507,11 +507,11 @@ shape)))))) (defn sha1-str [obj] - (let [bytes (.getBytes (with-out-str (pr obj)))] + (let [bytes (.getBytes (with-out-str (pr obj)))] (String. (.digest (MessageDigest/getInstance "MD") bytes)))) ;; streams, writers and readers - + (defn printstream-to-writer [writer] (-> (proxy [OutputStream] [] @@ -537,7 +537,7 @@ (defn copy-input-stream-to-writer "Continuously copies all content from a java InputStream to a java Writer. Blocks until InputStream closes." - [input-stream writer] + [input-stream writer] (let [reader (InputStreamReader. input-stream)] (loop [] (let [c (.read reader)] From d517b631abdb8bb773dfb0e307a5f60d0803daae Mon Sep 17 00:00:00 2001 From: Noah Bogart <noah.bogart@hey.com> Date: Sat, 27 Apr 2024 19:54:21 -0400 Subject: [PATCH 2/3] Remove all trailing whitespace --- src/clooj/cemerick/pomegranate.clj | 2 +- src/clooj/collaj.clj | 2 +- src/clooj/help.clj | 14 +++++++------- src/clooj/highlighting.clj | 2 +- src/clooj/navigate.clj | 4 ++-- src/clooj/project.clj | 20 ++++++++++---------- src/clooj/repl/external.clj | 12 ++++++------ src/clooj/repl/lein.clj | 2 +- src/clooj/repl/main.clj | 12 ++++++------ src/clooj/repl/output.clj | 6 +++--- 10 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/clooj/cemerick/pomegranate.clj b/src/clooj/cemerick/pomegranate.clj index a9a5cbf..e21df30 100644 --- a/src/clooj/cemerick/pomegranate.clj +++ b/src/clooj/cemerick/pomegranate.clj @@ -45,7 +45,7 @@ unless you are extending a type to this protocol." [sym & body] (when (resolve sym) `(do ~@body))) -(when-resolves sun.misc.Launcher +(when-resolves sun.misc.Launcher (extend sun.misc.Launcher$ExtClassLoader URLClasspath (assoc url-classloader-base :can-modify? (constantly false)))) diff --git a/src/clooj/collaj.clj b/src/clooj/collaj.clj index 0e1f9d7..701cdac 100644 --- a/src/clooj/collaj.clj +++ b/src/clooj/collaj.clj @@ -11,7 +11,7 @@ "URL-encode a string." [s] (URLEncoder/encode s "UTF-8")) - + (defn raw-data "Get a clojure data collection of raw search results from collaj.net" diff --git a/src/clooj/help.clj b/src/clooj/help.clj index dea4357..ea5774f 100644 --- a/src/clooj/help.clj +++ b/src/clooj/help.clj @@ -226,7 +226,7 @@ (defn item-help [item] (cond (map? item) (var-help item) - (class? item) (class-help item))) + (class? item) (class-help item))) (defn set-first-component [split-pane comp] (let [loc (.getDividerLocation split-pane)] @@ -286,13 +286,13 @@ (.getSelectedIndex help-list)) n)))))) (show-completion-list app)) - + (defn get-list-item [app] (-> app :completion-list .getSelectedValue)) (defn get-list-artifact [app] (when-let [artifact (:artifact (get-list-item app))] - (binding [*read-eval* false] + (binding [*read-eval* false] (read-string artifact)))) (defn get-list-token [app] @@ -323,11 +323,11 @@ (app :docs-tree-panel)) (.setText (app :repl-label) "Clojure REPL output")) (swap! help-state assoc :visible false :pos nil))) - + (defn help-handle-caret-move [app text-comp] (utils/awt-event (when (@help-state :visible) - (let [[start _] (local-token-location (utils/get-text-str text-comp) + (let [[start _] (local-token-location (utils/get-text-str text-comp) (.getCaretPosition text-comp))] (if-not (= start (@help-state :pos)) (hide-tab-help app) @@ -351,7 +351,7 @@ (add-classpath-to-repl app (aether/dependency-files deps))) (utils/append-text (app :repl-out-text-area) (str "done."))) - + (defn update-token [app text-comp new-token] (utils/awt-event (let [[start stop] (local-token-location @@ -388,7 +388,7 @@ (proxy [DefaultListCellRenderer] [] (getListCellRendererComponent [list item index isSelected cellHasFocus] (doto (proxy-super getListCellRendererComponent list item index isSelected cellHasFocus) - (.setText (present-item item)))))) + (.setText (present-item item)))))) (.addListSelectionListener (reify ListSelectionListener (valueChanged [_ e] diff --git a/src/clooj/highlighting.clj b/src/clooj/highlighting.clj index 826a777..dc54979 100644 --- a/src/clooj/highlighting.clj +++ b/src/clooj/highlighting.clj @@ -9,7 +9,7 @@ (java.awt Color) (javax.swing.event CaretListener)) (:require [clooj.utils :as utils])) - + (defn highlight ([text-comp start stop color] (when (and (<= 0 start) (<= stop (.. text-comp getDocument getLength))) diff --git a/src/clooj/navigate.clj b/src/clooj/navigate.clj index fb2bede..ff4166a 100644 --- a/src/clooj/navigate.clj +++ b/src/clooj/navigate.clj @@ -20,7 +20,7 @@ (defn move-to-line-start [comp] (.setCaretPosition comp (.getLineStartOffset comp - (get-caret-line-number comp)))) + (get-caret-line-number comp)))) (defn move-to-line-end [comp] (.setCaretPosition comp @@ -29,7 +29,7 @@ (if (= p (.. comp getDocument getLength)) p (dec p))))) - + (defn attach-navigation-keys [comp] (utils/attach-action-keys comp ["cmd1 LEFT" #(move-to-line-start comp)] diff --git a/src/clooj/project.clj b/src/clooj/project.clj index 58760c4..acc86f4 100644 --- a/src/clooj/project.clj +++ b/src/clooj/project.clj @@ -20,7 +20,7 @@ (defn save-project-set [] (utils/write-value-to-prefs utils/clooj-prefs "project-set" @project-set)) - + (defn load-project-set [] (reset! project-set (into (sorted-set) (utils/read-value-from-prefs utils/clooj-prefs "project-set")))) @@ -69,7 +69,7 @@ (.split File/separator)) (remove empty?) (remove #(= % ".")))) - + (defn file-ancestor? "In the file tree, returns true if descendant-file is a direct descendant of ancestor-file. @@ -79,7 +79,7 @@ descendant (path-components descendant-file)] (and (every? true? (map = ancestor descendant)) (<= (count ancestor) (count descendant))))) - + (defn node-children [node] (when-not (.isLeaf node) (for [i (range (.getChildCount node))] @@ -121,9 +121,9 @@ (defn load-tree-selection [tree] (let [path (utils/read-value-from-prefs utils/clooj-prefs "tree-selection")] - (if (nil? path) - false - (do + (if (nil? path) + false + (do (set-tree-selection tree path) true)))) @@ -183,7 +183,7 @@ (defn file-tree-model [projects] (DefaultTreeModel. (root-node projects) false)) - + (defn update-project-tree [tree] (let [model (file-tree-model (vec @project-set))] (utils/awt-event @@ -209,7 +209,7 @@ selections (.getSelectionPaths tree)] (for [selection selections] (-> selection .getPath second .getUserObject)))) - + (defn add-project [app project-path] (swap! project-set conj project-path)) @@ -226,5 +226,5 @@ (defn remove-selected-project [app] (apply swap! project-set disj (map #(.getAbsolutePath %) (get-selected-projects app))) - (update-project-tree (app :docs-tree))) - + (update-project-tree (app :docs-tree))) + diff --git a/src/clooj/repl/external.clj b/src/clooj/repl/external.clj index f759452..3ccd99a 100644 --- a/src/clooj/repl/external.clj +++ b/src/clooj/repl/external.clj @@ -13,7 +13,7 @@ [clooj.protocols :as protocols] [clooj.repl.lein :as lein] [clj-inspector.jars :as jars])) - + (defn own-clojure-jar "Locate the clojure jar being used by clooj (last resort)." [] @@ -37,7 +37,7 @@ jars (filter #(.contains (.getName %) "clojure") (jars/jar-files lib-dir))] (first (filter #(jar-contains-class? % "clojure.lang.RT") jars)))) - + (defn repl-classpath-items "Figures out the necessary pieces for a viable classpath given a particular project directory." @@ -49,7 +49,7 @@ (own-clojure-jar)) (str project-path "/lib/*") (str project-path "/src")]))) - + (defn java-binary "Returns the fully-qualified path of the java binary." [] @@ -64,7 +64,7 @@ (doto (ProcessBuilder. [(java-binary) "-cp" classpath-str "clojure.main"]) (.redirectErrorStream true) (.directory (io/file (or project-path "."))))))) - + (defn launch-repl "Launch an outside process with a clojure repl." [project-path classpath-items result-writer] @@ -104,7 +104,7 @@ (close repl-map)) (toString [this] (str "Repl with classpath" (:classpath repl-map)))))) - - + + diff --git a/src/clooj/repl/lein.clj b/src/clooj/repl/lein.clj index 8c74da1..27bbaa0 100644 --- a/src/clooj/repl/lein.clj +++ b/src/clooj/repl/lein.clj @@ -90,7 +90,7 @@ port (lein-nrepl-port-number (first (drop-while nil? lines)))] {:nrepl (nrepl port out-writer) :process process})) - + (defn lein-repl-stop "Disconnect from the nrepl connection and destroy the lein repl process." [{:keys [process nrepl]}] diff --git a/src/clooj/repl/main.clj b/src/clooj/repl/main.clj index 35c15ab..ed2d571 100644 --- a/src/clooj/repl/main.clj +++ b/src/clooj/repl/main.clj @@ -58,10 +58,10 @@ (defn initialize-repl [repl] (.evaluate repl - (str + (str "(do" (utils/local-clj-source "clooj/cemerick/pomegranate.clj") - (utils/local-clj-source "clooj/repl/remote.clj") + (utils/local-clj-source "clooj/repl/remote.clj") "(clooj.repl.remote/repl)" ")" ))) @@ -94,7 +94,7 @@ (binding [*source-path* ~short-file *file* ~file] (last (map eval ~read-string-code))))))) - + (defn print-to-repl [app cmd-str silent?] (when-let [repl @(app :repl)] @@ -164,7 +164,7 @@ (flush []) (close [] nil)) (PrintWriter. true))) - + (defn update-repl-in [app] (when (pos? (count @(:items repl-history))) (.setText (:repl-in-text-area app) @@ -197,7 +197,7 @@ (let [classpath-items ;(lein/lein-classpath-items project-path) (external/repl-classpath-items project-path) repl ;(lein/lein-repl project-path (app :repl-out-writer)) - (external/repl project-path classpath-items + (external/repl project-path classpath-items (app :repl-out-writer)) ] (initialize-repl repl) @@ -253,4 +253,4 @@ (send-to-repl app "(when *e (.printStackTrace *e))" true)) - + diff --git a/src/clooj/repl/output.clj b/src/clooj/repl/output.clj index 2f0bd32..fac2286 100644 --- a/src/clooj/repl/output.clj +++ b/src/clooj/repl/output.clj @@ -36,7 +36,7 @@ (insertUpdate [e] (set-scroll-offset e)) (removeUpdate [e])))) scroll-pane)) - + ;; manual tests (defn test-text-area @@ -59,9 +59,9 @@ .show) text-area )) - + (defn write-lines - "Write n lines of text (positive integers) in + "Write n lines of text (positive integers) in the text-area" [text-area n] (dotimes [i n] From be5ebfbbf09a0e5ae9ca7fd1defc16566eb7e6bd Mon Sep 17 00:00:00 2001 From: Noah Bogart <noah.bogart@hey.com> Date: Sat, 27 Apr 2024 19:54:33 -0400 Subject: [PATCH 3/3] Update project.clj url --- project.clj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/project.clj b/project.clj index e78388b..aaf5864 100644 --- a/project.clj +++ b/project.clj @@ -1,6 +1,6 @@ (defproject clooj "0.5" :description "clooj, a small IDE for clojure" - :url "https://github.com/arthuredelstein/clooj" + :url "https://github.com/clj-commons/clooj" :license {:name "Eclipse Public License" :url "http://www.eclipse.org/legal/epl-v10.html"} :main clooj.core