1 ;;; yasnippet-debug.el --- debug functions for yasnippet
3 ;; Copyright (C) 2010, 2013, 2014 Free Software Foundation, Inc.
6 ;; Keywords: emulations, convenience
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ;; Just some debug functions
30 (defun yas-debug-snippet-vars ()
31 "Debug snippets, fields, mirrors and the `buffer-undo-list'."
33 (with-output-to-temp-buffer "*YASnippet trace*"
34 (princ "Interesting YASnippet vars: \n\n")
36 (princ (format "\nPost command hook: %s\n" post-command-hook))
37 (princ (format "\nPre command hook: %s\n" pre-command-hook))
39 (princ (format "%s live snippets in total\n" (length (yas--snippets-at-point (quote all-snippets)))))
40 (princ (format "%s overlays in buffer:\n\n" (length (overlays-in (point-min) (point-max)))))
41 (princ (format "%s live snippets at point:\n\n" (length (yas--snippets-at-point))))
44 (dolist (snippet (yas--snippets-at-point))
45 (princ (format "\tsid: %d control overlay from %d to %d\n"
46 (yas--snippet-id snippet)
47 (overlay-start (yas--snippet-control-overlay snippet))
48 (overlay-end (yas--snippet-control-overlay snippet))))
49 (princ (format "\tactive field: %s from %s to %s covering \"%s\"\n"
50 (yas--field-number (yas--snippet-active-field snippet))
51 (marker-position (yas--field-start (yas--snippet-active-field snippet)))
52 (marker-position (yas--field-end (yas--snippet-active-field snippet)))
53 (buffer-substring-no-properties (yas--field-start (yas--snippet-active-field snippet)) (yas--field-end (yas--snippet-active-field snippet)))))
54 (when (yas--snippet-exit snippet)
55 (princ (format "\tsnippet-exit: at %s next: %s\n"
56 (yas--exit-marker (yas--snippet-exit snippet))
57 (yas--exit-next (yas--snippet-exit snippet)))))
58 (dolist (field (yas--snippet-fields snippet))
59 (princ (format "\tfield: %s from %s to %s covering \"%s\" next: %s%s\n"
60 (yas--field-number field)
61 (marker-position (yas--field-start field))
62 (marker-position (yas--field-end field))
63 (buffer-substring-no-properties (yas--field-start field) (yas--field-end field))
64 (yas--debug-format-fom-concise (yas--field-next field))
65 (if (yas--field-parent-field field) "(has a parent)" "")))
66 (dolist (mirror (yas--field-mirrors field))
67 (princ (format "\t\tmirror: from %s to %s covering \"%s\" next: %s\n"
68 (marker-position (yas--mirror-start mirror))
69 (marker-position (yas--mirror-end mirror))
70 (buffer-substring-no-properties (yas--mirror-start mirror) (yas--mirror-end mirror))
71 (yas--debug-format-fom-concise (yas--mirror-next mirror)))))))
73 (princ (format "\nUndo is %s and point-max is %s.\n"
74 (if (eq buffer-undo-list t)
78 (unless (eq buffer-undo-list t)
79 (princ (format "Undpolist has %s elements. First 10 elements follow:\n" (length buffer-undo-list)))
80 (let ((first-ten (subseq buffer-undo-list 0 (min 19
81 (length buffer-undo-list)))))
82 (dolist (undo-elem first-ten)
83 (princ (format "%2s: %s\n" (position undo-elem first-ten) (truncate-string-to-width (format "%s" undo-elem) 70))))))))
85 (defun yas--debug-format-fom-concise (fom)
87 (cond ((yas--field-p fom)
88 (format "field %s from %d to %d"
89 (yas--field-number fom)
90 (marker-position (yas--field-start fom))
91 (marker-position (yas--field-end fom))))
93 (format "mirror from %d to %d"
94 (marker-position (yas--mirror-start fom))
95 (marker-position (yas--mirror-end fom))))
97 (format "snippet exit at %d"
98 (marker-position (yas--fom-start fom)))))))
101 (defun yas-exterminate-package ()
105 (mapatoms #'(lambda (atom)
106 (when (string-match "yas[-/]" (symbol-name atom))
107 (unintern atom obarray)))))
109 (defun yas-debug-test (&optional quiet)
111 (yas-load-directory (or (and (listp yas-snippet-dirs)
112 (first yas-snippet-dirs))
114 "~/Source/yasnippet/snippets/"))
115 (set-buffer (switch-to-buffer "*YAS TEST*"))
116 (mapc #'yas--commit-snippet (yas--snippets-at-point 'all-snippets))
118 (setq buffer-undo-list nil)
119 (setq undo-in-progress nil)
126 (add-hook 'post-command-hook 'yas-debug-snippet-vars 't 'local)))
128 (provide 'yasnippet-debug)
130 ;; indent-tabs-mode: nil
131 ;; byte-compile-warnings: (not cl-functions)
133 ;;; yasnippet-debug.el ends here