| 162 | | (let* ((result-alist '((candidates) (transformed) (template-key-alist))) |
| 163 | | (hash-value-alist nil) |
| 164 | | (cur-table (or table (yas/snippet-table anything-c-yas-cur-major-mode))) |
| 165 | | (parent-table (yas/snippet-table-parent cur-table)) ;`yas/snippet-table-parent' |
| 166 | | (hash-table (yas/snippet-table-hash cur-table))) ;`yas/snippet-table-hash' |
| 167 | | (maphash (lambda (k v) (setq hash-value-alist (append v hash-value-alist))) hash-table) |
| 168 | | (loop with transformed |
| 169 | | with templates |
| 170 | | with template-key-alist |
| 171 | | for lst in hash-value-alist |
| 172 | | for key = (car lst) |
| 173 | | for template-struct = (cdr lst) |
| 174 | | for name = (yas/template-name template-struct) ;`yas/template-name' |
| 175 | | for template = (yas/template-content template-struct) ;`yas/template-content' |
| 176 | | do (progn (push template templates) |
| 177 | | (push `(,name . ,template) transformed) |
| 178 | | (push `(,template . ,key) template-key-alist)) |
| 179 | | finally (progn (push `(candidates . ,templates) result-alist) |
| 180 | | (push `(transformed . ,transformed) result-alist) |
| 181 | | (push `(template-key-alist . ,template-key-alist) result-alist))) |
| 182 | | ;; if cur-table has parent build recursively |
| 183 | | (when parent-table |
| 184 | | (let ((rec-ret (anything-c-yas-build-cur-snippets-alist parent-table)) |
| 185 | | (alist-keys '(candidates transformed template-key-alist))) |
| 186 | | (mapc (lambda (key) |
| 187 | | (let ((res-list (assq key result-alist)) |
| 188 | | (rec-val (assoc-default key rec-ret))) |
| 189 | | (setcdr res-list (nconc rec-val (cdr res-list))))) |
| 190 | | alist-keys))) |
| 191 | | result-alist)) |
| | 161 | (let ((yas/choose-keys-first nil) |
| | 162 | (yas/choose-tables-first nil) |
| | 163 | (yas/buffer-local-condition 'always)) |
| | 164 | (let* ((result-alist '((candidates) (transformed) (template-key-alist))) |
| | 165 | (hash-value-alist nil) |
| | 166 | (cur-table (first (yas/get-snippet-tables anything-c-yas-cur-major-mode))) |
| | 167 | (hash-table (yas/snippet-table-hash cur-table))) ;`yas/snippet-table-hash' |
| | 168 | (let ((hashes (loop for table in (yas/get-snippet-tables) |
| | 169 | collect (yas/snippet-table-hash table)))) |
| | 170 | (loop for hash in hashes |
| | 171 | do (maphash (lambda (k v) |
| | 172 | (setq hash-value-alist (append v hash-value-alist)) |
| | 173 | ) |
| | 174 | hash)) |
| | 175 | (loop with transformed |
| | 176 | with templates |
| | 177 | with template-key-alist |
| | 178 | for lst in hash-value-alist |
| | 179 | for key = (car lst) |
| | 180 | for template-struct = (cdr lst) |
| | 181 | for name = (yas/template-name template-struct) ;`yas/template-name' |
| | 182 | for template = (yas/template-content template-struct) ;`yas/template-content' |
| | 183 | do (progn (push template templates) |
| | 184 | (push `(,name . ,template) transformed) |
| | 185 | (push `(,template . ,key) template-key-alist)) |
| | 186 | finally (progn (push `(candidates . ,templates) result-alist) |
| | 187 | (push `(transformed . ,transformed) result-alist) |
| | 188 | (push `(template-key-alist . ,template-key-alist) result-alist))) |
| | 189 | result-alist) |
| | 190 | ))) |
| | 338 | |
| | 339 | ;;; visit template |
| | 340 | (defun anything-c-yas-all-templates () |
| | 341 | (let ((tables (yas/get-snippet-tables))) |
| | 342 | (loop for table in tables |
| | 343 | append (yas/snippet-table-templates table)))) |
| | 344 | |
| | 345 | (defun anything-c-yas-flatten-templates (templates) |
| | 346 | (loop for lot in templates ;lot is list of templates |
| | 347 | append lot)) |
| | 348 | |
| | 349 | (defun anything-c-yas-snippet-files-candidates () |
| | 350 | "called in `anything-c-source-yasnippet-snippet-files' candidates" |
| | 351 | (let ((yas/choose-keys-first nil) |
| | 352 | (yas/choose-tables-first nil) |
| | 353 | (yas/buffer-local-condition 'always)) |
| | 354 | (with-current-buffer anything-current-buffer |
| | 355 | (mapcar* 'yas/template-file |
| | 356 | (mapcar 'cdr |
| | 357 | (anything-c-yas-all-templates)))))) |
| | 358 | |
| | 359 | ;; (anything 'anything-c-source-yasnippet-snippet-files) |
| | 360 | (defvar anything-c-source-yasnippet-snippet-files |
| | 361 | '((name . "yasnippet snippet files") |
| | 362 | (candidates . anything-c-yas-snippet-files-candidates) |
| | 363 | (type . file) |
| | 364 | )) |
| | 365 | |