mirror of
https://github.com/joaotavora/yasnippet.git
synced 2025-10-15 22:13:04 +00:00
Fixed some bug with multiple parent modes and commiting fixed printf snippet
This commit is contained in:
parent
2ada74c6f2
commit
d70529d121
@ -1,20 +1,6 @@
|
|||||||
|
# -*- mode: snippet -*-
|
||||||
# name : printf
|
# name : printf
|
||||||
# contributor : joaotavora
|
# 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) "\);" "")}
|
printf ("${1:%s}\\n"${1:$(if (string-match "%" text) "," "\);")
|
||||||
|
}$2${1:$(if (string-match "%" text) "\);" "")}
|
43
yasnippet.el
43
yasnippet.el
@ -3,8 +3,8 @@
|
|||||||
;; Copyright 2008 pluskid
|
;; Copyright 2008 pluskid
|
||||||
|
|
||||||
;; Authors: pluskid <pluskid@gmail.com>, joaotavora <joaotavora@gmail.com>
|
;; Authors: pluskid <pluskid@gmail.com>, joaotavora <joaotavora@gmail.com>
|
||||||
;; Version: 0.6.0
|
;; Version: 0.6.1
|
||||||
;; Package-version: 0.6.0c
|
;; Package-version: 0.6.1b
|
||||||
;; X-URL: http://code.google.com/p/yasnippet/
|
;; X-URL: http://code.google.com/p/yasnippet/
|
||||||
;; Keywords: snippet, textmate
|
;; Keywords: snippet, textmate
|
||||||
;; URL: http://code.google.com/p/yasnippet/
|
;; URL: http://code.google.com/p/yasnippet/
|
||||||
@ -936,12 +936,12 @@ TEMPLATES is a list of `yas/template'."
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
;; Loading snippets from files
|
;; 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."
|
"Recursively load snippet templates from DIRECTORY."
|
||||||
|
|
||||||
(let* ((major-mode-and-parents (yas/compute-major-mode-and-parents (concat directory "/dummy")
|
(let* ((major-mode-and-parents (yas/compute-major-mode-and-parents (concat directory "/dummy")
|
||||||
nil
|
nil
|
||||||
root))
|
no-hierarchy-parents))
|
||||||
(mode-sym (car major-mode-and-parents))
|
(mode-sym (car major-mode-and-parents))
|
||||||
(parents (rest major-mode-and-parents))
|
(parents (rest major-mode-and-parents))
|
||||||
(snippet-defs nil))
|
(snippet-defs nil))
|
||||||
@ -969,7 +969,7 @@ content of the file is the template."
|
|||||||
(error "Error %s not a directory" directory))
|
(error "Error %s not a directory" directory))
|
||||||
(add-to-list 'yas/root-directory directory)
|
(add-to-list 'yas/root-directory directory)
|
||||||
(dolist (dir (yas/subdirs 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)
|
(when (interactive-p)
|
||||||
(message "done.")))
|
(message "done.")))
|
||||||
|
|
||||||
@ -1415,14 +1415,21 @@ also the current active tables."
|
|||||||
(push (format "%s/%s" main-dir (get mode 'derived-mode-parent)) options))
|
(push (format "%s/%s" main-dir (get mode 'derived-mode-parent)) options))
|
||||||
(reverse 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.
|
"Look for user snippets in guessed current mode's directory.
|
||||||
|
|
||||||
Calls `find-file' interactively in the guessed directory.
|
Calls `find-file' interactively in the guessed directory.
|
||||||
|
|
||||||
With prefix arg SAME-WINDOW opens the buffer in the same window.
|
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.
|
called non-interactively.
|
||||||
|
|
||||||
Because snippets can be loaded from many different locations,
|
Because snippets can be loaded from many different locations,
|
||||||
@ -1443,16 +1450,20 @@ otherwise, proposes to create the first option returned by
|
|||||||
|
|
||||||
(when target-directory
|
(when target-directory
|
||||||
(let ((default-directory target-directory))
|
(let ((default-directory target-directory))
|
||||||
(setq buffer (call-interactively (if same-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
|
||||||
'find-file-other-window)))
|
'find-file-other-window))))
|
||||||
(when buffer
|
(when buffer
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(set-buffer buffer)
|
(set-buffer buffer)
|
||||||
(when (eq major-mode 'fundamental-mode)
|
(when (eq major-mode 'fundamental-mode)
|
||||||
(snippet-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
|
(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
|
(major-mode-name (and file-dir
|
||||||
@ -1460,7 +1471,7 @@ otherwise, proposes to create the first option returned by
|
|||||||
(parent-file-dir (and file-dir
|
(parent-file-dir (and file-dir
|
||||||
(directory-file-name (file-name-directory file-dir))))
|
(directory-file-name (file-name-directory file-dir))))
|
||||||
(parent-mode-name (and parent-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)))
|
(file-name-nondirectory parent-file-dir)))
|
||||||
(major-mode-sym (or (and major-mode-name
|
(major-mode-sym (or (and major-mode-name
|
||||||
(intern major-mode-name))
|
(intern major-mode-name))
|
||||||
@ -1468,17 +1479,17 @@ otherwise, proposes to create the first option returned by
|
|||||||
(read-from-minibuffer "[yas] Cannot auto-detect major mode! Enter a major mode: "))))
|
(read-from-minibuffer "[yas] Cannot auto-detect major mode! Enter a major mode: "))))
|
||||||
(parent-mode-sym (and parent-mode-name
|
(parent-mode-sym (and parent-mode-name
|
||||||
(intern parent-mode-name)))
|
(intern parent-mode-name)))
|
||||||
(parent-file-name (concat file-dir "/.yas-parents"))
|
(extra-parents-file-name (concat file-dir "/.yas-parents"))
|
||||||
(more-parents (when (file-readable-p parent-file-name)
|
(more-parents (when (file-readable-p extra-parents-file-name)
|
||||||
(mapcar #'intern
|
(mapcar #'intern
|
||||||
(split-string
|
(split-string
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(insert-file parent-file-name)
|
(insert-file extra-parents-file-name)
|
||||||
(buffer-substring-no-properties (point-min)
|
(buffer-substring-no-properties (point-min)
|
||||||
(point-max))))))))
|
(point-max))))))))
|
||||||
(when major-mode-sym
|
(when major-mode-sym
|
||||||
(append (list major-mode-sym parent-mode-sym)
|
(remove nil (append (list major-mode-sym parent-mode-sym)
|
||||||
more-parents))))
|
more-parents)))))
|
||||||
|
|
||||||
(defun yas/load-snippet-buffer (&optional kill)
|
(defun yas/load-snippet-buffer (&optional kill)
|
||||||
"Parse and load current buffer's snippet definition.
|
"Parse and load current buffer's snippet definition.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user