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: %d 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: %d 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 19)))
81 (dolist (undo-elem first-ten)
82 (princ (format "%2s: %s\n" (position undo-elem first-ten) (truncate-string-to-width (format "%s" undo-elem) 70))))))))
84 (defun yas--debug-format-fom-concise (fom)
86 (cond ((yas--field-p fom)
87 (format "field %d from %d to %d"
88 (yas--field-number fom)
89 (marker-position (yas--field-start fom))
90 (marker-position (yas--field-end fom))))
92 (format "mirror from %d to %d"
93 (marker-position (yas--mirror-start fom))
94 (marker-position (yas--mirror-end fom))))
96 (format "snippet exit at %d"
97 (marker-position (yas--fom-start fom)))))))
100 (defun yas-exterminate-package ()
104 (mapatoms #'(lambda (atom)
105 (when (string-match "yas[-/]" (symbol-name atom))
106 (unintern atom obarray)))))
108 (defun yas-debug-test (&optional quiet)
110 (yas-load-directory (or (and (listp yas-snippet-dirs)
111 (first yas-snippet-dirs))
113 "~/Source/yasnippet/snippets/"))
114 (set-buffer (switch-to-buffer "*YAS TEST*"))
115 (mapc #'yas--commit-snippet (yas--snippets-at-point 'all-snippets))
117 (setq buffer-undo-list nil)
118 (setq undo-in-progress nil)
125 (add-hook 'post-command-hook 'yas-debug-snippet-vars 't 'local)))
127 (provide 'yasnippet-debug)
129 ;; indent-tabs-mode: nil
130 ;; byte-compile-warnings: (not cl-functions)
132 ;;; yasnippet-debug.el ends here