Closes #574: Simplify error reporting for invalid `yas-snippet-dirs'

* yasnippet.el (yas-snippet-dirs, yas--read-keybinding)
(yas--indent-according-to-mode): Use `yas--warning'.
(yas-load-directory): Use `yas--message' only here to inform on
loading.
(yas--load-snippet-dirs): Deleted.
(yas-reload-all): Call `yas-load-directory' directly. Simplify
error reporting.
(yas--guess-snippet-directories): Don't silently set
`yas-snippet-dirs'.
This commit is contained in:
João Távora 2015-05-21 10:04:59 +01:00
parent 197db9fc22
commit 5d44edb34d

View File

@ -182,19 +182,25 @@ created with `yas-new-snippet'. "
(equal old new)) (equal old new))
(yas-reload-all))))) (yas-reload-all)))))
(defun yas-snippet-dirs () (defun yas-snippet-dirs (&optional silent)
"Return variable `yas-snippet-dirs' as list of strings." "Return variable `yas-snippet-dirs' as list of strings.
If SILENT is non-nil, don't issue warnings on inexistent or
unreadable directories. "
(cl-loop for e in (if (listp yas-snippet-dirs) (cl-loop for e in (if (listp yas-snippet-dirs)
yas-snippet-dirs yas-snippet-dirs
(list yas-snippet-dirs)) (list yas-snippet-dirs))
collect for value = (cond ((stringp e) e)
(cond ((stringp e) e) ((and (symbolp e)
((and (symbolp e) (boundp e)
(boundp e) (stringp (symbol-value e)))
(stringp (symbol-value e))) (symbol-value e))
(symbol-value e)) (t
(t (error "[yas] invalid element %s in `yas-snippet-dirs'" e)))
(error "[yas] invalid element %s in `yas-snippet-dirs'" e))))) if (and (file-readable-p value)
(file-directory-p value))
collect value
else if (not silent)
do (yas--warning "%s is not a valid readable directory in `yas-snippet-dirs'" value)))
(defvaralias 'yas/root-directory 'yas-snippet-dirs) (defvaralias 'yas/root-directory 'yas-snippet-dirs)
@ -1317,8 +1323,8 @@ return an expression that when evaluated will issue an error."
(read-kbd-macro keybinding 'need-vector)))) (read-kbd-macro keybinding 'need-vector))))
res) res)
(error (error
(yas--message 3 "warning: keybinding \"%s\" invalid since %s." (yas--warning "keybinding \"%s\" invalid since %s."
keybinding (error-message-string err)) keybinding (error-message-string err))
nil)))) nil))))
(defun yas--table-get-create (mode) (defun yas--table-get-create (mode)
@ -1765,8 +1771,9 @@ With prefix argument USE-JIT do jit-loading of snippets."
;; ;;
(cl-loop for buffer in impatient-buffers (cl-loop for buffer in impatient-buffers
do (with-current-buffer buffer (yas--load-pending-jits)))) do (with-current-buffer buffer (yas--load-pending-jits))))
(when interactive (if use-jit
(yas--message 3 "Loaded snippets from %s." top-level-dir))) (yas--message 3 "Prepared jit-loading of %s" directory)
(yas--message 3 "Loaded %s" directory)))
(defun yas--load-directory-1 (directory mode-sym) (defun yas--load-directory-1 (directory mode-sym)
"Recursively load snippet templates from DIRECTORY." "Recursively load snippet templates from DIRECTORY."
@ -1809,22 +1816,6 @@ With prefix argument USE-JIT do jit-loading of snippets."
(yas--load-directory-2 subdir (yas--load-directory-2 subdir
mode-sym)))) mode-sym))))
(defun yas--load-snippet-dirs (&optional nojit)
"Reload the directories listed in `yas-snippet-dirs' or
prompt the user to select one."
(let (errors)
(if yas-snippet-dirs
(dolist (directory (reverse (yas-snippet-dirs)))
(cond ((file-directory-p directory)
(yas-load-directory directory (not nojit))
(if nojit
(yas--message 3 "Loaded %s" directory)
(yas--message 3 "Prepared just-in-time loading for %s" directory)))
(t
(push (yas--message 0 "Check your `yas-snippet-dirs': %s is not a directory" directory) errors))))
(call-interactively 'yas-load-directory))
errors))
(defun yas-reload-all (&optional no-jit interactive) (defun yas-reload-all (&optional no-jit interactive)
"Reload all snippets and rebuild the YASnippet menu. "Reload all snippets and rebuild the YASnippet menu.
@ -1876,18 +1867,16 @@ prefix argument."
;; ;;
(setq yas--scheduled-jit-loads (make-hash-table)) (setq yas--scheduled-jit-loads (make-hash-table))
;; Reload the directories listed in `yas-snippet-dirs' or prompt ;; Reload the directories listed in `yas-snippet-dirs'
;; the user to select one.
;; ;;
(setq errors (yas--load-snippet-dirs no-jit)) (mapc #'yas-load-directory (reverse (yas-snippet-dirs)))
;; Reload the direct keybindings ;; Reload the direct keybindings
;; ;;
(yas-direct-keymaps-reload) (yas-direct-keymaps-reload)
(run-hooks 'yas-after-reload-hook) (run-hooks 'yas-after-reload-hook)
(yas--message 3 "Reloaded everything%s...%s." (yas--message 3 "Reloaded everything%s...%s."
(if no-jit "" " (snippets will load just-in-time)") (if no-jit "" " (snippets will load just-in-time)")))))
(if errors " (some errors, check *Messages*)" "")))))
(defvar yas-after-reload-hook nil (defvar yas-after-reload-hook nil
"Hooks run after `yas-reload-all'.") "Hooks run after `yas-reload-all'.")
@ -2396,8 +2385,10 @@ Returns a list of elements (TABLE . DIRS) where TABLE is a
where snippets of table might exist." where snippets of table might exist."
(let ((main-dir (replace-regexp-in-string (let ((main-dir (replace-regexp-in-string
"/+$" "" "/+$" ""
(or (first (or (yas-snippet-dirs) (or (first (yas-snippet-dirs 'silent))
(setq yas-snippet-dirs '("~/.emacs.d/snippets"))))))) (progn
(yas--warning "No valid `yas-snippet-dirs', using \"~/.emacs.d/snippets\"")
"~/.emacs.d/snippets"))))
(tables (or (and table (tables (or (and table
(list table)) (list table))
(yas--get-snippet-tables)))) (yas--get-snippet-tables))))
@ -3875,7 +3866,7 @@ Meant to be called in a narrowed buffer, does various passes"
(widen) (widen)
(condition-case _ (condition-case _
(indent-according-to-mode) (indent-according-to-mode)
(error (yas--message 3 "Warning: `yas--indent-according-to-mode' having problems running %s" indent-line-function) (error (yas--warning "`yas--indent-according-to-mode' having problems running %s" indent-line-function)
nil))) nil)))
(mapc #'(lambda (marker) (mapc #'(lambda (marker)
(set-marker marker (point))) (set-marker marker (point)))