-
Notifications
You must be signed in to change notification settings - Fork 0
/
canary.el
executable file
·77 lines (64 loc) · 2.58 KB
/
canary.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
;;; canary.el --- Tools to inspect Emacs state -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Aaron Harris
;; Author: Aaron Harris <[email protected]>
;; Keywords: lisp tools
;; 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/>.
;;; Commentary:
;; This module contains functions that help an Elisp programmer
;; inspect the current state of Emacs in one way or another.
;;
;; Functions included are as follows:
;;
;; `canary':
;;
;; This function just prints a message including its argument
;; list. This is most useful when used with advice; just install
;; it as :before advice on a function of interest, and `canary'
;; will tell you what arguments that function is called with.
;;
;; `canary-hooks':
;;
;; This command executes another command and logs all hooks run in
;; the process. It is useful when a command is triggering
;; anomalous behavior, but you don't know why. Alternatively, it
;; can be used to figure out what hooks exist that you can attach
;; new code to.
;;; Code:
(eval-when-compile (require 'vizier))
;;;###autoload
(defun canary (&rest args)
"Print a message containing ARGS."
(message "Canary called with args %s" args))
;;;###autoload
(defun canary-hooks (command &optional verbose)
"Call COMMAND, reporting every hook run in the process.
Interactively, prompt for a command to execute.
Return a list of the hooks run, in the order they were run.
Interactively, or with optional argument VERBOSE, also print a
message listing the hooks."
(interactive "CCommand to log hooks: \np")
(let* ((log nil)
(logger (lambda (&rest hooks)
(setq log (append log hooks nil)))))
(vizier-with-advice
((run-hooks :before logger))
(call-interactively command))
(when verbose
(message
(if log "Hooks run during execution of %s:"
"No hooks run during execution of %s.")
command)
(dolist (hook log)
(message "> %s" hook)))
log))
(provide 'canary)
;;; canary.el ends here