; yasnippet-debug.el: Fix deprecation warning.

This commit is contained in:
Noam Postavsky 2018-01-31 07:37:48 -05:00
parent 6ffd1c7950
commit ff8e833375

View File

@ -46,13 +46,19 @@
(require 'color nil t)
(require 'edebug)
(eval-when-compile
(unless (and (require 'subr-x nil t) (fboundp 'when-let))
;; Introduced in 25.1
(defmacro when-let (key-val &rest body)
(require 'subr-x nil t)
(cond ((fboundp 'when-let*) nil) ; Introduced in 26.
((fboundp 'when-let) ; Introduced in 25.1,
(defalias 'when-let* 'when-let)) ; deprecated in 26.
(t (defmacro when-let* (key-vals &rest body)
(declare (indent 1) (debug ((symbolp form) body)))
(let ((key-val (pop key-vals)))
(if key-val
`(let ((,(car key-val) ,(cadr key-val)))
(when ,(car key-val)
,@body)))))
(if ,(car key-val)
(when-let* ,key-vals
,@body)))
(macroexp-progn body)))))))
(defvar yas-debug-live-indicators
(make-hash-table :test #'eq))
@ -73,7 +79,7 @@
(setq beg (setq end (marker-position location)))
(setq beg (yas-debug-ov-fom-start location)
end (yas-debug-ov-fom-end location)))
(or (when-let (color-ov (gethash location yas-debug-live-indicators))
(or (when-let* ((color-ov (gethash location yas-debug-live-indicators)))
(if (and beg end) (move-overlay (cdr color-ov) beg end)
(delete-overlay (cdr color-ov)))
color-ov)
@ -170,18 +176,18 @@
(defun yas-debug-snippet (snippet &optional outbuf)
(yas-debug-with-tracebuf outbuf
(when-let (overlay (yas--snippet-control-overlay snippet))
(when-let* ((overlay (yas--snippet-control-overlay snippet)))
(printf "\tsid: %d control overlay %s\n"
(yas--snippet-id snippet)
(yas-debug-live-range overlay)))
(when-let (active-field (yas--snippet-active-field snippet))
(when-let* ((active-field (yas--snippet-active-field snippet)))
(unless (consp (yas--field-start active-field))
(printf "\tactive field: #%d %s %s covering \"%s\"\n"
(or (yas--field-number active-field) -1)
(if (yas--field-modified-p active-field) "**" "--")
(yas-debug-live-range active-field)
(buffer-substring-no-properties (yas--field-start active-field) (yas--field-end active-field)))))
(when-let (exit (yas--snippet-exit snippet))
(when-let* ((exit (yas--snippet-exit snippet)))
(printf "\tsnippet-exit: %s next: %s\n"
(yas-debug-live-marker (yas--exit-marker exit))
(yas--exit-next exit)))
@ -308,15 +314,15 @@ buffer-locally, otherwise install it globally. If HOOK is
while (and opt (not (equal opt "--"))
(string-prefix-p "-" opt))
collect opt)))
(when-let (mode (cl-member "-M:" options :test #'string-prefix-p))
(when-let* ((mode (cl-member "-M:" options :test #'string-prefix-p)))
(setq snippet-mode (intern (concat (substring (car mode) 3) "-mode"))))
(when-let (mode (cl-member "-M." options :test #'string-prefix-p))
(when-let* ((mode (cl-member "-M." options :test #'string-prefix-p)))
(setq snippet-mode
(cdr (cl-assoc (substring (car mode) 2) auto-mode-alist
:test (lambda (ext regexp) (string-match-p regexp ext))))))
(switch-to-buffer (get-buffer-create "*yas test*"))
(funcall snippet-mode)
(when-let (snippet-file (cl-member "-S:" options :test #'string-prefix-p))
(when-let* ((snippet-file (cl-member "-S:" options :test #'string-prefix-p)))
(setq snippet-file (substring (car snippet-file) 3))
(if (file-exists-p snippet-file)
(with-temp-buffer
@ -331,7 +337,7 @@ buffer-locally, otherwise install it globally. If HOOK is
(error "No such snippet `%s'" snippet-file)))))
(display-buffer (find-file-noselect
(expand-file-name "yasnippet.el" yas--loaddir)))
(when-let (verbosity (car (or (member "-v" options) (member "-vv" options))))
(when-let* ((verbosity (car (or (member "-v" options) (member "-vv" options)))))
(set-window-buffer
(split-window) (yas-debug-snippets
nil (if (equal verbosity "-vv") 'edebug-create t))))