File: gnuplot-debug-context.el

package info (click to toggle)
gnuplot-mode 1:0.7.0-2014-12-31-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,392 kB
  • sloc: lisp: 6,002; sh: 494; makefile: 38
file content (115 lines) | stat: -rw-r--r-- 3,244 bytes parent folder | download | duplicates (2)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
;;
;; debugging utilities for the gnuplot-mode context matcher
;;

(require 'gnuplot-test-context) 	; for gnuplot-simplify-tokens

(defun gnuplot-unload ()
  (interactive)
  (mapatoms
   (lambda (sym)
     (when (string-match
	    "gnuplot"
	    (symbol-name sym))
       (unintern sym obarray)))))

(defun gnuplot-reload (&optional context)
  (interactive "p")
  (condition-case nil
      (gnuplot-unload)
    (error nil))
  (require 'gnuplot)
  (when context
    (if (= context 16)
	(require 'gnuplot-debug-context))
    (require 'gnuplot-context)))

(defsubst gnuplot-recompile ()
  (save-current-buffer
    (save-window-excursion
      (find-file "gnuplot-context.el")
      (delete-file "gnuplot-context.elc")
      (emacs-lisp-byte-compile)
      (load-file "gnuplot-context.elc"))))
  
(defun gnuplot-nodebug ()
  (interactive)
  (when (featurep 'gnuplot-debug-context)
      (let ((savef (symbol-function 'gnuplot-debug-on)))
	(unload-feature 'gnuplot-debug-context)
	(fset 'gnuplot-debug-on savef)))
  (gnuplot-recompile))

(defun gnuplot-debug-on ()
  (interactive)
  (unless (featurep 'gnuplot-debug-context)
    (load-library "gnuplot-debug-context"))
  (gnuplot-recompile))

(defmacro with-gnuplot-trace-buffer (&rest body)
  `(with-current-buffer (get-buffer-create "gnuplot-trace")
     ,@body))

(defmacro gnuplot-debug (&rest args)
  `(progn ,@args))

(defmacro gnuplot-trace (&rest args)
  `(with-gnuplot-trace-buffer (insert (format ,@args))))

(defun gnuplot-backtrace ()
  (if stack
      (with-gnuplot-trace-buffer
       (insert "\n-- * backtrace: * --\n")
       (dolist (x stack)
	 (insert (format "%s\n"
			 (if (eq (car x) 'return)
			     x
			   (list (car x) (cadr x)
				 (gnuplot-simplify-tokens (caddr x)))))))
       (insert "-- end backtrace  --\n"))))

(defun gnuplot-dump-backtrack (backtrack)
  (if backtrack
      (with-gnuplot-trace-buffer
       (insert "\n-- * backtrack records: * --\n")
       (dolist (x backtrack)
	 (insert (format "%s\t%s\n" (caddr x) (gnuplot-simplify-tokens (cadr x)))))
       (insert "-- end backtrack records  --\n\n"))))

(defun gnuplot-dump-progress (progress)
  (if progress
      (with-gnuplot-trace-buffer
       (insert "\n-- * progress records: * --\n")
       (dolist (x progress)
	 (insert (format "%s\t%s\n" (car x) (gnuplot-simplify-tokens (cdr x)))))
       (insert "-- end progress records  --\n\n"))))

(defun gnuplot-dump-code (&optional inst)
  (interactive)
  (let ((inst (or inst gnuplot-compiled-grammar)))
    (with-gnuplot-trace-buffer
     (insert "\n-- * compiled code: * --\n")
     (dotimes (i (length inst))
       (insert (format "%s\t%s\n" i (aref inst i))))
     (insert "--  end compiled code --\n\n")
     (pop-to-buffer (current-buffer)))))

(defun gnuplot-dump-captures ()
  (interactive)
  (if gnuplot-captures
      (with-gnuplot-trace-buffer
       (insert "\n-- * capture groups: * --\n")
       (loop for c on gnuplot-captures
	     do
	     (let ((name (caar c))
		   (gnuplot-captures c))
	       (insert (format "%s\t%s\n"
			       name
			       (mapconcat 'gnuplot-token-id
					  (gnuplot-capture-group name)
					  " ")))))
       (insert "-- end capture groups  --\n\n"))))

(provide 'gnuplot-debug-context)

(gnuplot-debug-on)