Path: blob/master/elisp/emacs-for-python/yasnippet/yasnippet-debug.el
990 views
;;; yasnippet-debug.el --- debug functions for yasnippet12;; Copyright (C) 2010 João Távora34;; Author: João Távora(defun yas/debug-snippet-vars () <[email protected]>5;; Keywords: emulations, convenience67;; This program is free software; you can redistribute it and/or modify8;; it under the terms of the GNU General Public License as published by9;; the Free Software Foundation, either version 3 of the License, or10;; (at your option) any later version.1112;; This program is distributed in the hope that it will be useful,13;; but WITHOUT ANY WARRANTY; without even the implied warranty of14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the15;; GNU General Public License for more details.1617;; You should have received a copy of the GNU General Public License18;; along with this program. If not, see <http://www.gnu.org/licenses/>.1920;;; Commentary:2122;; Just some debug functions2324;;; Code:2526(require 'yasnippet)2728(defun yas/debug-snippet-vars ()29"Debug snippets, fields, mirrors and the `buffer-undo-list'."30(interactive)31(with-output-to-temp-buffer "*YASnippet trace*"32(princ "Interesting YASnippet vars: \n\n")3334(princ (format "\nPost command hook: %s\n" post-command-hook))35(princ (format "\nPre command hook: %s\n" pre-command-hook))3637(princ (format "%s live snippets in total\n" (length (yas/snippets-at-point (quote all-snippets)))))38(princ (format "%s overlays in buffer:\n\n" (length (overlays-in (point-min) (point-max)))))39(princ (format "%s live snippets at point:\n\n" (length (yas/snippets-at-point))))404142(dolist (snippet (yas/snippets-at-point))43(princ (format "\tsid: %d control overlay from %d to %d\n"44(yas/snippet-id snippet)45(overlay-start (yas/snippet-control-overlay snippet))46(overlay-end (yas/snippet-control-overlay snippet))))47(princ (format "\tactive field: %d from %s to %s covering \"%s\"\n"48(yas/field-number (yas/snippet-active-field snippet))49(marker-position (yas/field-start (yas/snippet-active-field snippet)))50(marker-position (yas/field-end (yas/snippet-active-field snippet)))51(buffer-substring-no-properties (yas/field-start (yas/snippet-active-field snippet)) (yas/field-end (yas/snippet-active-field snippet)))))52(when (yas/snippet-exit snippet)53(princ (format "\tsnippet-exit: at %s next: %s\n"54(yas/exit-marker (yas/snippet-exit snippet))55(yas/exit-next (yas/snippet-exit snippet)))))56(dolist (field (yas/snippet-fields snippet))57(princ (format "\tfield: %d from %s to %s covering \"%s\" next: %s%s\n"58(yas/field-number field)59(marker-position (yas/field-start field))60(marker-position (yas/field-end field))61(buffer-substring-no-properties (yas/field-start field) (yas/field-end field))62(yas/debug-format-fom-concise (yas/field-next field))63(if (yas/field-parent-field field) "(has a parent)" "")))64(dolist (mirror (yas/field-mirrors field))65(princ (format "\t\tmirror: from %s to %s covering \"%s\" next: %s\n"66(marker-position (yas/mirror-start mirror))67(marker-position (yas/mirror-end mirror))68(buffer-substring-no-properties (yas/mirror-start mirror) (yas/mirror-end mirror))69(yas/debug-format-fom-concise (yas/mirror-next mirror)))))))7071(princ (format "\nUndo is %s and point-max is %s.\n"72(if (eq buffer-undo-list t)73"DISABLED"74"ENABLED")75(point-max)))76(unless (eq buffer-undo-list t)77(princ (format "Undpolist has %s elements. First 10 elements follow:\n" (length buffer-undo-list)))78(let ((first-ten (subseq buffer-undo-list 0 19)))79(dolist (undo-elem first-ten)80(princ (format "%2s: %s\n" (position undo-elem first-ten) (truncate-string-to-width (format "%s" undo-elem) 70))))))))8182(defun yas/debug-format-fom-concise (fom)83(when fom84(cond ((yas/field-p fom)85(format "field %d from %d to %d"86(yas/field-number fom)87(marker-position (yas/field-start fom))88(marker-position (yas/field-end fom))))89((yas/mirror-p fom)90(format "mirror from %d to %d"91(marker-position (yas/mirror-start fom))92(marker-position (yas/mirror-end fom))))93(t94(format "snippet exit at %d"95(marker-position (yas/fom-start fom)))))))969798(defun yas/exterminate-package ()99(interactive)100(yas/global-mode -1)101(yas/minor-mode -1)102(mapatoms #'(lambda (atom)103(when (string-match "yas/" (symbol-name atom))104(unintern atom)))))105106(defun yas/debug-test (&optional quiet)107(interactive "P")108(yas/load-directory (or (and (listp yas/snippet-dirs)109(first yas/snippet-dirs))110yas/snippet-dirs111"~/Source/yasnippet/snippets/"))112(set-buffer (switch-to-buffer "*YAS TEST*"))113(mapc #'yas/commit-snippet (yas/snippets-at-point 'all-snippets))114(erase-buffer)115(setq buffer-undo-list nil)116(setq undo-in-progress nil)117(snippet-mode)118(yas/minor-mode 1)119(let ((abbrev))120(setq abbrev "$f")121(insert abbrev))122(unless quiet123(add-hook 'post-command-hook 'yas/debug-snippet-vars 't 'local)))124125(provide 'yasnippet-debug)126;;; yasnippet-debug.el ends here127128129130