Make yas-describe-tables easier to use from lisp

* yasnippet.el (yas-describe-table-by-namehash): new function.
(yas-describe-tables): remove query for by-namehash variant, replace
query for non-active tables with prefix arg.
This commit is contained in:
Noam Postavsky 2014-08-10 11:16:24 -04:00
parent 1735a283d2
commit c7441486db

View File

@ -2664,58 +2664,49 @@ and `kill-buffer' instead."
(car (last (or (yas--template-group template) (car (last (or (yas--template-group template)
(yas--template-perm-group template))))) (yas--template-perm-group template)))))
(defun yas-describe-tables (&optional choose) (defun yas-describe-table-by-namehash ()
"Display snippets for each table." "Display snippet tables by NAMEHASH."
(interactive "P") (interactive)
(let* ((by-name-hash (and choose (with-current-buffer (get-buffer-create "*YASnippet Tables by NAMEHASH*")
(y-or-n-p "Show by namehash? "))) (let ((inhibit-read-only t))
(buffer (get-buffer-create "*YASnippet tables*"))
(active-tables (yas--get-snippet-tables))
(remain-tables (let ((all))
(maphash #'(lambda (_k v)
(unless (find v active-tables)
(push v all)))
yas--tables)
all))
(table-lists (list active-tables remain-tables))
(original-buffer (current-buffer))
(continue t)
(yas--condition-cache-timestamp (current-time)))
(with-current-buffer buffer
(setq buffer-read-only nil)
(erase-buffer) (erase-buffer)
(cond ((not by-name-hash) (insert "YASnippet tables by NAMEHASH: \n")
(insert "YASnippet tables:\n") (maphash
(while (and table-lists (lambda (_mode table)
continue)
(dolist (table (car table-lists))
(yas--describe-pretty-table table original-buffer))
(setq table-lists (cdr table-lists))
(when table-lists
(yas--create-snippet-xrefs)
(display-buffer buffer)
(setq continue (and choose (y-or-n-p "Show also non-active tables? ")))))
(yas--create-snippet-xrefs)
(help-mode)
(goto-char 1))
(t
(insert "\n\nYASnippet tables by NAMEHASH: \n")
(dolist (table (append active-tables remain-tables))
(insert (format "\nSnippet table `%s':\n\n" (yas--table-name table))) (insert (format "\nSnippet table `%s':\n\n" (yas--table-name table)))
(let ((keys)) (maphash
(maphash #'(lambda (k _v) (lambda (key _v)
(push k keys))
(yas--table-hash table))
(dolist (key keys)
(insert (format " key %s maps snippets: %s\n" key (insert (format " key %s maps snippets: %s\n" key
(let ((names)) (let ((names))
(maphash #'(lambda (k _v) (maphash #'(lambda (k _v)
(push k names)) (push k names))
(gethash key (yas--table-hash table))) (gethash key (yas--table-hash table)))
names)))))))) names))))
(yas--table-hash table)))
yas--tables))
(view-mode +1)
(goto-char 1) (goto-char 1)
(setq buffer-read-only t)) (display-buffer (current-buffer))))
(display-buffer buffer)))
(defun yas-describe-tables (&optional with-nonactive)
"Display snippets for each table."
(interactive "P")
(let ((original-buffer (current-buffer))
(tables (yas--get-snippet-tables)))
(with-current-buffer (get-buffer-create "*YASnippet Tables*")
(let ((inhibit-read-only t))
(when with-nonactive
(maphash #'(lambda (_k v)
(cl-pushnew v tables))
yas--tables))
(erase-buffer)
(insert "YASnippet tables:\n")
(dolist (table tables)
(yas--describe-pretty-table table original-buffer))
(yas--create-snippet-xrefs))
(help-mode)
(goto-char 1)
(display-buffer (current-buffer)))))
(defun yas--describe-pretty-table (table &optional original-buffer) (defun yas--describe-pretty-table (table &optional original-buffer)
(insert (format "\nSnippet table `%s'" (insert (format "\nSnippet table `%s'"