(save-match-data
(eval condition))))
(error (progn
- (message (format "[yas] error in condition evaluation: %s"
- (error-message-string err)))
+ (yas/message 1 "Error in condition evaluation: %s" (error-message-string err))
nil))))
(when result
(format "%s" result))))))
(error (if yas/good-grace
- (format "[yas] elisp error! %s" (error-message-string err))
- (error (format "[yas] elisp error: %s"
+ (yas/format "elisp error! %s" (error-message-string err))
+ (error (yas/format "elisp error: %s"
(error-message-string err)))))))))
(when (and (consp retval)
(eq 'yas/exception (car retval)))
(condition-case err
(eval form)
(error (if yas/good-grace
- (format "[yas] elisp error! %s" (error-message-string err))
- (error (format "[yas] elisp error: %s"
+ (yas/format "elisp error! %s" (error-message-string err))
+ (error (yas/format "elisp error: %s"
(error-message-string err)))))))
(defun yas/read-lisp (string &optional nil-on-error)
(read-kbd-macro keybinding 'need-vector))))
res)
(error
- (message "[yas] warning: keybinding \"%s\" invalid since %s."
+ (yas/message 3 "warning: keybinding \"%s\" invalid since %s."
keybinding (error-message-string err))
nil))))
(car major-mode-and-parents)
(cdr major-mode-and-parents))))
(when (interactive-p)
- (message "[yas] Loaded snippets from %s." top-level-dir)))
+ (yas/message 3 "Loaded snippets from %s." top-level-dir)))
(defun yas/load-snippet-dirs ()
"Reload the directories listed in `yas/snippet-dirs' or
(condition-case oops
(progn
(yas/load-directory directory)
- (message "[yas] Loaded %s" directory))
+ (yas/message 3 "Loaded %s" directory))
(error (push oops errors)
- (message "[yas] Check your `yas/snippet-dirs': %s" (second oops)))))
+ (yas/message 3 "Check your `yas/snippet-dirs': %s" (second oops)))))
(call-interactively 'yas/load-directory))
errors))
;; Reload the direct keybindings
;;
(yas/direct-keymaps-reload)
- (message "[yas] Reloaded everything...%s." (if errors " (some errors, check *Messages*)" ""))))
+ (yas/message 3 "Reloaded everything...%s." (if errors " (some errors, check *Messages*)" ""))))
(defun yas/quote-string (string)
"Escape and quote STRING.
(define-key keymap (vector (gensym))
'(menu-item "----")))
(t
- (message "[yas] don't know anything about menu entry %s" (first e))))))
+ (yas/message 3 "don't know anything about menu entry %s" (first e))))))
(defun yas/define (mode key template &optional name condition group)
"Define a snippet. Expanding KEY into TEMPLATE.
(car where)
(cdr where)
(yas/template-expand-env yas/current-template))
- (message "[yas] No snippets can be inserted here!"))))
+ (yas/message 3 "No snippets can be inserted here!"))))
(defun yas/visit-snippet-file ()
"Choose a snippet to edit, selection like `yas/insert-snippet'.
(or (some #'(lambda (dir) (when (file-directory-p dir) dir)) (cdr table-and-dirs))
(let ((candidate (first (cdr table-and-dirs))))
(unless (file-writable-p (file-name-directory candidate))
- (error "[yas] %s is not writable." candidate))
+ (error (yas/format "%s is not writable." candidate)))
(if (y-or-n-p (format "Guessed directory (%s) for%s%s table \"%s\" does not exist! Create? "
candidate
(if (gethash (intern (yas/table-name (car table-and-dirs)))
(not (string-match (expand-file-name (first yas/snippet-dirs))
(yas/template-file yas/editing-template)))))
- (when (y-or-n-p "[yas] Looks like a library or new snippet. Save to new file? ")
+ (when (y-or-n-p (yas/format "Looks like a library or new snippet. Save to new file? "))
(let* ((option (first (yas/guess-snippet-directories (yas/template-table yas/editing-template))))
(chosen (and option
(yas/make-directory-maybe option))))
(setf (yas/template-file yas/editing-template) buffer-file-name))))))
(when kill
(quit-window kill))
- (message "[yas] Snippet \"%s\" loaded for %s."
+ (yas/message 3 "Snippet \"%s\" loaded for %s."
(yas/template-name yas/editing-template)
(yas/table-name (yas/template-table yas/editing-template))))
(fboundp (car major-mode-and-parent))
(car major-mode-and-parent))
(first yas/guessed-modes)
- (intern (read-from-minibuffer "[yas] please input a mode: "))))
+ (intern (read-from-minibuffer (yas/format "Please input a mode: ")))))
(yas/current-template
(and parsed
(fboundp test-mode)
(require 'yasnippet-debug nil t))
(add-hook 'post-command-hook 'yas/debug-snippet-vars nil t))))
(t
- (message "[yas] Cannot test snippet for unknown major mode")))))
+ (yas/message 3 "Cannot test snippet for unknown major mode")))))
(defun yas/template-fine-group (template)
(car (last (or (yas/template-group template)
Otherwise throw exception."
(when (and yas/moving-away-p (notany #'(lambda (pos) (string= pos yas/text)) possibilities))
- (yas/throw (format "[yas] field only allows %s" possibilities))))
+ (yas/throw (yas/format "Field only allows %s" possibilities))))
(defun yas/field-value (number)
"Get the string for field with NUMBER.
;; again from `yas/take-care-of-redo'....
(setf (yas/snippet-fields snippet) nil)))
- (message "[yas] snippet %s exited." (yas/snippet-id snippet)))
+ (yas/message 3 "snippet %s exited." (yas/snippet-id snippet)))
(defun yas/safely-run-hooks (hook-var)
(condition-case error
(run-hooks hook-var)
(error
- (message "[yas] %s error: %s" hook-var (error-message-string error)))))
+ (yas/message 3 "%s error: %s" hook-var (error-message-string error)))))
(defun yas/check-commit-snippet ()
(when first-field
(sit-for 0) ;; fix issue 125
(yas/move-to-field snippet first-field)))
- (message "[yas] snippet expanded.")
+ (yas/message 3 "snippet expanded.")
t))))
(defun yas/take-care-of-redo (beg end snippet)
(widen)
(condition-case err
(indent-according-to-mode)
- (error (message "[yas] warning: yas/indent-according-to-mode habing problems running %s" indent-line-function)
+ (error (yas/message 3 "warning: yas/indent-according-to-mode habing problems running %s" indent-line-function)
nil)))
(mapc #'(lambda (marker)
(set-marker marker (point)))
(apply (car fn-and-args)
(cdr fn-and-args)))
yas/post-command-runonce-actions)
- (error (message "[yas] problem running `yas/post-command-runonce-actions'!")))
+ (error (yas/message 3 "problem running `yas/post-command-runonce-actions'!")))
(setq yas/post-command-runonce-actions nil))
(cond (yas/protection-violation
(goto-char yas/protection-violation)
(gethash uuid (yas/table-uuidhash table)))))
(when yas/current-template
(yas/expand-snippet (yas/template-content yas/current-template)))))
+\f
+;;; Utils
+;;;
+
+(defvar yas/verbosity 4
+ "Log level for `yas/message' 4 means trace most anything, 0 means nothing.")
+(defun yas/message (level message &rest args)
+ (when (> yas/verbosity level)
+ (message (apply #'yas/format message args))))
+
+(defun yas/format (format-control &rest format-args)
+ (apply #'format (concat "[yas] " format-control) format-args))
\f
;;; Some hacks: