Klimi's new dotfiles with stow.
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

90 satır
3.5 KiB

4 yıl önce
  1. ;;; cider-tracing.el --- Executing tracing functionality -*- lexical-binding: t -*-
  2. ;; Copyright © 2013-2019 Bozhidar Batsov, Artur Malabarba and CIDER contributors
  3. ;;
  4. ;; Author: Bozhidar Batsov <bozhidar@batsov.com>
  5. ;; Artur Malabarba <bruce.connor.am@gmail.com>
  6. ;; This program is free software: you can redistribute it and/or modify
  7. ;; it under the terms of the GNU General Public License as published by
  8. ;; the Free Software Foundation, either version 3 of the License, or
  9. ;; (at your option) any later version.
  10. ;; This program is distributed in the hope that it will be useful,
  11. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ;; GNU General Public License for more details.
  14. ;; You should have received a copy of the GNU General Public License
  15. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ;; This file is not part of GNU Emacs.
  17. ;;; Commentary:
  18. ;; A couple of commands for tracing the execution of functions.
  19. ;;; Code:
  20. (require 'cider-client)
  21. (require 'cider-common) ; for `cider-prompt-for-symbol-function'
  22. (require 'cider-util) ; for `cider-propertize'
  23. (require 'cider-connection) ; for `cider-map-repls'
  24. (require 'nrepl-dict)
  25. (defun cider-sync-request:toggle-trace-var (symbol)
  26. "Toggle var tracing for SYMBOL."
  27. (thread-first `("op" "toggle-trace-var"
  28. "ns" ,(cider-current-ns)
  29. "sym" ,symbol)
  30. (cider-nrepl-send-sync-request)))
  31. (defun cider--toggle-trace-var (sym)
  32. "Toggle var tracing for SYM."
  33. (let* ((trace-response (cider-sync-request:toggle-trace-var sym))
  34. (var-name (nrepl-dict-get trace-response "var-name"))
  35. (var-status (nrepl-dict-get trace-response "var-status")))
  36. (pcase var-status
  37. ("not-found" (error "Var %s not found" (cider-propertize sym 'fn)))
  38. ("not-traceable" (error "Var %s can't be traced because it's not bound to a function" (cider-propertize var-name 'fn)))
  39. (_ (message "Var %s %s" (cider-propertize var-name 'fn) var-status)))))
  40. ;;;###autoload
  41. (defun cider-toggle-trace-var (arg)
  42. "Toggle var tracing.
  43. Prompts for the symbol to use, or uses the symbol at point, depending on
  44. the value of `cider-prompt-for-symbol'. With prefix arg ARG, does the
  45. opposite of what that option dictates."
  46. (interactive "P")
  47. (cider-ensure-op-supported "toggle-trace-var")
  48. (funcall (cider-prompt-for-symbol-function arg)
  49. "Toggle trace for var"
  50. #'cider--toggle-trace-var))
  51. (defun cider-sync-request:toggle-trace-ns (ns)
  52. "Toggle namespace tracing for NS."
  53. (thread-first `("op" "toggle-trace-ns"
  54. "ns" ,ns)
  55. (cider-nrepl-send-sync-request)))
  56. ;;;###autoload
  57. (defun cider-toggle-trace-ns (query)
  58. "Toggle ns tracing.
  59. Defaults to the current ns. With prefix arg QUERY, prompts for a ns."
  60. (interactive "P")
  61. (cider-map-repls :clj-strict
  62. (lambda (conn)
  63. (with-current-buffer conn
  64. (cider-ensure-op-supported "toggle-trace-ns")
  65. (let ((ns (if query
  66. (completing-read "Toggle trace for ns: "
  67. (cider-sync-request:ns-list))
  68. (cider-current-ns))))
  69. (let* ((trace-response (cider-sync-request:toggle-trace-ns ns))
  70. (ns-status (nrepl-dict-get trace-response "ns-status")))
  71. (pcase ns-status
  72. ("not-found" (error "Namespace %s not found" (cider-propertize ns 'ns)))
  73. (_ (message "Namespace %s %s" (cider-propertize ns 'ns) ns-status)))))))))
  74. (provide 'cider-tracing)
  75. ;;; cider-tracing.el ends here