mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-13 13:13:03 +00:00
Merge branch 'master' into jit-loading
Minor conflicts (had already corrected spelling on some log lines...): yasnippet.el
This commit is contained in:
commit
ce85cffcfc
59
yasnippet.el
59
yasnippet.el
@ -1116,8 +1116,7 @@ string and TEMPLATE is a `yas/template' structure."
|
|||||||
(save-match-data
|
(save-match-data
|
||||||
(eval condition))))
|
(eval condition))))
|
||||||
(error (progn
|
(error (progn
|
||||||
(message (format "[yas] error in condition evaluation: %s"
|
(yas/message 1 "Error in condition evaluation: %s" (error-message-string err))
|
||||||
(error-message-string err)))
|
|
||||||
nil))))
|
nil))))
|
||||||
|
|
||||||
|
|
||||||
@ -1238,8 +1237,8 @@ a list of modes like this to help the judgement."
|
|||||||
(when result
|
(when result
|
||||||
(format "%s" result))))))
|
(format "%s" result))))))
|
||||||
(error (if yas/good-grace
|
(error (if yas/good-grace
|
||||||
(format "[yas] elisp error! %s" (error-message-string err))
|
(yas/format "elisp error! %s" (error-message-string err))
|
||||||
(error (format "[yas] elisp error: %s"
|
(error (yas/format "elisp error: %s"
|
||||||
(error-message-string err)))))))))
|
(error-message-string err)))))))))
|
||||||
(when (and (consp retval)
|
(when (and (consp retval)
|
||||||
(eq 'yas/exception (car retval)))
|
(eq 'yas/exception (car retval)))
|
||||||
@ -1250,8 +1249,8 @@ a list of modes like this to help the judgement."
|
|||||||
(condition-case err
|
(condition-case err
|
||||||
(eval form)
|
(eval form)
|
||||||
(error (if yas/good-grace
|
(error (if yas/good-grace
|
||||||
(format "[yas] elisp error! %s" (error-message-string err))
|
(yas/format "elisp error! %s" (error-message-string err))
|
||||||
(error (format "[yas] elisp error: %s"
|
(error (yas/format "elisp error: %s"
|
||||||
(error-message-string err)))))))
|
(error-message-string err)))))))
|
||||||
|
|
||||||
(defun yas/read-lisp (string &optional nil-on-error)
|
(defun yas/read-lisp (string &optional nil-on-error)
|
||||||
@ -1274,7 +1273,7 @@ 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
|
||||||
(message "[yas] warning: keybinding \"%s\" invalid since %s."
|
(yas/message 3 "warning: keybinding \"%s\" invalid since %s."
|
||||||
keybinding (error-message-string err))
|
keybinding (error-message-string err))
|
||||||
nil))))
|
nil))))
|
||||||
|
|
||||||
@ -1656,7 +1655,7 @@ Below TOP-LEVEL-DIR., each directory is a mode name."
|
|||||||
`(yas/load-directory-1 ,dir
|
`(yas/load-directory-1 ,dir
|
||||||
',mode-sym))))
|
',mode-sym))))
|
||||||
(when (interactive-p)
|
(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 ()
|
(defun yas/load-snippet-dirs ()
|
||||||
"Reload the directories listed in `yas/snippet-dirs' or
|
"Reload the directories listed in `yas/snippet-dirs' or
|
||||||
@ -1667,9 +1666,9 @@ Below TOP-LEVEL-DIR., each directory is a mode name."
|
|||||||
(condition-case oops
|
(condition-case oops
|
||||||
(progn
|
(progn
|
||||||
(yas/load-directory directory)
|
(yas/load-directory directory)
|
||||||
(message "[yas] Loaded %s" directory))
|
(yas/message 3 "Loaded %s" directory))
|
||||||
(error (push oops errors)
|
(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))
|
(call-interactively 'yas/load-directory))
|
||||||
errors))
|
errors))
|
||||||
|
|
||||||
@ -1700,7 +1699,7 @@ Below TOP-LEVEL-DIR., each directory is a mode name."
|
|||||||
;; Reload the direct keybindings
|
;; Reload the direct keybindings
|
||||||
;;
|
;;
|
||||||
(yas/direct-keymaps-reload)
|
(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)
|
(defun yas/quote-string (string)
|
||||||
"Escape and quote STRING.
|
"Escape and quote STRING.
|
||||||
@ -1979,7 +1978,7 @@ ommited from MODE's menu, even if they're manually loaded.
|
|||||||
(define-key keymap (vector (gensym))
|
(define-key keymap (vector (gensym))
|
||||||
'(menu-item "----")))
|
'(menu-item "----")))
|
||||||
(t
|
(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)
|
(defun yas/define (mode key template &optional name condition group)
|
||||||
"Define a snippet. Expanding KEY into TEMPLATE.
|
"Define a snippet. Expanding KEY into TEMPLATE.
|
||||||
@ -2178,7 +2177,7 @@ by condition."
|
|||||||
(car where)
|
(car where)
|
||||||
(cdr where)
|
(cdr where)
|
||||||
(yas/template-expand-env yas/current-template))
|
(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 ()
|
(defun yas/visit-snippet-file ()
|
||||||
"Choose a snippet to edit, selection like `yas/insert-snippet'.
|
"Choose a snippet to edit, selection like `yas/insert-snippet'.
|
||||||
@ -2267,7 +2266,7 @@ where snippets of table might exist."
|
|||||||
(or (some #'(lambda (dir) (when (file-directory-p dir) dir)) (cdr table-and-dirs))
|
(or (some #'(lambda (dir) (when (file-directory-p dir) dir)) (cdr table-and-dirs))
|
||||||
(let ((candidate (first (cdr table-and-dirs))))
|
(let ((candidate (first (cdr table-and-dirs))))
|
||||||
(unless (file-writable-p (file-name-directory candidate))
|
(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? "
|
(if (y-or-n-p (format "Guessed directory (%s) for%s%s table \"%s\" does not exist! Create? "
|
||||||
candidate
|
candidate
|
||||||
(if (gethash (intern (yas/table-name (car table-and-dirs)))
|
(if (gethash (intern (yas/table-name (car table-and-dirs)))
|
||||||
@ -2441,7 +2440,7 @@ With optional prefix argument KILL quit the window and buffer."
|
|||||||
(not (string-match (expand-file-name (first yas/snippet-dirs))
|
(not (string-match (expand-file-name (first yas/snippet-dirs))
|
||||||
(yas/template-file yas/editing-template)))))
|
(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))))
|
(let* ((option (first (yas/guess-snippet-directories (yas/template-table yas/editing-template))))
|
||||||
(chosen (and option
|
(chosen (and option
|
||||||
(yas/make-directory-maybe option))))
|
(yas/make-directory-maybe option))))
|
||||||
@ -2455,7 +2454,7 @@ With optional prefix argument KILL quit the window and buffer."
|
|||||||
(setf (yas/template-file yas/editing-template) buffer-file-name))))))
|
(setf (yas/template-file yas/editing-template) buffer-file-name))))))
|
||||||
(when kill
|
(when kill
|
||||||
(quit-window 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/template-name yas/editing-template)
|
||||||
(yas/table-name (yas/template-table yas/editing-template))))
|
(yas/table-name (yas/template-table yas/editing-template))))
|
||||||
|
|
||||||
@ -2469,7 +2468,7 @@ With optional prefix argument KILL quit the window and buffer."
|
|||||||
(fboundp (car major-mode-and-parent))
|
(fboundp (car major-mode-and-parent))
|
||||||
(car major-mode-and-parent))
|
(car major-mode-and-parent))
|
||||||
(first yas/guessed-modes)
|
(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
|
(yas/current-template
|
||||||
(and parsed
|
(and parsed
|
||||||
(fboundp test-mode)
|
(fboundp test-mode)
|
||||||
@ -2494,7 +2493,7 @@ With optional prefix argument KILL quit the window and buffer."
|
|||||||
(require 'yasnippet-debug nil t))
|
(require 'yasnippet-debug nil t))
|
||||||
(add-hook 'post-command-hook 'yas/debug-snippet-vars nil t))))
|
(add-hook 'post-command-hook 'yas/debug-snippet-vars nil t))))
|
||||||
(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)
|
(defun yas/template-fine-group (template)
|
||||||
(car (last (or (yas/template-group template)
|
(car (last (or (yas/template-group template)
|
||||||
@ -2655,7 +2654,7 @@ If found, the content of subexp group SUBEXP (default 0) is
|
|||||||
|
|
||||||
Otherwise throw exception."
|
Otherwise throw exception."
|
||||||
(when (and yas/moving-away-p (notany #'(lambda (pos) (string= pos yas/text)) possibilities))
|
(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)
|
(defun yas/field-value (number)
|
||||||
"Get the string for field with NUMBER.
|
"Get the string for field with NUMBER.
|
||||||
@ -2996,13 +2995,13 @@ snippet as ordinary text."
|
|||||||
;; again from `yas/take-care-of-redo'....
|
;; again from `yas/take-care-of-redo'....
|
||||||
(setf (yas/snippet-fields snippet) nil)))
|
(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)
|
(defun yas/safely-run-hooks (hook-var)
|
||||||
(condition-case error
|
(condition-case error
|
||||||
(run-hooks hook-var)
|
(run-hooks hook-var)
|
||||||
(error
|
(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 ()
|
(defun yas/check-commit-snippet ()
|
||||||
@ -3401,7 +3400,7 @@ considered when expanding the snippet."
|
|||||||
(when first-field
|
(when first-field
|
||||||
(sit-for 0) ;; fix issue 125
|
(sit-for 0) ;; fix issue 125
|
||||||
(yas/move-to-field snippet first-field)))
|
(yas/move-to-field snippet first-field)))
|
||||||
(message "[yas] snippet expanded.")
|
(yas/message 3 "snippet expanded.")
|
||||||
t))))
|
t))))
|
||||||
|
|
||||||
(defun yas/take-care-of-redo (beg end snippet)
|
(defun yas/take-care-of-redo (beg end snippet)
|
||||||
@ -3685,7 +3684,7 @@ SNIPPET-MARKERS."
|
|||||||
(widen)
|
(widen)
|
||||||
(condition-case err
|
(condition-case err
|
||||||
(indent-according-to-mode)
|
(indent-according-to-mode)
|
||||||
(error (message "[yas] warning: `yas/indent-according-to-mode' having problems running %s" indent-line-function)
|
(error (yas/message 3 "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)))
|
||||||
@ -4028,7 +4027,7 @@ that the rest of `yas/post-command-handler' runs.")
|
|||||||
(apply (car fn-and-args)
|
(apply (car fn-and-args)
|
||||||
(cdr fn-and-args)))
|
(cdr fn-and-args)))
|
||||||
yas/post-command-runonce-actions)
|
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))
|
(setq yas/post-command-runonce-actions nil))
|
||||||
(cond (yas/protection-violation
|
(cond (yas/protection-violation
|
||||||
(goto-char yas/protection-violation)
|
(goto-char yas/protection-violation)
|
||||||
@ -4135,6 +4134,18 @@ Remaining args as in `yas/expand-snippet'."
|
|||||||
(gethash uuid (yas/table-uuidhash table)))))
|
(gethash uuid (yas/table-uuidhash table)))))
|
||||||
(when yas/current-template
|
(when yas/current-template
|
||||||
(yas/expand-snippet (yas/template-content yas/current-template)))))
|
(yas/expand-snippet (yas/template-content yas/current-template)))))
|
||||||
|
|
||||||
|
;;; 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))
|
||||||
|
|
||||||
|
|
||||||
;;; Some hacks:
|
;;; Some hacks:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user