-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Evaluated on load or require
-;;
-;; ;;;### eval this on require!
-;; (progn
-;; (yas/init-minor-keymap))
-
-;; ;;;### eval this on require!
-;; (progn
-;; (yas/init-major-keymap))
-
-;; ;;;### eval this on require!
-;; (progn
-;; (when yas/root-directory
-;; (yas/reload-all)))
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;; Debug functions. Use (or change) at will whenever needed.
-;;
-;; some useful debug code for looking up snippet tables
-;;
-;; (insert (pp
-;; (let ((shit))
-;; (maphash #'(lambda (k v)
-;; (push k shit))
-;; (yas/snippet-table-hash (gethash 'ruby-mode yas/snippet-tables)))
-;; shit)))
-;;
-
-(defun yas/debug-tables ()
- (interactive)
- (with-output-to-temp-buffer "*YASnippet tables*"
- (dolist (symbol (remove nil (append (list major-mode)
- (if (listp yas/mode-symbol)
- yas/mode-symbol
- (list yas/mode-symbol)))))
- (princ (format "Snippet table hash keys for %s:\n\n" symbol))
- (let ((keys))
- (maphash #'(lambda (k v)
- (push k keys))
- (yas/snippet-table-hash (gethash symbol yas/snippet-tables)))
- (princ keys))
-
- (princ (format "Keymap for %s:\n\n" symbol))
- (princ (gethash symbol yas/menu-table)))))
-
-(defun yas/debug-snippet-vars ()
- "Debug snippets, fields, mirrors and the `buffer-undo-list'."
- (interactive)
- (with-output-to-temp-buffer "*YASnippet trace*"
- (princ "Interesting YASnippet vars: \n\n")
-
- (princ (format "\nPost command hook: %s\n" post-command-hook))
- (princ (format "\nPre command hook: %s\n" pre-command-hook))
-
- (princ (format "%s live snippets in total\n" (length (yas/snippets-at-point (quote all-snippets)))))
- (princ (format "%s overlays in buffer:\n\n" (length (overlays-in (point-min) (point-max)))))
- (princ (format "%s live snippets at point:\n\n" (length (yas/snippets-at-point))))
-
-
- (dolist (snippet (yas/snippets-at-point))
- (princ (format "\tsid: %d control overlay from %d to %d\n"
- (yas/snippet-id snippet)
- (overlay-start (yas/snippet-control-overlay snippet))
- (overlay-end (yas/snippet-control-overlay snippet))))
- (princ (format "\tactive field: %d from %s to %s covering \"%s\"\n"
- (yas/field-number (yas/snippet-active-field snippet))
- (marker-position (yas/field-start (yas/snippet-active-field snippet)))
- (marker-position (yas/field-end (yas/snippet-active-field snippet)))
- (buffer-substring-no-properties (yas/field-start (yas/snippet-active-field snippet)) (yas/field-end (yas/snippet-active-field snippet)))))
- (when (yas/snippet-exit snippet)
- (princ (format "\tsnippet-exit: at %s next: %s\n"
- (yas/exit-marker (yas/snippet-exit snippet))
- (yas/exit-next (yas/snippet-exit snippet)))))
- (dolist (field (yas/snippet-fields snippet))
- (princ (format "\tfield: %d from %s to %s covering \"%s\" next: %s\n"
- (yas/field-number field)
- (marker-position (yas/field-start field))
- (marker-position (yas/field-end field))
- (buffer-substring-no-properties (yas/field-start field) (yas/field-end field))
- (yas/debug-format-fom-concise (yas/field-next field))))
- (dolist (mirror (yas/field-mirrors field))
- (princ (format "\t\tmirror: from %s to %s covering \"%s\" next: %s\n"
- (marker-position (yas/mirror-start mirror))
- (marker-position (yas/mirror-end mirror))
- (buffer-substring-no-properties (yas/mirror-start mirror) (yas/mirror-end mirror))
- (yas/debug-format-fom-concise (yas/mirror-next mirror)))))))
-
- (princ (format "\nUndo is %s and point-max is %s.\n"
- (if (eq buffer-undo-list t)
- "DISABLED"
- "ENABLED")
- (point-max)))
- (unless (eq buffer-undo-list t)
- (princ (format "Undpolist has %s elements. First 10 elements follow:\n" (length buffer-undo-list)))
- (let ((first-ten (subseq buffer-undo-list 0 19)))
- (dolist (undo-elem first-ten)
- (princ (format "%2s: %s\n" (position undo-elem first-ten) (truncate-string-to-width (format "%s" undo-elem) 70))))))))
-
-(defun yas/debug-format-fom-concise (fom)
- (when fom
- (cond ((yas/field-p fom)
- (format "field %d from %d to %d"
- (yas/field-number fom)
- (marker-position (yas/field-start fom))
- (marker-position (yas/field-end fom))))
- ((yas/mirror-p fom)
- (format "mirror from %d to %d"
- (marker-position (yas/mirror-start fom))
- (marker-position (yas/mirror-end fom))))
- (t
- (format "snippet exit at %d"
- (marker-position (yas/fom-start fom)))))))
-
-
-(defun yas/exterminate-package ()
- (interactive)
- (yas/global-mode -1)
- (yas/minor-mode -1)
- (yas/kill-snippet-keybindings)
- (mapatoms #'(lambda (atom)
- (when (string-match "yas/" (symbol-name atom))
- (unintern atom)))))
-
-(defun yas/debug-test (&optional quiet)
- (interactive "P")
- (yas/load-directory (or (and (listp yas/root-directory)
- (first yas/root-directory))
- yas/root-directory
- "~/Source/yasnippet/snippets/"))
- (set-buffer (switch-to-buffer "*YAS TEST*"))
- (mapc #'yas/commit-snippet (yas/snippets-at-point 'all-snippets))
- (erase-buffer)
- (setq buffer-undo-list nil)
- (setq undo-in-progress nil)
- (snippet-mode)
- (yas/minor-mode 1)
- (let ((abbrev))
- (setq abbrev "$f")
- (insert abbrev))
- (unless quiet
- (add-hook 'post-command-hook 'yas/debug-snippet-vars 't 'local)))
-
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
-;;; `locate-dominating-file' is added for compatibility in emacs < 23
-(unless (or (eq emacs-major-version 23)
- (fboundp 'locate-dominating-file))
- (defvar locate-dominating-stop-dir-regexp
- "\\`\\(?:[\\/][\\/][^\\/]+[\\/]\\|/\\(?:net\\|afs\\|\\.\\.\\.\\)/\\)\\'"
- "Regexp of directory names which stop the search in `locate-dominating-file'.