| 2 | | ;; TODO: defvar => defcustom |
| | 2 | |
| | 3 | ;; Author: Kenji.I (Kenji Imakado) <ken.imakaado@gmail.com> |
| | 4 | ;; Version: 0.3 |
| | 5 | ;; Keywords: anything yasnippet |
| | 6 | |
| | 7 | ;; This file is free software; you can redistribute it and/or modify |
| | 8 | ;; it under the terms of the GNU General Public License as published by |
| | 9 | ;; the Free Software Foundation; either version 2, or (at your option) |
| | 10 | ;; any later version. |
| | 11 | |
| | 12 | ;; This file is distributed in the hope that it will be useful, |
| | 13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| | 14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| | 15 | ;; GNU General Public License for more details. |
| | 16 | |
| | 17 | ;; You should have received a copy of the GNU General Public License |
| | 18 | ;; along with GNU Emacs; see the file COPYING. If not, write to the |
| | 19 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| | 20 | ;; Boston, MA 02110-1301, USA. |
| 55 | | (defvar anything-c-yas-appear-rule nil) ;; customizable e.i (add-to-list 'anything-c-yas-appear-rule '(ruby-mode . (text-mode html-mode))) |
| 56 | | (defvar anything-c-yas-not-display-dups t) ;; customizable |
| 57 | | (defvar anything-c-yas-display-msg-after-complete t) ;; customizable |
| 58 | | (defvar anything-c-yas-snippets-dir-list nil) ;;customizable list of path(string) for finding snippet file in Action |
| 59 | | (defvar anything-c-yas-space-match-any-greedy nil |
| 60 | | "non-nil anything pattern, space match anyword greedy. |
| | 73 | ;;; Code |
| | 74 | (defvar anything-c-yas-version "0.3" "Version of anything-c-yasnippet") |
| | 75 | |
| | 76 | (defgroup anything-c-yasnippet nil |
| | 77 | "anything config yasnippet") |
| | 78 | |
| | 79 | (defcustom anything-c-yas-not-display-dups t |
| | 80 | "if non-nil not display duplicate snippet otherwise display all snippet" |
| | 81 | :type 'boolean |
| | 82 | :group 'anything-c-yasnippet) |
| | 83 | |
| | 84 | (defcustom anything-c-yas-display-msg-after-complete t |
| | 85 | "if non-nil display snippet key message in minibuffer after Complete" |
| | 86 | :type 'boolean |
| | 87 | :group 'anything-c-yasnippet) |
| | 88 | |
| | 89 | ;(defvar anything-c-yas-snippets-dir-list nil) ;;customizable list of path(string) for finding snippet file in Action |
| | 90 | (defcustom anything-c-yas-snippets-dir-list nil |
| | 91 | "list of directory used to find snippet file" |
| | 92 | :type '(repeat (directory |
| | 93 | :tag "snippet-directory")) |
| | 94 | :group 'anything-c-yasnippet) |
| | 95 | |
| | 96 | (defcustom anything-c-yas-space-match-any-greedy nil |
| | 97 | "if non-nil anything pattern space match anyword greedy. |
| | 113 | |
| | 114 | (defun anything-c-yas-create-new-snippet (selected-text) |
| | 115 | (let* ((mode-name (symbol-name anything-c-yas-cur-major-mode)) |
| | 116 | (root-dir (expand-file-name yas/root-directory)) |
| | 117 | (default-snippet-dir (anything-c-yas-find-recursively mode-name root-dir 'dir)) |
| | 118 | (dir (read-file-name "create snippet : " default-snippet-dir default-snippet-dir))) |
| | 119 | (condition-case e |
| | 120 | (progn (when (file-exists-p dir) |
| | 121 | (error "can't create file [%s] already exists" (file-name-nondirectory dir))) |
| | 122 | ;; create buffer, insert template |
| | 123 | (find-file dir) |
| | 124 | (insert "#name : \n# --\n " selected-text)) |
| | 125 | (message "%s" (error-message-string e))))) |
| | 126 | |
| | 127 | (defun anything-c-yas-find-recursively (regexp &optional directory predicate) |
| | 128 | (let ((directory (or directory default-directory)) |
| | 129 | (predfunc (case predicate |
| | 130 | (dir 'file-directory-p) |
| | 131 | (file 'file-regular-p) |
| | 132 | (otherwise 'identity))) |
| | 133 | (files (remove-if (lambda (s) (string-match "^\\." (file-name-nondirectory s))) (directory-files directory t))) |
| | 134 | (found nil) |
| | 135 | (result nil)) |
| | 136 | (loop for file in files |
| | 137 | unless found |
| | 138 | do (if (and (funcall predfunc file) |
| | 139 | (string-match regexp file)) |
| | 140 | (progn (setq found t) |
| | 141 | (return (file-name-as-directory file))) |
| | 142 | (when (file-directory-p file) |
| | 143 | (setq result (anything-c-yas-find-recursively regexp file predicate)))) |
| | 144 | finally (return result)))) |
| 208 | | (anything-c-yas-find-file-snippet-by-template template t))))) |
| | 290 | (anything-c-yas-find-file-snippet-by-template template t))) |
| | 291 | ("Create new snippet on region" . (lambda (template) |
| | 292 | (anything-c-yas-create-new-snippet anything-c-yas-selected-text))) |
| | 293 | ("Reload All Snippts" . (lambda (template) |
| | 294 | (yas/reload-all) |
| | 295 | (message "Reload All Snippts done"))) |
| | 296 | ("Rename snippet file" . (lambda (template) |
| | 297 | (let* ((path (or (anything-c-yas-get-path-by-template template) "")) |
| | 298 | (dir (file-name-directory path)) |
| | 299 | (filename (file-name-nondirectory path)) |
| | 300 | (rename-to (read-string (concat "rename [" filename "] to: ")))) |
| | 301 | (rename-file path (concat dir rename-to)) |
| | 302 | (yas/reload-all)))) |
| | 303 | ("Delete snippet file" . (lambda (template) |
| | 304 | (let ((path (or (anything-c-yas-get-path-by-template template) ""))) |
| | 305 | (when (y-or-n-p "really delete?") |
| | 306 | (delete-file path) |
| | 307 | (yas/reload-all))))))) |