summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cider-interaction.el52
-rw-r--r--cider-mode.el2
-rw-r--r--cider-repl.el4
-rw-r--r--cider-tracing.el90
4 files changed, 94 insertions, 54 deletions
diff --git a/cider-interaction.el b/cider-interaction.el
index 49046876..f2ffdf6e 100644
--- a/cider-interaction.el
+++ b/cider-interaction.el
@@ -1566,58 +1566,6 @@ See command `cider-mode'."
;;; Completion
-(defun cider-sync-request:toggle-trace-var (symbol)
- "Toggle var tracing for SYMBOL."
- (thread-first `("op" "toggle-trace-var"
- "ns" ,(cider-current-ns)
- "sym" ,symbol)
- (cider-nrepl-send-sync-request)))
-
-(defun cider--toggle-trace-var (sym)
- "Toggle var tracing for SYM."
- (let* ((trace-response (cider-sync-request:toggle-trace-var sym))
- (var-name (nrepl-dict-get trace-response "var-name"))
- (var-status (nrepl-dict-get trace-response "var-status")))
- (pcase var-status
- ("not-found" (error "Var %s not found" (cider-propertize sym 'fn)))
- ("not-traceable" (error "Var %s can't be traced because it's not bound to a function" (cider-propertize var-name 'fn)))
- (_ (message "Var %s %s" (cider-propertize var-name 'fn) var-status)))))
-
-(defun cider-toggle-trace-var (arg)
- "Toggle var tracing.
-Prompts for the symbol to use, or uses the symbol at point, depending on
-the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the
-opposite of what that option dictates."
- (interactive "P")
- (cider-ensure-op-supported "toggle-trace-var")
- (funcall (cider-prompt-for-symbol-function arg)
- "Toggle trace for var"
- #'cider--toggle-trace-var))
-
-(defun cider-sync-request:toggle-trace-ns (ns)
- "Toggle namespace tracing for NS."
- (thread-first `("op" "toggle-trace-ns"
- "ns" ,ns)
- (cider-nrepl-send-sync-request)))
-
-(defun cider-toggle-trace-ns (query)
- "Toggle ns tracing.
-Defaults to the current ns. With prefix arg QUERY, prompts for a ns."
- (interactive "P")
- (cider-map-repls :clj-strict
- (lambda (conn)
- (with-current-buffer conn
- (cider-ensure-op-supported "toggle-trace-ns")
- (let ((ns (if query
- (completing-read "Toggle trace for ns: "
- (cider-sync-request:ns-list))
- (cider-current-ns))))
- (let* ((trace-response (cider-sync-request:toggle-trace-ns ns))
- (ns-status (nrepl-dict-get trace-response "ns-status")))
- (pcase ns-status
- ("not-found" (error "Namespace %s not found" (cider-propertize ns 'ns)))
- (_ (message "Namespace %s %s" (cider-propertize ns 'ns) ns-status)))))))))
-
(defun cider-undef ()
"Undefine a symbol from the current ns."
(interactive)
diff --git a/cider-mode.el b/cider-mode.el
index f0a88de3..45d9c518 100644
--- a/cider-mode.el
+++ b/cider-mode.el
@@ -379,6 +379,8 @@ If invoked with a prefix ARG eval the expression after inserting it."
(declare-function cider-macroexpand-1 "cider-macroexpansion")
(declare-function cider-macroexpand-all "cider-macroexpansion")
(declare-function cider-selector "cider-selector")
+(declare-function cider-toggle-trace-ns "cider-tracing")
+(declare-function cider-toggle-trace-var "cider-tracing")
(defconst cider-mode-map
(let ((map (make-sparse-keymap)))
(define-key map (kbd "C-c C-d") 'cider-doc-map)
diff --git a/cider-repl.el b/cider-repl.el
index 9a4a77ce..de93b68f 100644
--- a/cider-repl.el
+++ b/cider-repl.el
@@ -1562,8 +1562,8 @@ constructs."
(declare-function cider-eval-last-sexp "cider-interaction")
(declare-function cider-refresh "cider-interaction")
-(declare-function cider-toggle-trace-ns "cider-interaction")
-(declare-function cider-toggle-trace-var "cider-interaction")
+(declare-function cider-toggle-trace-ns "cider-tracing")
+(declare-function cider-toggle-trace-var "cider-tracing")
(declare-function cider-find-resource "cider-interaction")
(declare-function cider-find-ns "cider-interaction")
(declare-function cider-find-keyword "cider-interaction")
diff --git a/cider-tracing.el b/cider-tracing.el
new file mode 100644
index 00000000..c00e7b7f
--- /dev/null
+++ b/cider-tracing.el
@@ -0,0 +1,90 @@
+;;; cider-tracing.el --- Executing tracing functionality -*- lexical-binding: t -*-
+
+;; Copyright © 2013-2018 Bozhidar Batsov, Artur Malabarba and CIDER contributors
+;;
+;; Author: Bozhidar Batsov <bozhidar@batsov.com>
+;; Artur Malabarba <bruce.connor.am@gmail.com>
+
+;; This program is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;; This file is not part of GNU Emacs.
+
+;;; Commentary:
+
+;; A couple of commands for tracing the execution of functions.
+
+;;; Code:
+
+(require 'cider-client)
+(require 'cider-common) ; for `cider-prompt-for-symbol-function'
+(require 'cider-util) ; for `cider-propertize'
+(require 'cider-connection) ; for `cider-map-repls'
+(require 'nrepl-dict)
+
+(defun cider-sync-request:toggle-trace-var (symbol)
+ "Toggle var tracing for SYMBOL."
+ (thread-first `("op" "toggle-trace-var"
+ "ns" ,(cider-current-ns)
+ "sym" ,symbol)
+ (cider-nrepl-send-sync-request)))
+
+(defun cider--toggle-trace-var (sym)
+ "Toggle var tracing for SYM."
+ (let* ((trace-response (cider-sync-request:toggle-trace-var sym))
+ (var-name (nrepl-dict-get trace-response "var-name"))
+ (var-status (nrepl-dict-get trace-response "var-status")))
+ (pcase var-status
+ ("not-found" (error "Var %s not found" (cider-propertize sym 'fn)))
+ ("not-traceable" (error "Var %s can't be traced because it's not bound to a function" (cider-propertize var-name 'fn)))
+ (_ (message "Var %s %s" (cider-propertize var-name 'fn) var-status)))))
+
+;;;###autoload
+(defun cider-toggle-trace-var (arg)
+ "Toggle var tracing.
+Prompts for the symbol to use, or uses the symbol at point, depending on
+the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the
+opposite of what that option dictates."
+ (interactive "P")
+ (cider-ensure-op-supported "toggle-trace-var")
+ (funcall (cider-prompt-for-symbol-function arg)
+ "Toggle trace for var"
+ #'cider--toggle-trace-var))
+
+(defun cider-sync-request:toggle-trace-ns (ns)
+ "Toggle namespace tracing for NS."
+ (thread-first `("op" "toggle-trace-ns"
+ "ns" ,ns)
+ (cider-nrepl-send-sync-request)))
+
+;;;###autoload
+(defun cider-toggle-trace-ns (query)
+ "Toggle ns tracing.
+Defaults to the current ns. With prefix arg QUERY, prompts for a ns."
+ (interactive "P")
+ (cider-map-repls :clj-strict
+ (lambda (conn)
+ (with-current-buffer conn
+ (cider-ensure-op-supported "toggle-trace-ns")
+ (let ((ns (if query
+ (completing-read "Toggle trace for ns: "
+ (cider-sync-request:ns-list))
+ (cider-current-ns))))
+ (let* ((trace-response (cider-sync-request:toggle-trace-ns ns))
+ (ns-status (nrepl-dict-get trace-response "ns-status")))
+ (pcase ns-status
+ ("not-found" (error "Namespace %s not found" (cider-propertize ns 'ns)))
+ (_ (message "Namespace %s %s" (cider-propertize ns 'ns) ns-status)))))))))
+
+(provide 'cider-tracing)
+;;; cider-tracing.el ends here