diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2018-01-20 10:53:54 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2018-01-20 10:53:54 -0700 |
commit | b9df1151f60f07d3c8632fdbe6318b5d70337718 (patch) | |
tree | 33b8ad2a47f78257853d1cab9c5fd41119f8748d /cider-repl.el | |
parent | 3233785f6658e505a3ec54b192a3ba606d64f980 (diff) | |
parent | 50c7a0e84832acffce917461a457879a4f64459a (diff) |
Merge tag 'v0.16.0+dfsg'
DFSG-clean upstream version 0.16.0
Diffstat (limited to 'cider-repl.el')
-rw-r--r-- | cider-repl.el | 124 |
1 files changed, 67 insertions, 57 deletions
diff --git a/cider-repl.el b/cider-repl.el index e6168aef..ec412478 100644 --- a/cider-repl.el +++ b/cider-repl.el @@ -219,11 +219,11 @@ via `cider-current-connection'.") ;; Metadata changed, so signatures may have changed too. (setq cider-eldoc-last-symbol nil) (when (or cider-mode (derived-mode-p 'cider-repl-mode)) - (when-let ((ns-dict (or (nrepl-dict-get changed-namespaces (cider-current-ns)) - (let ((ns-dict (cider-resolve--get-in (cider-current-ns)))) - (when (seq-find (lambda (ns) (nrepl-dict-get changed-namespaces ns)) - (nrepl-dict-get ns-dict "aliases")) - ns-dict))))) + (when-let* ((ns-dict (or (nrepl-dict-get changed-namespaces (cider-current-ns)) + (let ((ns-dict (cider-resolve--get-in (cider-current-ns)))) + (when (seq-find (lambda (ns) (nrepl-dict-get changed-namespaces ns)) + (nrepl-dict-get ns-dict "aliases")) + ns-dict))))) (cider-refresh-dynamic-font-lock ns-dict)))))))))) (declare-function cider-default-err-handler "cider-interaction") @@ -255,52 +255,62 @@ ENDPOINT is a plist as returned by `nrepl-connect'." (add-hook 'nrepl-disconnected-hook 'cider--disconnected-handler nil 'local) (current-buffer)))) -(defun cider-repl-require-repl-utils () - "Require standard REPL util functions into the current REPL." - (interactive) - (cider-nrepl-request:eval - "(when (clojure.core/resolve 'clojure.main/repl-requires) - (clojure.core/map clojure.core/require clojure.main/repl-requires))" - (lambda (_response) nil))) - (declare-function cider-set-buffer-ns "cider-mode") (defun cider-repl-set-initial-ns (buffer) - "Set the REPL BUFFER's initial namespace (by altering `cider-buffer-ns'). -This is \"user\" by default but can be overridden in apps like lein (:init-ns)." + "Require standard REPL util functions and set the ns of the REPL's BUFFER. +Namespace is \"user\" by default, but can be overridden in apps like +lein (:init-ns). Both of these operations need to be done as a sync +request at the beginning of the session. Bundling them together for +efficiency." ;; we don't want to get a timeout during init (let ((nrepl-sync-request-timeout nil)) (with-current-buffer buffer - (let ((initial-ns (or (read - (nrepl-dict-get - (cider-nrepl-sync-request:eval "(str *ns*)") - "value")) - "user"))) + (let* ((response (nrepl-send-sync-request + (lax-plist-put (nrepl--eval-request "(str *ns*))") + "inhibit-cider-middleware" "true") + (cider-current-connection))) + (initial-ns (or (read (nrepl-dict-get response "value")) + "user"))) (cider-set-buffer-ns initial-ns))))) -(defvar cider-current-clojure-buffer nil - "This variable holds current buffer temporarily when connecting to a REPL. -It is set to current buffer when `cider' or `cider-jack-in' is called. -After the REPL buffer is created, the value of this variable is used -to call `cider-remember-clojure-buffer'.") - -(declare-function cider-remember-clojure-buffer "cider-mode") +(defun cider-repl-require-repl-utils () + "Require standard REPL util functions into the current REPL." + (interactive) + (nrepl-send-sync-request + (lax-plist-put + (nrepl--eval-request + "(when (clojure.core/resolve 'clojure.main/repl-requires) + (clojure.core/map clojure.core/require clojure.main/repl-requires))") + "inhibit-cider-middleware" "true") + (cider-current-connection))) (defun cider-repl-init (buffer &optional no-banner) "Initialize the REPL in BUFFER. BUFFER must be a REPL buffer with `cider-repl-mode' and a running client process connection. Unless NO-BANNER is non-nil, insert a banner." - (cider-repl-set-initial-ns buffer) - (cider-repl-require-repl-utils) - (unless no-banner - (cider-repl--insert-banner-and-prompt buffer)) (when cider-repl-display-in-current-window (add-to-list 'same-window-buffer-names (buffer-name buffer))) (pcase cider-repl-pop-to-buffer-on-connect (`display-only (display-buffer buffer)) ((pred identity) (pop-to-buffer buffer))) - (cider-remember-clojure-buffer cider-current-clojure-buffer) + (cider-repl-set-initial-ns buffer) + (cider-repl-require-repl-utils) + (unless no-banner + (cider-repl--insert-banner-and-prompt buffer)) buffer) +(defun cider-repl--insert-banner-and-prompt (buffer) + "Insert REPL banner and REPL prompt in BUFFER." + (with-current-buffer buffer + (when (zerop (buffer-size)) + (insert (propertize (cider-repl--banner) 'font-lock-face 'font-lock-comment-face)) + (when cider-repl-display-help-banner + (insert (propertize (cider-repl--help-banner) 'font-lock-face 'font-lock-comment-face)))) + (goto-char (point-max)) + (cider-repl--mark-output-start) + (cider-repl--mark-input-start) + (cider-repl--insert-prompt cider-buffer-ns))) + (defun cider-repl--banner () "Generate the welcome REPL buffer banner." (let ((host (cider--connection-host (current-buffer))) @@ -361,18 +371,6 @@ client process connection. Unless NO-BANNER is non-nil, insert a banner." ;; ====================================================================== ")) -(defun cider-repl--insert-banner-and-prompt (buffer) - "Insert REPL banner and REPL prompt in BUFFER." - (with-current-buffer buffer - (when (zerop (buffer-size)) - (insert (propertize (cider-repl--banner) 'font-lock-face 'font-lock-comment-face)) - (when cider-repl-display-help-banner - (insert (propertize (cider-repl--help-banner) 'font-lock-face 'font-lock-comment-face)))) - (goto-char (point-max)) - (cider-repl--mark-output-start) - (cider-repl--mark-input-start) - (cider-repl--insert-prompt cider-buffer-ns))) - ;;; REPL interaction @@ -557,7 +555,7 @@ When there is a possible unfinished ansi control sequence, (defun cider-repl--ns-form-changed-p (ns-form connection) "Return non-nil if NS-FORM for CONNECTION changed since last eval." - (when-let ((ns (cider-ns-from-form ns-form))) + (when-let* ((ns (cider-ns-from-form ns-form))) (not (string= ns-form (lax-plist-get (buffer-local-value 'cider-repl--ns-forms-plist connection) @@ -575,7 +573,7 @@ When there is a possible unfinished ansi control sequence, (defun cider-repl--cache-ns-form (ns-form connection) "Given NS-FORM cache root ns in CONNECTION." (with-current-buffer connection - (when-let ((ns (cider-ns-from-form ns-form))) + (when-let* ((ns (cider-ns-from-form ns-form))) ;; cache ns-form (setq cider-repl--ns-forms-plist (lax-plist-put cider-repl--ns-forms-plist ns ns-form)) @@ -702,9 +700,10 @@ If BOL is non-nil, emit at the beginning of the line." (cider-repl--insert-prompt cider-buffer-ns)))) (cider-repl--show-maximum-output))) -(defun cider-repl-emit-result (buffer string &optional bol) +(defun cider-repl-emit-result (buffer string show-prefix &optional bol) "Emit into BUFFER the result STRING and mark it as an evaluation result. -If BOL is non-nil insert at the beginning of the line." +If SHOW-PREFIX is non-nil insert `cider-repl-result-prefix' at the beginning +of the line. If BOL is non-nil insert at the beginning of the line." (with-current-buffer buffer (save-excursion (cider-save-marker cider-repl-output-start @@ -712,7 +711,8 @@ If BOL is non-nil insert at the beginning of the line." (goto-char cider-repl-input-start-mark) (when (and bol (not (bolp))) (insert-before-markers "\n")) - (insert-before-markers (propertize cider-repl-result-prefix 'font-lock-face 'font-lock-comment-face)) + (when show-prefix + (insert-before-markers (propertize cider-repl-result-prefix 'font-lock-face 'font-lock-comment-face))) (if cider-repl-use-clojure-font-lock (insert-before-markers (cider-font-lock-as-clojure string)) (cider-propertize-region @@ -770,8 +770,10 @@ the symbol." (defun cider-repl-handler (buffer) "Make an nREPL evaluation handler for the REPL BUFFER." (nrepl-make-response-handler buffer - (lambda (buffer value) - (cider-repl-emit-result buffer value t)) + (let (after-first-result-chunk) + (lambda (buffer value) + (cider-repl-emit-result buffer value (not after-first-result-chunk) t) + (setq after-first-result-chunk t))) (lambda (buffer out) (cider-repl-emit-stdout buffer out)) (lambda (buffer err) @@ -779,8 +781,10 @@ the symbol." (lambda (buffer) (cider-repl-emit-prompt buffer)) nrepl-err-handler - (lambda (buffer pprint-out) - (cider-repl-emit-result buffer pprint-out nil)))) + (let (after-first-result-chunk) + (lambda (buffer pprint-out) + (cider-repl-emit-result buffer pprint-out (not after-first-result-chunk)) + (setq after-first-result-chunk t))))) (defun cider-repl--send-input (&optional newline) "Go to the end of the input and send the current input. @@ -896,7 +900,7 @@ text property `cider-old-input'." (defun cider-repl-switch-to-other () "Switch between the Clojure and ClojureScript REPLs for the current project." (interactive) - (if-let (other-connection (cider-other-connection)) + (if-let* ((other-connection (cider-other-connection))) (switch-to-buffer other-connection) (message "There's no other REPL for the current project"))) @@ -1068,7 +1072,7 @@ for locref look up." This function is used from help-echo property inside REPL buffers and uses regexes from `cider-locref-regexp-alist' to infer locations at point." (interactive) - (if-let ((loc (cider-locref-at-point pos))) + (if-let* ((loc (cider-locref-at-point pos))) (let* ((var (plist-get loc :var)) (line (plist-get loc :line)) (file (or @@ -1099,11 +1103,11 @@ regexes from `cider-locref-regexp-alist' to infer locations at point." "Overlay used during hoovering on location references in REPL buffers. One for all REPLs.") -(defun cider-locref-help-echo (win buffer pos) +(defun cider-locref-help-echo (_win buffer pos) "Function for help-echo property in REPL buffers. WIN, BUFFER and POS are the window, buffer and point under mouse position." (with-current-buffer buffer - (if-let ((hl (plist-get (cider-locref-at-point pos) :highlight))) + (if-let* ((hl (plist-get (cider-locref-at-point pos) :highlight))) (move-overlay cider-locref-hoover-overlay (car hl) (cdr hl)) (delete-overlay cider-locref-hoover-overlay)) nil)) @@ -1376,6 +1380,7 @@ constructs." (cider-repl-add-shortcut "quit" #'cider-quit) (cider-repl-add-shortcut "restart" #'cider-restart) (cider-repl-add-shortcut "version" #'cider-version) +(cider-repl-add-shortcut "require-repl-utils" #'cider-repl-require-repl-utils) (defconst cider-repl-shortcuts-help-buffer "*CIDER REPL Shortcuts Help*") @@ -1428,6 +1433,7 @@ constructs." (declare-function cider-find-resource "cider-interaction") (declare-function cider-restart "cider-interaction") (declare-function cider-find-ns "cider-interaction") +(declare-function cider-find-keyword "cider-interaction") (declare-function cider-switch-to-last-clojure-buffer "cider-mode") (defvar cider-repl-mode-map @@ -1437,6 +1443,7 @@ constructs." (define-key map (kbd "C-c C-t") 'cider-test-commands-map) (define-key map (kbd "M-.") #'cider-find-var) (define-key map (kbd "C-c C-.") #'cider-find-ns) + (define-key map (kbd "C-c C-:") #'cider-find-keyword) (define-key map (kbd "M-,") #'cider-pop-back) (define-key map (kbd "C-c M-.") #'cider-find-resource) (define-key map (kbd "RET") #'cider-repl-return) @@ -1482,7 +1489,9 @@ constructs." "--" ("Find" ["Find definition" cider-find-var] + ["Find namespace" cider-find-ns] ["Find resource" cider-find-resource] + ["Find keyword" cider-find-keyword] ["Go back" cider-pop-back]) "--" ["Switch to Clojure buffer" cider-switch-to-last-clojure-buffer] @@ -1502,6 +1511,7 @@ constructs." "--" ["Set REPL ns" cider-repl-set-ns] ["Toggle pretty printing" cider-repl-toggle-pretty-printing] + ["Require REPL utils" cider-repl-require-repl-utils] "--" ["Browse classpath" cider-classpath] ["Browse classpath entry" cider-open-classpath-entry] |