diff --git a/src/el/sayid-magit.el b/src/el/sayid-magit.el new file mode 100644 index 0000000..a70c2a9 --- /dev/null +++ b/src/el/sayid-magit.el @@ -0,0 +1,57 @@ +;;; sayid-magit.el --- Choose sayid tracing from magit -*- lexical-binding: t -*- + +;; Author: Mark Dawson +;; Maintainer: Bill Piel +;; Version: 0.0.1 +;; URL: https://github.com/clojure-emacs/sayid +;; Package-Requires: ((cider "0.21.0") (magit "2.90.1")) + +;; Licensed under the Apache License, Version 2.0 (the "License"); +;; you may not use this file except in compliance with the License. +;; You may obtain a copy of the License at + +;; http://www.apache.org/licenses/LICENSE-2.0 + +;; Unless required by applicable law or agreed to in writing, software +;; distributed under the License is distributed on an "AS IS" BASIS, +;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +;; See the License for the specific language governing permissions and +;; limitations under the License. + +;;; Commentary: + +;;; Code: + +;;;###autoload +(defun sayid-magit--trace-ns-in-files (file-names) + "Trace namespace in FILE-NAMES." + (mapc (lambda (file-name) + (with-current-buffer (find-file-noselect + file-name) + (nrepl-send-sync-request (list "op" "sayid-trace-ns-in-file" + "file" (buffer-file-name)) + (cider-current-connection)))) + file-names) + (sayid-show-traced)) + +;;;###autoload +(defun sayid-magit--changed-files () + "Return the absolute paths to changed files which have a .clj \ +extension in the current .git directory." + (seq-filter + (apply-partially #'string-match ".clj$") + (mapcar + (lambda (file) + (expand-file-name file (locate-dominating-file file ".git"))) + (magit-changed-files (magit-read-starting-point "Sayid trace" nil "HEAD"))))) + +;;;###autoload +(defun sayid-magit-trace-changed-ns () + "Trace the changed namespaces in a git commit." + (interactive) + (sayid-magit--trace-ns-in-files + (sayid-magit--changed-files))) + +(provide 'sayid-magit) + +;;; sayid-magit.el ends here diff --git a/src/el/sayid.el b/src/el/sayid.el index 9806c92..6ecf848 100644 --- a/src/el/sayid.el +++ b/src/el/sayid.el @@ -564,12 +564,13 @@ Disable traces, load buffer, enable traces, clear log." (sayid-show-traced)) ;;;###autoload -(defun sayid-trace-ns-by-pattern () +(defun sayid-trace-ns-by-pattern (ns-pattern) "Trace all namespaces that match specified pattern." - (interactive) + (interactive (list + (read-string "Namespace to trace (*=wildcard) " + (cider-current-ns)))) (nrepl-send-sync-request (list "op" "sayid-trace-ns-by-pattern" - "ns-pattern" (read-string "Namespace to trace (*=wildcard) " - (cider-current-ns)) + "ns-pattern" ns-pattern "ref-ns" (cider-current-ns)) (cider-current-connection)) (sayid-show-traced)) @@ -718,19 +719,30 @@ Disable traces, load buffer, enable traces, clear log." (setq paths (cdr paths))) (car paths)))) -;;;###autoload -(defun sayid-buffer-nav-from-point () - "Navigate from sayid buffer to function source." +(defun sayid-buffer-file-at-point () + "Return file path for function at point in sayid buffer." (interactive) (let* ((file (get-text-property (point) 'src-file)) - (line (get-text-property (point) 'src-line)) (xfile (sayid-find-existing-file file))) (if xfile - (progn - (pop-to-buffer (find-file-noselect xfile)) - (goto-char (point-min)) - (forward-line (- line 1))) - (message (concat "File not found: " file))))) + xfile + (user-error (concat "File not found: " file))))) + +(defun sayid-buffer-line-at-point () + "Return line number for function at point in sayid buffer." + (get-text-property (point) 'src-line)) + +;;;###autoload +(defun sayid-buffer-nav-from-point () + "Navigate from sayid buffer to function source." + (interactive) + (let ((line (sayid-buffer-line-at-point)) + (file (sayid-buffer-file-at-point))) + (when file + (progn + (pop-to-buffer (find-file-noselect file)) + (goto-char (point-min)) + (forward-line (- line 1)))))) ;;;###autoload (defun sayid-buffer-nav-to-prev () @@ -870,8 +882,8 @@ Disable traces, load buffer, enable traces, clear log." "Try to generate an expression that will reproduce traced call. Place expression in kill ring." (interactive) - (let ((expr (sayid-req-get-value (list "op" "sayid-gen-instance-expr" - "trace-id" (get-text-property (point) 'id))))) + (let ((expr (prin1-to-string (sayid-req-get-value (list "op" "sayid-gen-instance-expr" + "trace-id" (get-text-property (point) 'id)))))) (kill-new expr) (message (concat "Written to kill ring: " expr)) (sayid-buffer-nav-from-point)))