Changeset 35399

Show
Ignore:
Timestamp:
09/16/09 21:22:12 (4 years ago)
Author:
imakado
Message:

fix some that change api yasnippet.el(0.6)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/elisp/anything-c-yasnippet/anything-c-yasnippet.el

    r31031 r35399  
    22 
    33;; Author: Kenji.I (Kenji Imakado) <ken.imakaado@gmail.com> 
    4 ;; Version: 0.5 
     4;; Version: 0.6 
    55;; Keywords: anything yasnippet 
    66 
     
    2121 
    2222;;; Commentary: 
     23;; thans to grandVin for patch on his blog. 
    2324 
    2425;; anything-source name  => anything-c-source-yasnippet 
     
    7071(require 'yasnippet) 
    7172 
    72 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 
    73  
    7473;;; Code 
    75 (defvar anything-c-yas-version "0.5" "Version of anything-c-yasnippet") 
     74(defvar anything-c-yas-version "0.6" "Version of anything-c-yasnippet") 
    7675 
    7776(defgroup anything-c-yasnippet nil 
     
    111110  :type 'boolean 
    112111  :group 'anything-c-yasnippet) 
    113  
    114112 
    115113(defvar anything-c-yas-snippets-dir-list nil) 
     
    159157          finally (return result)))) 
    160158 
     159 
    161160(defun anything-c-yas-build-cur-snippets-alist (&optional table) 
    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      ))) 
    192191 
    193192(defun anything-c-yas-get-modes () 
     
    337336    (match . (anything-c-yas-match)))) 
    338337 
     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 
    339366  
    340367;;; Commands 
     
    344371  (anything 'anything-c-source-yasnippet)) 
    345372 
     373(defun anything-c-yas-visit-snippet-file () 
     374  "List of yasnippet snippet files" 
     375  (interactive) 
     376  (anything 'anything-c-source-yasnippet-snippet-files)) 
     377 
    346378(defun anything-c-yas-create-snippet-on-region (&optional start end file-name) 
    347379  "Create a snippet from region." 
     
    351383;; (anything-c-yas-create-snippet-on-region (region-beginning) (region-end) "aaaa") 
    352384 
     385 
     386 
    353387(provide 'anything-c-yasnippet) 
    354388;; anything-c-yasnippet.el ends here