@@ -1065,41 +1065,31 @@ evaluation command. Honor `cider-auto-jump-to-error'."
1065
1065
#'identity ))
1066
1066
" Function to translate Emacs filenames to nREPL namestrings." )
1067
1067
1068
- (defvar-local cider--ns-form-cache (make-hash-table :test 'equal )
1069
- " ns form cache for the current buffer.
1070
-
1071
- The cache is a hash where the keys are connection names and the values
1072
- are ns forms. This allows every connection to keep track of the ns
1073
- form independently." )
1074
-
1075
- (defun cider--cache-ns-form ()
1076
- " Cache the form in the current buffer for the current connection."
1077
- (puthash (cider-current-connection)
1078
- (cider-ns-form)
1079
- cider--ns-form-cache))
1080
-
1081
- (defun cider--cached-ns-form ()
1082
- " Retrieve the cached ns form for the current buffer & connection."
1083
- (gethash (cider-current-connection) cider--ns-form-cache))
1084
-
1085
- (defun cider--prep-interactive-eval (form )
1086
- " Prepare the environment for an interactive eval of FORM.
1087
-
1088
- Ensure the current ns declaration has been
1089
- evaluated (so that the ns containing FORM exists).
1090
- If FORM is a ns declaration it's not processed and cached.
1091
-
1092
- Clears any compilation highlights and kills the error window."
1068
+ (defvar-local cider--last-ns-form nil
1069
+ " Ns-form of the most recent interactive evaluation." )
1070
+
1071
+ (defun cider--prep-interactive-eval (form connection )
1072
+ " Prepare the environment for an interactive eval of FORM in CONNECTION.
1073
+ Ensure the current ns declaration has been evaluated (so that the ns
1074
+ containing FORM exists). Cache ns-form in the current buffer unless FORM is
1075
+ ns declaration itself. Clear any compilation highlights and kill the error
1076
+ window."
1093
1077
(cider--clear-compilation-highlights)
1094
1078
(cider--quit-error-window)
1095
1079
(let ((cur-ns-form (cider-ns-form)))
1096
1080
(when (and cur-ns-form
1097
- (not (string= cur-ns-form (cider--cached-ns-form)))
1081
+ (not (string= cur-ns-form
1082
+ (buffer-local-value 'cider--last-ns-form connection)))
1098
1083
(not (cider-ns-form-p form)))
1099
1084
(when cider-auto-track-ns-form-changes
1100
- ; ; TODO: check for evaluation errors
1101
- (cider-eval-ns-form 'sync ))
1102
- (cider--cache-ns-form))))
1085
+ ; ; The first interactive eval on a file can load a lot of libs. This can
1086
+ ; ; easily lead to more than 10 sec.
1087
+ (let ((nrepl-sync-request-timeout 30 ))
1088
+ ; ; TODO: check for evaluation errors
1089
+ (cider-nrepl-sync-request:eval cur-ns-form connection)))
1090
+ ; ; cache at the end, in case of errors
1091
+ (with-current-buffer connection
1092
+ (setq cider--last-ns-form cur-ns-form)))))
1103
1093
1104
1094
(defvar-local cider-interactive-eval-override nil
1105
1095
" Function to call instead of `cider-interactive-eval' ." )
@@ -1127,9 +1117,9 @@ arguments and only proceed with evaluation if it returns nil."
1127
1117
(functionp cider-interactive-eval-override)
1128
1118
(funcall cider-interactive-eval-override form callback bounds))
1129
1119
(cider-map-connections #'ignore :any )
1130
- (cider--prep-interactive-eval form)
1131
1120
(cider-map-connections
1132
1121
(lambda (connection )
1122
+ (cider--prep-interactive-eval form connection)
1133
1123
(cider-nrepl-request:eval
1134
1124
form
1135
1125
(or callback (cider-interactive-eval-handler nil bounds))
@@ -1624,10 +1614,12 @@ ClojureScript REPL exists for the project, it is evaluated in both REPLs."
1624
1614
(remove-overlays nil nil 'cider-temporary t )
1625
1615
(cider--clear-compilation-highlights)
1626
1616
(cider--quit-error-window)
1627
- (cider--cache-ns-form )
1628
- ( let ((filename ( buffer-file-name buffer )))
1617
+ (let ((filename ( buffer-file-name buffer) )
1618
+ (ns-form (cider-ns-form )))
1629
1619
(cider-map-connections
1630
1620
(lambda (connection )
1621
+ (with-current-buffer connection
1622
+ (setq cider--last-ns-form ns-form))
1631
1623
(cider-request:load-file (cider-file-string filename)
1632
1624
(funcall cider-to-nrepl-filename-function
1633
1625
(cider--server-filename filename))
@@ -1795,11 +1787,7 @@ START and END represent the region's boundaries."
1795
1787
(defun cider--quit-connection (conn )
1796
1788
" Quit the connection CONN."
1797
1789
(when conn
1798
- (cider--close-connection-buffer conn)
1799
- ; ; clean the cached ns forms for this connection in all Clojure buffers
1800
- (dolist (clojure-buffer (cider-util--clojure-buffers))
1801
- (with-current-buffer clojure-buffer
1802
- (remhash conn cider--ns-form-cache)))))
1790
+ (cider--close-connection-buffer conn)))
1803
1791
1804
1792
(defun cider-quit (&optional quit-all )
1805
1793
" Quit the currently active CIDER connection.
0 commit comments