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)
(yas--template-perm-group template)))))
(defun yas-describe-tables (&optional choose)
(defun yas-describe-table-by-namehash ()
"Display snippet tables by NAMEHASH."
(interactive)
(with-current-buffer (get-buffer-create "*YASnippet Tables by NAMEHASH*")
(let ((inhibit-read-only t))
(erase-buffer)
(insert "YASnippet tables by NAMEHASH: \n")
(maphash
(lambda (_mode table)
(insert (format "\nSnippet table `%s':\n\n" (yas--table-name table)))
(maphash
(lambda (key _v)
(insert (format " key %s maps snippets: %s\n" key
(let ((names))
(maphash #'(lambda (k _v)
(push k names))
(gethash key (yas--table-hash table)))
names))))
(yas--table-hash table)))
yas--tables))
(view-mode +1)
(goto-char 1)
(display-buffer (current-buffer))))
(defun yas-describe-tables (&optional with-nonactive)
"Display snippets for each table."
(interactive "P")
(let* ((by-name-hash (and choose
(y-or-n-p "Show by namehash? ")))
(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)
(cond ((not by-name-hash)
(insert "YASnippet tables:\n")
(while (and table-lists
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)))
(let ((keys))
(maphash #'(lambda (k _v)
(push k keys))
(yas--table-hash table))
(dolist (key keys)
(insert (format " key %s maps snippets: %s\n" key
(let ((names))
(maphash #'(lambda (k _v)
(push k names))
(gethash key (yas--table-hash table)))
names))))))))
(goto-char 1)
(setq buffer-read-only t))
(display-buffer buffer)))
(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)
(insert (format "\nSnippet table `%s'"