Emacs config utilizing prelude as a base
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

128 lines
5.6 KiB

  1. ;;; yasnippet-debug.el --- debug functions for yasnippet
  2. ;; Copyright (C) 2010 João Távora
  3. ;; Author: João Távora(defun yas/debug-snippet-vars () <joaotavora@gmail.com>
  4. ;; Keywords: emulations, convenience
  5. ;; This program is free software; you can redistribute it and/or modify
  6. ;; it under the terms of the GNU General Public License as published by
  7. ;; the Free Software Foundation, either version 3 of the License, or
  8. ;; (at your option) any later version.
  9. ;; This program is distributed in the hope that it will be useful,
  10. ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ;; GNU General Public License for more details.
  13. ;; You should have received a copy of the GNU General Public License
  14. ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. ;;; Commentary:
  16. ;; Just some debug functions
  17. ;;; Code:
  18. (require 'yasnippet)
  19. (defun yas/debug-snippet-vars ()
  20. "Debug snippets, fields, mirrors and the `buffer-undo-list'."
  21. (interactive)
  22. (with-output-to-temp-buffer "*YASnippet trace*"
  23. (princ "Interesting YASnippet vars: \n\n")
  24. (princ (format "\nPost command hook: %s\n" post-command-hook))
  25. (princ (format "\nPre command hook: %s\n" pre-command-hook))
  26. (princ (format "%s live snippets in total\n" (length (yas/snippets-at-point (quote all-snippets)))))
  27. (princ (format "%s overlays in buffer:\n\n" (length (overlays-in (point-min) (point-max)))))
  28. (princ (format "%s live snippets at point:\n\n" (length (yas/snippets-at-point))))
  29. (dolist (snippet (yas/snippets-at-point))
  30. (princ (format "\tsid: %d control overlay from %d to %d\n"
  31. (yas/snippet-id snippet)
  32. (overlay-start (yas/snippet-control-overlay snippet))
  33. (overlay-end (yas/snippet-control-overlay snippet))))
  34. (princ (format "\tactive field: %d from %s to %s covering \"%s\"\n"
  35. (yas/field-number (yas/snippet-active-field snippet))
  36. (marker-position (yas/field-start (yas/snippet-active-field snippet)))
  37. (marker-position (yas/field-end (yas/snippet-active-field snippet)))
  38. (buffer-substring-no-properties (yas/field-start (yas/snippet-active-field snippet)) (yas/field-end (yas/snippet-active-field snippet)))))
  39. (when (yas/snippet-exit snippet)
  40. (princ (format "\tsnippet-exit: at %s next: %s\n"
  41. (yas/exit-marker (yas/snippet-exit snippet))
  42. (yas/exit-next (yas/snippet-exit snippet)))))
  43. (dolist (field (yas/snippet-fields snippet))
  44. (princ (format "\tfield: %d from %s to %s covering \"%s\" next: %s%s\n"
  45. (yas/field-number field)
  46. (marker-position (yas/field-start field))
  47. (marker-position (yas/field-end field))
  48. (buffer-substring-no-properties (yas/field-start field) (yas/field-end field))
  49. (yas/debug-format-fom-concise (yas/field-next field))
  50. (if (yas/field-parent-field field) "(has a parent)" "")))
  51. (dolist (mirror (yas/field-mirrors field))
  52. (princ (format "\t\tmirror: from %s to %s covering \"%s\" next: %s\n"
  53. (marker-position (yas/mirror-start mirror))
  54. (marker-position (yas/mirror-end mirror))
  55. (buffer-substring-no-properties (yas/mirror-start mirror) (yas/mirror-end mirror))
  56. (yas/debug-format-fom-concise (yas/mirror-next mirror)))))))
  57. (princ (format "\nUndo is %s and point-max is %s.\n"
  58. (if (eq buffer-undo-list t)
  59. "DISABLED"
  60. "ENABLED")
  61. (point-max)))
  62. (unless (eq buffer-undo-list t)
  63. (princ (format "Undpolist has %s elements. First 10 elements follow:\n" (length buffer-undo-list)))
  64. (let ((first-ten (subseq buffer-undo-list 0 19)))
  65. (dolist (undo-elem first-ten)
  66. (princ (format "%2s: %s\n" (position undo-elem first-ten) (truncate-string-to-width (format "%s" undo-elem) 70))))))))
  67. (defun yas/debug-format-fom-concise (fom)
  68. (when fom
  69. (cond ((yas/field-p fom)
  70. (format "field %d from %d to %d"
  71. (yas/field-number fom)
  72. (marker-position (yas/field-start fom))
  73. (marker-position (yas/field-end fom))))
  74. ((yas/mirror-p fom)
  75. (format "mirror from %d to %d"
  76. (marker-position (yas/mirror-start fom))
  77. (marker-position (yas/mirror-end fom))))
  78. (t
  79. (format "snippet exit at %d"
  80. (marker-position (yas/fom-start fom)))))))
  81. (defun yas/exterminate-package ()
  82. (interactive)
  83. (yas/global-mode -1)
  84. (yas/minor-mode -1)
  85. (mapatoms #'(lambda (atom)
  86. (when (string-match "yas/" (symbol-name atom))
  87. (unintern atom)))))
  88. (defun yas/debug-test (&optional quiet)
  89. (interactive "P")
  90. (yas/load-directory (or (and (listp yas/snippet-dirs)
  91. (first yas/snippet-dirs))
  92. yas/snippet-dirs
  93. "~/Source/yasnippet/snippets/"))
  94. (set-buffer (switch-to-buffer "*YAS TEST*"))
  95. (mapc #'yas/commit-snippet (yas/snippets-at-point 'all-snippets))
  96. (erase-buffer)
  97. (setq buffer-undo-list nil)
  98. (setq undo-in-progress nil)
  99. (snippet-mode)
  100. (yas/minor-mode 1)
  101. (let ((abbrev))
  102. (setq abbrev "$f")
  103. (insert abbrev))
  104. (unless quiet
  105. (add-hook 'post-command-hook 'yas/debug-snippet-vars 't 'local)))
  106. (provide 'yasnippet-debug)
  107. ;;; yasnippet-debug.el ends here