-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmy-debug.el
68 lines (57 loc) · 2.18 KB
/
my-debug.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
;;; my-debug --- debug helper functions
;;
;;; Commentary:
;;
;; This is not included normally and has to be loaded manually
;;
;;; Code:
(defun my-check-for-subdir (filename newdir)
"Check to see if newdir is bellow where filename is in the heirachy"
(let ((dir (file-name-directory filename)))
(> (length newdir) (length dir))))
;; (my-check-for-subdir "/this/is/a.file" "/this/is/in/a/subdir")
;; (my-check-for-subdir "/this/is/a.file" "/this/is/")
(defun my-default-dir-watcher (symbol newval operation where)
(when (and where (eq operation 'set))
(let ((name (buffer-name where))
(path (buffer-file-name where)))
(message "default-directory set to: %s in %s" newval name)
(when (and path
(my-check-for-subdir (buffer-file-name) newval))
(message "%s not in %s\n%s" newval path
(catch 'catcher
(throw 'catcher
(with-temp-buffer
(backtrace)
(buffer-string)))))))))
;; (add-variable-watcher 'default-directory 'my-default-dir-watcher)
;; (remove-variable-watcher 'default-directory 'my-default-dir-watcher)
(defun my-add-dir-watcher-for-this-buffer ()
"Add a watcher to current-buffer for when default-directory changes
from it's current value."
(interactive)
(let ((orig-dir default-directory)
(buf (current-buffer)))
(add-variable-watcher
'default-directory
(lambda (symbol newval operation where)
(when (and (not (eq operation 'let))
(eq buf (current-buffer))
(not (string-equal orig-dir newval)))
(message "%s default-directory to %s (from %s) in %s"
operation newval orig-dir (current-buffer))
(backtrace))))))
(defun my-reset-dir-watchers ()
"Remove all default-directory watchers."
(interactive)
(--each
(get-variable-watchers 'default-directory)
(remove-variable-watcher 'default-directory it)))
;; Total buffer size
(defun my-debug-total-buffer-size ()
(let ((stext 0))
(dolist (b (buffer-list))
(setq stext (+ stext (buffer-size))))
stext))
(provide 'my-debug)
;;; my-debug.el ends here