Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 129 lines (107 sloc) 5.741 kB
affd244 @capitaomorte * Help display for snippet keybindings much cleaner.
authored
1 ;;; yasnippet-debug.el --- debug functions for yasnippet
2
3 ;; Copyright (C) 2010 João Távora
4
5 ;; Author: João Távora(defun yas/debug-snippet-vars () <joaotavora@gmail.com>
6 ;; Keywords: emulations, convenience
7
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.
12
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.
17
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/>.
20
21 ;;; Commentary:
22
23 ;; Just some debug functions
24
25 ;;; Code:
26
27 (require 'yasnippet)
28
29 (defun yas/debug-snippet-vars ()
30 "Debug snippets, fields, mirrors and the `buffer-undo-list'."
31 (interactive)
32 (with-output-to-temp-buffer "*YASnippet trace*"
33 (princ "Interesting YASnippet vars: \n\n")
34
35 (princ (format "\nPost command hook: %s\n" post-command-hook))
36 (princ (format "\nPre command hook: %s\n" pre-command-hook))
37
38 (princ (format "%s live snippets in total\n" (length (yas/snippets-at-point (quote all-snippets)))))
39 (princ (format "%s overlays in buffer:\n\n" (length (overlays-in (point-min) (point-max)))))
40 (princ (format "%s live snippets at point:\n\n" (length (yas/snippets-at-point))))
41
42
43 (dolist (snippet (yas/snippets-at-point))
44 (princ (format "\tsid: %d control overlay from %d to %d\n"
45 (yas/snippet-id snippet)
46 (overlay-start (yas/snippet-control-overlay snippet))
47 (overlay-end (yas/snippet-control-overlay snippet))))
48 (princ (format "\tactive field: %d from %s to %s covering \"%s\"\n"
49 (yas/field-number (yas/snippet-active-field snippet))
50 (marker-position (yas/field-start (yas/snippet-active-field snippet)))
51 (marker-position (yas/field-end (yas/snippet-active-field snippet)))
52 (buffer-substring-no-properties (yas/field-start (yas/snippet-active-field snippet)) (yas/field-end (yas/snippet-active-field snippet)))))
53 (when (yas/snippet-exit snippet)
54 (princ (format "\tsnippet-exit: at %s next: %s\n"
55 (yas/exit-marker (yas/snippet-exit snippet))
56 (yas/exit-next (yas/snippet-exit snippet)))))
57 (dolist (field (yas/snippet-fields snippet))
58 (princ (format "\tfield: %d from %s to %s covering \"%s\" next: %s%s\n"
59 (yas/field-number field)
60 (marker-position (yas/field-start field))
61 (marker-position (yas/field-end field))
62 (buffer-substring-no-properties (yas/field-start field) (yas/field-end field))
63 (yas/debug-format-fom-concise (yas/field-next field))
64 (if (yas/field-parent-field field) "(has a parent)" "")))
65 (dolist (mirror (yas/field-mirrors field))
66 (princ (format "\t\tmirror: from %s to %s covering \"%s\" next: %s\n"
67 (marker-position (yas/mirror-start mirror))
68 (marker-position (yas/mirror-end mirror))
69 (buffer-substring-no-properties (yas/mirror-start mirror) (yas/mirror-end mirror))
70 (yas/debug-format-fom-concise (yas/mirror-next mirror)))))))
71
72 (princ (format "\nUndo is %s and point-max is %s.\n"
73 (if (eq buffer-undo-list t)
74 "DISABLED"
75 "ENABLED")
76 (point-max)))
77 (unless (eq buffer-undo-list t)
78 (princ (format "Undpolist has %s elements. First 10 elements follow:\n" (length buffer-undo-list)))
79 (let ((first-ten (subseq buffer-undo-list 0 19)))
80 (dolist (undo-elem first-ten)
81 (princ (format "%2s: %s\n" (position undo-elem first-ten) (truncate-string-to-width (format "%s" undo-elem) 70))))))))
82
83 (defun yas/debug-format-fom-concise (fom)
84 (when fom
85 (cond ((yas/field-p fom)
86 (format "field %d from %d to %d"
87 (yas/field-number fom)
88 (marker-position (yas/field-start fom))
89 (marker-position (yas/field-end fom))))
90 ((yas/mirror-p fom)
91 (format "mirror from %d to %d"
92 (marker-position (yas/mirror-start fom))
93 (marker-position (yas/mirror-end fom))))
94 (t
95 (format "snippet exit at %d"
96 (marker-position (yas/fom-start fom)))))))
97
98
99 (defun yas/exterminate-package ()
100 (interactive)
101 (yas/global-mode -1)
102 (yas/minor-mode -1)
103 (mapatoms #'(lambda (atom)
104 (when (string-match "yas/" (symbol-name atom))
105 (unintern atom)))))
106
107 (defun yas/debug-test (&optional quiet)
108 (interactive "P")
109 (yas/load-directory (or (and (listp yas/snippet-dirs)
110 (first yas/snippet-dirs))
111 yas/snippet-dirs
112 "~/Source/yasnippet/snippets/"))
113 (set-buffer (switch-to-buffer "*YAS TEST*"))
114 (mapc #'yas/commit-snippet (yas/snippets-at-point 'all-snippets))
115 (erase-buffer)
116 (setq buffer-undo-list nil)
117 (setq undo-in-progress nil)
118 (snippet-mode)
119 (yas/minor-mode 1)
120 (let ((abbrev))
121 (setq abbrev "$f")
122 (insert abbrev))
123 (unless quiet
124 (add-hook 'post-command-hook 'yas/debug-snippet-vars 't 'local)))
125
126 (provide 'yasnippet-debug)
127 ;;; yasnippet-debug.el ends here
128
Something went wrong with that request. Please try again.