Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract file and line at point into functions #62

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
57 changes: 57 additions & 0 deletions src/el/sayid-magit.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
;;; sayid-magit.el --- Choose sayid tracing from magit -*- lexical-binding: t -*-

;; Author: Mark Dawson
;; Maintainer: Bill Piel <bill@billpiel.com>
;; 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
42 changes: 27 additions & 15 deletions src/el/sayid.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 ()
Expand Down Expand Up @@ -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)))
Expand Down