+# -*- mode: snippet -*-
# name : printf
# contributor : joaotavora
-# description : a snippet that is very slightly buggy in 0.6.0b. There *must* be a space before the $2!
-#
-# While a per-snippet exit-hook property does not exist, this can be fixed with
-# this in your .emacs
-#
-# (setq yas/after-exit-snippet-hook '(yas/munch-useless-spaces-at-end))
-#
-# (defun yas/munch-useless-spaces-at-end ()
-# (let ((end (1- yas/snippet-end)))
-# (while (= (char-after end) ?\s)
-# (setq end (1- end))
-# (backward-char))
-# (delete-region (point) yas/snippet-end)))
-#
-# but this might break some other snippets...
-#
# --
-printf ("${1:%s}\\n"${1:$(if (string-match "%" text) "," "\);")} $2${1:$(if (string-match "%" text) "\);" "")}
\ No newline at end of file
+printf ("${1:%s}\\n"${1:$(if (string-match "%" text) "," "\);")
+}$2${1:$(if (string-match "%" text) "\);" "")}
\ No newline at end of file
;; Copyright 2008 pluskid
;; Authors: pluskid <pluskid@gmail.com>, joaotavora <joaotavora@gmail.com>
-;; Version: 0.6.0
-;; Package-version: 0.6.0c
+;; Version: 0.6.1
+;; Package-version: 0.6.1b
;; X-URL: http://code.google.com/p/yasnippet/
;; Keywords: snippet, textmate
;; URL: http://code.google.com/p/yasnippet/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Loading snippets from files
;;
-(defun yas/load-directory-1 (directory &optional parents root)
+(defun yas/load-directory-1 (directory &optional parents no-hierarchy-parents)
"Recursively load snippet templates from DIRECTORY."
(let* ((major-mode-and-parents (yas/compute-major-mode-and-parents (concat directory "/dummy")
nil
- root))
+ no-hierarchy-parents))
(mode-sym (car major-mode-and-parents))
(parents (rest major-mode-and-parents))
(snippet-defs nil))
(error "Error %s not a directory" directory))
(add-to-list 'yas/root-directory directory)
(dolist (dir (yas/subdirs directory))
- (yas/load-directory-1 dir nil directory))
+ (yas/load-directory-1 dir nil 'no-hierarchy-parents))
(when (interactive-p)
(message "done.")))
(push (format "%s/%s" main-dir (get mode 'derived-mode-parent)) options))
(reverse options)))
-(defun yas/find-snippets (&optional same-window file)
+(defun yas/new-snippet (&optional same-window)
+ "Create a new snippet in guessed current mode's directory."
+ (interactive)
+ (yas/find-snippets same-window
+ (read-from-minibuffer "Enter snippet name: ")))
+
+
+(defun yas/find-snippets (&optional same-window file-name)
"Look for user snippets in guessed current mode's directory.
Calls `find-file' interactively in the guessed directory.
With prefix arg SAME-WINDOW opens the buffer in the same window.
-With optional FILE, finds the file directly, i.e. `find-file' is
+With optional FILE-NAME, finds the file directly, i.e. `find-file' is
called non-interactively.
Because snippets can be loaded from many different locations,
(when target-directory
(let ((default-directory target-directory))
- (setq buffer (call-interactively (if same-window
- 'find-file
- 'find-file-other-window)))
+ (setq buffer (if file-name
+ (if same-window
+ (find-file file-name)
+ (find-file-other-window file-name))
+ (call-interactively (if same-window
+ 'find-file
+ 'find-file-other-window))))
(when buffer
(save-excursion
(set-buffer buffer)
(when (eq major-mode 'fundamental-mode)
(snippet-mode))))))))
-(defun yas/compute-major-mode-and-parents (file &optional prompt-if-failed root-directory)
+(defun yas/compute-major-mode-and-parents (file &optional prompt-if-failed no-hierarchy-parents)
(let* ((file-dir (and file
- (directory-file-name (file-name-directory file))))
+ (directory-file-name (file-name-directory file))))
(major-mode-name (and file-dir
(file-name-nondirectory file-dir)))
(parent-file-dir (and file-dir
(directory-file-name (file-name-directory file-dir))))
(parent-mode-name (and parent-file-dir
- (not (string= parent-file-dir root-directory))
+ (not no-hierarchy-parents)
(file-name-nondirectory parent-file-dir)))
(major-mode-sym (or (and major-mode-name
(intern major-mode-name))
(read-from-minibuffer "[yas] Cannot auto-detect major mode! Enter a major mode: "))))
(parent-mode-sym (and parent-mode-name
(intern parent-mode-name)))
- (parent-file-name (concat file-dir "/.yas-parents"))
- (more-parents (when (file-readable-p parent-file-name)
+ (extra-parents-file-name (concat file-dir "/.yas-parents"))
+ (more-parents (when (file-readable-p extra-parents-file-name)
(mapcar #'intern
(split-string
(with-temp-buffer
- (insert-file parent-file-name)
+ (insert-file extra-parents-file-name)
(buffer-substring-no-properties (point-min)
(point-max))))))))
(when major-mode-sym
- (append (list major-mode-sym parent-mode-sym)
- more-parents))))
+ (remove nil (append (list major-mode-sym parent-mode-sym)
+ more-parents)))))
(defun yas/load-snippet-buffer (&optional kill)
"Parse and load current buffer's snippet definition.