@@ -694,8 +694,8 @@ which nREPL uses for temporary evaluation file names."
694
694
(defun cider-find-file (url )
695
695
" Return a buffer visiting the file URL if it exists, or nil otherwise.
696
696
If URL has a scheme prefix, it must represent a fully-qualified file path
697
- or an entry within a zip/jar archive. If URL doesn't contain a scheme
698
- prefix and is an absolute path, it is treated as such. Finally, if URL is
697
+ or an entry within a zip/jar archive. If URL doesn't contain a scheme
698
+ prefix and is an absolute path, it is treated as such. Finally, if URL is
699
699
relative, it is expanded within each of the open Clojure buffers till an
700
700
existing file ending with URL has been found."
701
701
(cond ((string-match " ^file:\\ (.+\\ )" url)
@@ -781,46 +781,100 @@ window."
781
781
(cider--find-dwim symbol-file 'cider-find-dwim-other-window t ))
782
782
783
783
(defun cider-find-dwim (symbol-file )
784
- " Try to jump to the SYMBOL-FILE at point. If thing at point is empty dired
785
- on project. If var is not found, try to jump to resource of the same name.
786
- When called interactively, A prompt is given according to the variable
787
- cider-prompt-for-symbol. A prefix inverts the meaning. A default value of
788
- thing at point is given when prompted."
784
+ " Find and display the SYMBOL-FILE at point.
785
+
786
+ SYMBOL-FILE could be a var or a resource. If thing at point is empty
787
+ then show dired on project. If var is not found, try to jump to resource
788
+ of the same name. When called interactively, a prompt is given according
789
+ to the variable `cider-prompt-for-symbol' . A single or double prefix argument
790
+ inverts the meaning. A prefix of `-` or a double prefix argument causes the
791
+ results to be displayed in a different window.
792
+ A default value of thing at point is given when prompted."
789
793
(interactive (cider--find-dwim-interactive " Jump to: " ))
790
- (cider--find-dwim symbol-file 'cider-find-dwim ))
794
+ (cider--find-dwim symbol-file `cider-find-dwim
795
+ (cider--open-other-window-p current-prefix-arg)))
791
796
792
797
(defun cider--find-dwim (symbol-file callback &optional other-window )
793
- " Try to jump to the SYMBOL-FILE at point, show results in OTHER-WINDOW as indicated.
798
+ " Find the SYMBOL-FILE at point.
799
+
794
800
CALLBACK upon failure to invoke prompt if not prompted previously.
795
- If thing at point is empty dired on project ."
801
+ Show results in a different window if OTHER-WINDOW is true ."
796
802
(-if-let (info (cider-var-info symbol-file))
797
803
(cider--jump-to-loc-from-info info other-window)
798
804
(progn
799
805
(cider-ensure-op-supported " resource" )
800
806
(-if-let* ((resource (cider-sync-request:resource symbol-file))
801
807
(buffer (cider-find-file resource)))
802
808
(cider-jump-to buffer 0 other-window)
803
- (if (cider--should- prompt-for-symbol current-prefix-arg)
809
+ (if (cider--prompt-for-symbol-p current-prefix-arg)
804
810
(error " Resource or var %s not resolved " symbol-file)
805
811
(let ((current-prefix-arg (if current-prefix-arg nil '(4 ))))
806
812
(call-interactively callback)))))))
807
813
808
814
(defun cider--find-dwim-interactive (prompt )
809
815
" Get interactive arguments for jump-to functions using PROMPT as needed."
810
- (if (cider--should- prompt-for-symbol current-prefix-arg)
816
+ (if (cider--prompt-for-symbol-p current-prefix-arg)
811
817
(list
812
818
(cider-read-from-minibuffer prompt (thing-at-point 'filename )))
813
819
(list (or (thing-at-point 'filename ) " " )))) ; No prompt.
814
820
815
821
(defun cider-find-resource (path )
816
- " Jump to the resource at the resource-relative PATH.
817
- When called interactively, this operates on point."
818
- (interactive (list (thing-at-point 'filename )))
822
+ " Find the resource at PATH.
823
+
824
+ Prompt for input as indicated by the variable `cider-prompt-for-symbol`.
825
+ A single or double prefix argument inverts the meaning of
826
+ `cider-prompt-for-symbol`. A prefix argument of `-` or a double prefix
827
+ argument causes the results to be displayed in other window. The default
828
+ value is thing at point."
829
+ (interactive
830
+ (list
831
+ (if (cider--prompt-for-symbol-p current-prefix-arg)
832
+ (cider-read-from-minibuffer " Resource: " (thing-at-point 'filename ))
833
+ (or (thing-at-point 'filename ) " " ))))
834
+
819
835
(cider-ensure-op-supported " resource" )
820
836
(-if-let* ((resource (cider-sync-request:resource path))
821
837
(buffer (cider-find-file resource)))
822
- (cider-jump-to buffer)
823
- (error " Cannot find resource %s " path)))
838
+ (cider-jump-to buffer nil (cider--open-other-window-p current-prefix-arg))
839
+ (if (cider--prompt-for-symbol-p current-prefix-arg)
840
+ (error " Cannot find resource %s " path)
841
+ (let ((current-prefix-arg (cider--invert-prefix-arg current-prefix-arg)))
842
+ (call-interactively `cider-find-resource)))))
843
+
844
+ (defun cider--open-other-window-p (arg )
845
+ " Test prefix value ARG to see if it indicates displaying results in other window."
846
+ (let ((narg (prefix-numeric-value arg)))
847
+ (pcase narg
848
+ (-1 t ) ; -
849
+ (16 t ) ; empty empty
850
+ (narg nil ))))
851
+
852
+ (defun cider--invert-prefix-arg (arg )
853
+ " Invert the effect of prefix value ARG on `cider-prompt-for-symbol' .
854
+
855
+ This function preserves the `other-window' meaning of ARG."
856
+ (let ((narg (prefix-numeric-value arg)))
857
+ (pcase narg
858
+ (16 -1 ) ; empty empty -> -
859
+ (-1 16 ) ; - -> empty empty
860
+ (4 nil ) ; empty -> no-prefix
861
+ (nil 4 )))) ; no-prefix -> empty
862
+
863
+ (defun cider--prefix-invert-prompt-p (arg )
864
+ " Test prefix value ARG for its effect on `cider-prompt-for-symbol`."
865
+ (let ((narg (prefix-numeric-value arg)))
866
+ (pcase narg
867
+ (16 t ) ; empty empty
868
+ (4 t ) ; empty
869
+ (narg nil ))))
870
+
871
+ (defun cider--prompt-for-symbol-p (&optional prefix )
872
+ " Check if cider should prompt for symbol.
873
+
874
+ Tests againsts PREFIX and the value of `cider-prompt-for-symbol' .
875
+ Invert meaning of `cider-prompt-for-symbol' if PREFIX indicates it should be."
876
+ (if (cider--prefix-invert-prompt-p prefix)
877
+ (not cider-prompt-for-symbol) cider-prompt-for-symbol))
824
878
825
879
(defun cider--jump-to-loc-from-info (info &optional other-window )
826
880
" Jump to location give by INFO.
@@ -835,26 +889,41 @@ OTHER-WINDOW is passed to `cider-jamp-to'."
835
889
(cider-jump-to buffer (cons line nil ) other-window)
836
890
(error " No source location " ))))
837
891
892
+ (defun cider--find-var-other-window (var &optional line )
893
+ " Find the definition of VAR, optionally at a specific LINE.
894
+
895
+ Display the results in a different window."
896
+ (-if-let (info (cider-var-info var))
897
+ (progn
898
+ (if line (setq info (nrepl-dict-put info " line" line)))
899
+ (cider--jump-to-loc-from-info info t ))
900
+ (error " Symbol %s not resolved " var)))
901
+
838
902
(defun cider--find-var (var &optional line )
839
- " Jump to the definition of VAR, optionally at a specific LINE."
903
+ " Find the definition of VAR, optionally at a specific LINE."
840
904
(-if-let (info (cider-var-info var))
841
905
(progn
842
906
(if line (setq info (nrepl-dict-put info " line" line)))
843
907
(cider--jump-to-loc-from-info info))
844
908
(error " Symbol %s not resolved " var)))
845
909
846
910
(defun cider-find-var (&optional arg var line )
847
- " Jump to the definition of VAR, optionally at a specific LINE.
848
- Prompts for the symbol to use, or uses the symbol at point, depending on
849
- the value of `cider-prompt-for-symbol' . With prefix arg ARG, does the
850
- opposite of what that option dictates."
911
+ " Find definition for VAR at LINE. Prompt according to prefix ARG
912
+ and `cider-prompt-for-symbol' .
913
+
914
+ A single or double prefix argument inverts the meaning of
915
+ `cider-prompt-for-symbol. A prefix of `-` or a double prefix argument causes
916
+ the results to be displayed in a different window. The default value is
917
+ thing at point."
851
918
(interactive " P" )
852
919
(cider-ensure-op-supported " info" )
853
920
(if var
854
921
(cider--find-var var line)
855
922
(funcall (cider-prompt-for-symbol-function arg)
856
923
" Symbol: "
857
- #'cider--find-var )))
924
+ (if (cider--open-other-window-p arg)
925
+ #'cider--find-var-other-window
926
+ #'cider--find-var ))))
858
927
859
928
(define-obsolete-function-alias 'cider-jump-to-resource 'cider-find-resource " 0.9.0" )
860
929
(define-obsolete-function-alias 'cider-jump-to-var 'cider-find-var " 0.9.0" )
0 commit comments