@@ -316,16 +316,12 @@ state. POS is the position to move cursor to."
316316
317317(defun sayid-tree--show-form-query (file line )
318318 " Fetch and render every recorded call of the form at FILE and LINE as a tree."
319- (let ((roots (sayid-req-get-value (list " op" " sayid-query-form-at-point-data"
320- " file" file
321- " line" line))))
322- (if roots
323- (sayid-tree--render roots
324- (format " Query: %s :%s "
325- (file-name-nondirectory file) line)
326- nil
327- (lambda () (sayid-tree--show-form-query file line)))
328- (user-error " No recorded calls for the form at point" ))))
319+ (sayid-tree--show-query
320+ (lambda () (sayid-req-get-value (list " op" " sayid-query-form-at-point-data"
321+ " file" file
322+ " line" line)))
323+ (format " Query: %s :%s " (file-name-nondirectory file) line)
324+ " No recorded calls for the form at point" ))
329325
330326;;;### autoload
331327(defun sayid-query-form-at-point ()
@@ -363,9 +359,12 @@ to naming the command."
363359 (t (format " M-x %s " command)))))
364360
365361(defun sayid--refresh-traced-if-visible ()
366- " Refresh the traced-functions view when its buffer is visible."
367- (when (get-buffer-window " *sayid-traced*" 'visible )
368- (save-selected-window (sayid-show-traced))))
362+ " Refresh the traced-functions view when its buffer is visible.
363+ Preserves the namespace filter the view was rendered with."
364+ (when-let* ((win (get-buffer-window " *sayid-traced*" 'visible )))
365+ (save-selected-window
366+ (sayid-show-traced
367+ (buffer-local-value 'sayid-traced--ns (window-buffer win))))))
369368
370369(defun sayid--trace-fn-at-point (action )
371370 " Apply trace ACTION to the function at point and describe the outcome.
@@ -651,19 +650,23 @@ the thrown error, or a named argument."
651650 (user-error " No call at point" ))))
652651 (cider-tree-view-node-value node)))
653652
654- (defconst sayid-tree--empty-workspace-hint
655- " The workspace is empty - Sayid hasn't recorded any calls yet.
653+ (defun sayid-tree--empty-workspace-hint ()
654+ " Build the hint shown in the workspace tree when nothing was recorded.
655+ The key sequences are looked up live, so a custom prefix shows correctly."
656+ (format " The workspace is empty - Sayid hasn't recorded any calls yet.
656657
657658To record something:
658659
659- 1. Trace what you're interested in: `sayid-trace-fn' (`C-c s t t ')
660+ 1. Trace what you're interested in: `sayid-trace-fn' (`%s ' )
660661 traces the function at point, `sayid-trace-ns-in-file'
661- (`C-c s t b ') the current buffer's whole namespace.
662+ (`%s ' ) the current buffer's whole namespace.
662663 2. Run some code that calls what you traced (eval a form,
663664 run a test, hit an endpoint).
664- 3. Refresh this buffer with `g' (or `C-c s w ' from anywhere).
665+ 3. Refresh this buffer with `g' (or `%s ' from anywhere).
665666"
666- " What to show in the workspace tree buffer when nothing was recorded." )
667+ (sayid--key-hint #'sayid-trace-fn )
668+ (sayid--key-hint #'sayid-trace-ns-in-file )
669+ (sayid--key-hint #'sayid-tree-view-workspace )))
667670
668671(defvar-local sayid-tree--refresh-fn nil
669672 " Function of no arguments that re-runs the fetch that produced this tree." )
@@ -686,6 +689,30 @@ so `sayid-tree-refresh' can re-run the fetch that produced this tree."
686689 (interactive )
687690 (funcall (or sayid-tree--refresh-fn #'sayid-tree-view-workspace )))
688691
692+ (defun sayid-tree--stale-query-hint ()
693+ " Build the hint shown when a refreshed query no longer matches anything."
694+ (format " This query no longer matches anything - the recording changed.
695+
696+ Press `w' for the full workspace, or trace and run something new
697+ \( `%s' traces the function at point).
698+ "
699+ (sayid--key-hint #'sayid-trace-fn )))
700+
701+ (defun sayid-tree--show-query (fetch-fn title empty-error &optional refreshing )
702+ " Fetch roots with FETCH-FN and render them as a tree titled TITLE.
703+ When nothing matches, signal EMPTY-ERROR - unless REFRESHING is non-nil
704+ \( a `sayid-tree-refresh' re-run of an existing view), where an emptied
705+ query renders as an empty tree with a hint, rather than erroring while
706+ the stale content stays on screen."
707+ (let ((roots (funcall fetch-fn))
708+ (refresh (lambda ()
709+ (sayid-tree--show-query fetch-fn title empty-error t ))))
710+ (cond
711+ (roots (sayid-tree--render roots title nil refresh))
712+ (refreshing
713+ (sayid-tree--render nil title (sayid-tree--stale-query-hint) refresh))
714+ (t (user-error " %s" empty-error)))))
715+
689716(defun sayid-tree--query-title (kind selector mod )
690717 " Build a tree title for a query of KIND on SELECTOR with modifier MOD."
691718 (format " Query: %s %s%s " kind selector
@@ -737,7 +764,11 @@ prompt for which value."
737764 (sayid-req-insert-content (list " op" " sayid-pprint-value"
738765 " trace-id" (nrepl-dict-get call " id" )
739766 " path" path))
740- (goto-char 1 )
767+ ; ; Point may have landed back in the tree buffer; reset the pprint
768+ ; ; buffer's position without disturbing the tree's.
769+ (when-let* ((buf (get-buffer (car sayid-pprint-buf-spec))))
770+ (with-current-buffer buf
771+ (goto-char (point-min ))))
741772 (sayid-select-default-buf)))
742773
743774(defun sayid-tree-gen-instance-expr ()
@@ -756,14 +787,12 @@ it into the REPL replays the call."
756787
757788(defun sayid-tree--show-fn-query (fn-name mod )
758789 " Fetch and render every recorded call of FN-NAME, with query modifier MOD."
759- (let ((roots (sayid-req-get-value (list " op" " sayid-query-by-fn-data"
760- " fn-name" fn-name
761- " mod" mod))))
762- (if roots
763- (sayid-tree--render roots (sayid-tree--query-title " fn" fn-name mod)
764- nil
765- (lambda () (sayid-tree--show-fn-query fn-name mod)))
766- (user-error " No recorded calls of %s" fn-name))))
790+ (sayid-tree--show-query
791+ (lambda () (sayid-req-get-value (list " op" " sayid-query-by-fn-data"
792+ " fn-name" fn-name
793+ " mod" mod)))
794+ (sayid-tree--query-title " fn" fn-name mod)
795+ (format " No recorded calls of %s " fn-name)))
767796
768797(defun sayid-tree-query-fn (&optional arg )
769798 " Re-render the tree with every recorded call of the function at point.
@@ -774,14 +803,12 @@ With a prefix ARG, also prompt for a query modifier."
774803
775804(defun sayid-tree--show-id-query (id mod )
776805 " Fetch and render the recorded call ID and its subtree, with modifier MOD."
777- (let ((roots (sayid-req-get-value (list " op" " sayid-query-by-id-data"
778- " trace-id" id
779- " mod" mod))))
780- (if roots
781- (sayid-tree--render roots (sayid-tree--query-title " id" id mod)
782- nil
783- (lambda () (sayid-tree--show-id-query id mod)))
784- (user-error " Call %s not found" id))))
806+ (sayid-tree--show-query
807+ (lambda () (sayid-req-get-value (list " op" " sayid-query-by-id-data"
808+ " trace-id" id
809+ " mod" mod)))
810+ (sayid-tree--query-title " id" id mod)
811+ (format " Call %s not found " id)))
785812
786813(defun sayid-tree-query-id (&optional arg )
787814 " Re-render the tree focused on the call at point.
@@ -799,7 +826,8 @@ When nothing has been recorded yet the buffer explains how to get going.
799826See `sayid-tree-mode' for the keys available in the tree buffer."
800827 (interactive )
801828 (let ((roots (sayid-req-get-value (list " op" " sayid-get-workspace-data" ))))
802- (sayid-tree--render roots " Sayid workspace" sayid-tree--empty-workspace-hint
829+ (sayid-tree--render roots " Sayid workspace"
830+ (sayid-tree--empty-workspace-hint)
803831 #'sayid-tree-view-workspace )))
804832
805833(defvar sayid-tree-mode-map
@@ -908,15 +936,19 @@ management: \\<sayid-traced-tree-mode-map>\\[sayid-traced-enable] enable,
908936\\ [sayid-traced-inner-trace] inner-trace, \\ [sayid-traced-outer-trace]
909937outer-trace the entry at point, \\ [sayid-traced-refresh] refresh the view." )
910938
911- (defconst sayid-traced--empty-hint
912- " Nothing is traced yet.
939+ (defun sayid-traced--empty-hint ()
940+ " Build the hint shown in the traced-functions buffer when nothing is traced.
941+ The key sequences are looked up live, so a custom prefix shows correctly."
942+ (format " Nothing is traced yet.
913943
914- In a Clojure buffer, `sayid-trace-ns-in-file' (`C-c s t b ') traces the
915- buffer's namespace; `sayid-trace-ns-by-pattern' (`C-c s t p ') traces
944+ In a Clojure buffer, `sayid-trace-ns-in-file' (`%s ' ) traces the
945+ buffer's namespace; `sayid-trace-ns-by-pattern' (`%s ' ) traces
916946namespaces by a wildcard pattern. Then run some code and view the
917- recording with `sayid-tree-view-workspace' (`C-c s w ').
947+ recording with `sayid-tree-view-workspace' (`%s ' ).
918948"
919- " What to show in the traced-functions buffer when nothing is traced." )
949+ (sayid--key-hint #'sayid-trace-ns-in-file )
950+ (sayid--key-hint #'sayid-trace-ns-by-pattern )
951+ (sayid--key-hint #'sayid-tree-view-workspace )))
920952
921953(defvar-local sayid-traced--ns nil
922954 " The namespace filter this traced-functions buffer was rendered with." )
@@ -933,7 +965,7 @@ GROUPS is empty, show a hint on how to trace something instead."
933965 " Traced functions"
934966 (unless groups
935967 (lambda ()
936- (insert (propertize sayid-traced--empty-hint
968+ (insert (propertize ( sayid-traced--empty-hint)
937969 'face 'shadow )))))))
938970
939971(defun sayid-traced-refresh ()
0 commit comments