* More adjustments in issue 84, fix issue 78, and faq update for issue 71

This commit is contained in:
capitaomorte 2009-08-28 14:49:44 +00:00
parent 364a3c8378
commit 560fd2acf7
6 changed files with 116 additions and 62 deletions

View File

@ -5,8 +5,6 @@
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" /> <meta name="generator" content="Docutils 0.6: http://docutils.sourceforge.net/" />
<title>Frequently Asked Questions</title> <title>Frequently Asked Questions</title>
<meta name="author" content="pluskid" />
<meta name="date" content="2008-03-20" />
<link rel="stylesheet" href="styles.css" type="text/css" /> <link rel="stylesheet" href="styles.css" type="text/css" />
</head> </head>
<body> <body>
@ -68,10 +66,10 @@ newline for you automatically.</p>
</div> </div>
<div class="section" id="why-tab-key-doesn-t-expand-a-snippet"> <div class="section" id="why-tab-key-doesn-t-expand-a-snippet">
<h1>Why TAB key doesn't expand a snippet?</h1> <h1>Why TAB key doesn't expand a snippet?</h1>
<p>First check the mode line to see if there's <tt class="docutils literal"><span class="pre">yas</span></tt>. If no, then try <p>First check the mode line to see if there's <tt class="docutils literal"><span class="pre">yas</span></tt>. If not, then try
<tt class="docutils literal"><span class="pre">M-x</span> <span class="pre">yas/minor-mode-on</span></tt> to manually turn on <tt class="docutils literal"><span class="pre">yas/minor-mode</span></tt> and <tt class="docutils literal"><span class="pre">M-x</span> <span class="pre">yas/minor-mode</span></tt> to manually turn on the minor mode and try to
try to expand the snippet again. If it works, then, you can add the expand the snippet again. If it works, then, you can add the following
following code to your <tt class="docutils literal"><span class="pre">.emacs</span></tt> <em>before</em> loading YASnippet:</p> code to your <tt class="docutils literal"><span class="pre">.emacs</span></tt> <em>before</em> loading YASnippet:</p>
<div class="highlight"><pre>(add-hook &#39;the-major-mode-hook &#39;yas/minor-mode-on) <div class="highlight"><pre>(add-hook &#39;the-major-mode-hook &#39;yas/minor-mode-on)
</pre></div> </pre></div>
<p>where <tt class="docutils literal"><span class="pre">the-major-mode</span></tt> is the major mode in which <tt class="docutils literal"><span class="pre">yas/minor-mode</span></tt> <p>where <tt class="docutils literal"><span class="pre">the-major-mode</span></tt> is the major mode in which <tt class="docutils literal"><span class="pre">yas/minor-mode</span></tt>
@ -89,16 +87,32 @@ latter has priority. If you see <tt class="docutils literal"><span class="pre">&
than <tt class="docutils literal"><span class="pre">yas/expand</span></tt>, (e.g. in <tt class="docutils literal"><span class="pre">org-mode</span></tt>) you can try the following than <tt class="docutils literal"><span class="pre">yas/expand</span></tt>, (e.g. in <tt class="docutils literal"><span class="pre">org-mode</span></tt>) you can try the following
code to work around:</p> code to work around:</p>
<div class="highlight"><pre>(add-hook &#39;org-mode-hook <div class="highlight"><pre>(add-hook &#39;org-mode-hook
&#39;(lambda () #&#39;(lambda ()
(make-variable-buffer-local &#39;yas/trigger-key) (local-set-key [tab] &#39;yas/expand)))
(setq yas/trigger-key [tab])))
</pre></div> </pre></div>
<p>replace <tt class="docutils literal"><span class="pre">org-mode-hook</span></tt> with the major mode hook you are dealing <p>replace <tt class="docutils literal"><span class="pre">org-mode-hook</span></tt> with the major mode hook you are dealing
with (<tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">m</span></tt> to see what major mode you are in).</p> with (<tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">m</span></tt> to see what major mode you are in).</p>
<p>If it says <tt class="docutils literal"><span class="pre">TAB</span></tt> but YASnippet still doesn't work, check your <p>If this doesn't work, you can also try</p>
configuration and you may also ask for help on the <a class="reference external" href="http://groups.google.com/group/smart-snippet">discussion group</a>. Don't forget to <div class="highlight"><pre>(defun yas/advise-indent-function (function-symbol)
attach the information on what command is bound to TAB as well as the (eval `(defadvice ,function-symbol (around yas/try-expand-first activate)
mode information (Can be obtained by <tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">m</span></tt>).</p> ,(format
&quot;Try to expand a snippet before point, then call `%s&#39; as usual&quot;
function-symbol)
(let ((yas/fallback-behavior nil))
(unless (and (interactive-p)
(yas/expand))
ad-do-it)))))
(yas/advise-indent-function &#39;ruby-indent-line)
</pre></div>
<p>To <em>advise</em> the modes indentation function bound to TAB, (in this case
<tt class="docutils literal"><span class="pre">ruby-indent-line</span></tt>) to first try to run <tt class="docutils literal"><span class="pre">yas/expand</span></tt>.</p>
<p>If The output of <tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">k</span> <span class="pre">RET</span> <span class="pre">&lt;tab&gt;</span></tt> tells you that <tt class="docutils literal"><span class="pre">&lt;tab&gt;</span></tt> is
indeed bound to <tt class="docutils literal"><span class="pre">yas/expand</span></tt> but YASnippet still doesn't work, check
your configuration and you may also ask for help on the <a class="reference external" href="http://groups.google.com/group/smart-snippet">discussion
group</a>.</p>
<p>Don't forget to attach the information on what command is bound to TAB
as well as the mode information (Can be obtained by <tt class="docutils literal"><span class="pre">C-h</span> <span class="pre">m</span></tt>).</p>
</div> </div>
<div class="section" id="how-to-define-snippets-with-named-by-characters-not-supported-by-the-filesystem"> <div class="section" id="how-to-define-snippets-with-named-by-characters-not-supported-by-the-filesystem">
<h1>How to define snippets with named by characters not supported by the filesystem?</h1> <h1>How to define snippets with named by characters not supported by the filesystem?</h1>

View File

@ -2,10 +2,6 @@
Frequently Asked Questions Frequently Asked Questions
========================== ==========================
:Author: pluskid
:Contact: pluskid@gmail.com
:Date: 2008-03-20
Why there's an extra newline? Why there's an extra newline?
============================= =============================
@ -21,10 +17,10 @@ newline for you automatically.
Why TAB key doesn't expand a snippet? Why TAB key doesn't expand a snippet?
===================================== =====================================
First check the mode line to see if there's ``yas``. If no, then try First check the mode line to see if there's ``yas``. If not, then try
``M-x yas/minor-mode-on`` to manually turn on ``yas/minor-mode`` and ``M-x yas/minor-mode`` to manually turn on the minor mode and try to
try to expand the snippet again. If it works, then, you can add the expand the snippet again. If it works, then, you can add the following
following code to your ``.emacs`` *before* loading YASnippet: code to your ``.emacs`` *before* loading YASnippet:
.. sourcecode:: lisp .. sourcecode:: lisp
@ -51,18 +47,38 @@ code to work around:
.. sourcecode:: lisp .. sourcecode:: lisp
(add-hook 'org-mode-hook (add-hook 'org-mode-hook
'(lambda () #'(lambda ()
(make-variable-buffer-local 'yas/trigger-key) (local-set-key [tab] 'yas/expand)))
(setq yas/trigger-key [tab])))
replace ``org-mode-hook`` with the major mode hook you are dealing replace ``org-mode-hook`` with the major mode hook you are dealing
with (``C-h m`` to see what major mode you are in). with (``C-h m`` to see what major mode you are in).
If it says ``TAB`` but YASnippet still doesn't work, check your If this doesn't work, you can also try
configuration and you may also ask for help on the `discussion group
<http://groups.google.com/group/smart-snippet>`_. Don't forget to .. sourcecode:: lisp
attach the information on what command is bound to TAB as well as the
mode information (Can be obtained by ``C-h m``). (defun yas/advise-indent-function (function-symbol)
(eval `(defadvice ,function-symbol (around yas/try-expand-first activate)
,(format
"Try to expand a snippet before point, then call `%s' as usual"
function-symbol)
(let ((yas/fallback-behavior nil))
(unless (and (interactive-p)
(yas/expand))
ad-do-it)))))
(yas/advise-indent-function 'ruby-indent-line)
To *advise* the modes indentation function bound to TAB, (in this case
``ruby-indent-line``) to first try to run ``yas/expand``.
If The output of ``C-h k RET <tab>`` tells you that ``<tab>`` is
indeed bound to ``yas/expand`` but YASnippet still doesn't work, check
your configuration and you may also ask for help on the `discussion
group <http://groups.google.com/group/smart-snippet>`_.
Don't forget to attach the information on what command is bound to TAB
as well as the mode information (Can be obtained by ``C-h m``).
How to define snippets with named by characters not supported by the filesystem? How to define snippets with named by characters not supported by the filesystem?
================================================================================ ================================================================================

View File

@ -1,4 +1,4 @@
#contributor : rejeep <johan.rejeep@gmail.com> #contributor : rejeep <johan.rejeep@gmail.com>
#name : display: block #name : display: block
# -- # --
dislpay: block; display: block;

View File

@ -1,4 +1,4 @@
#contributor : rejeep <johan.rejeep@gmail.com> #contributor : rejeep <johan.rejeep@gmail.com>
#name : display: inline #name : display: inline
# -- # --
dislpay: inline; display: inline;

View File

@ -1,4 +1,4 @@
#contributor : rejeep <johan.rejeep@gmail.com> #contributor : rejeep <johan.rejeep@gmail.com>
#name : display: none #name : display: none
# -- # --
dislpay: none; display: none;

View File

@ -164,22 +164,22 @@ bulk reloading of all snippets using `yas/reload-all'"
These functions are called with the following arguments: These functions are called with the following arguments:
* PROMPT: A string to prompt the user - PROMPT: A string to prompt the user
* CHOICES: a list of strings or objects. - CHOICES: a list of strings or objects.
* optional DISPLAY-FN : A function that, when applied to each of - optional DISPLAY-FN : A function that, when applied to each of
the objects in CHOICES will return a string. the objects in CHOICES will return a string.
The return value of any function you put here should be one of The return value of any function you put here should be one of
the objects in CHOICES, properly formatted with DISPLAY-FN (if the objects in CHOICES, properly formatted with DISPLAY-FN (if
that is passed). that is passed).
* To signal that your particular style of prompting is - To signal that your particular style of prompting is
unavailable at the moment, you can also have the function return unavailable at the moment, you can also have the function return
nil. nil.
* To signal that the user quit the prompting process, you can - To signal that the user quit the prompting process, you can
signal `quit' with signal `quit' with
(signal 'quit \"user quit!\")." (signal 'quit \"user quit!\")."
@ -191,9 +191,9 @@ signal `quit' with
The following values are possible: The following values are possible:
`fixed' Indent the snippet to the current column; - `fixed' Indent the snippet to the current column;
`auto' Indent each line of the snippet with `indent-according-to-mode' - `auto' Indent each line of the snippet with `indent-according-to-mode'
Every other value means don't apply any snippet-side indendation Every other value means don't apply any snippet-side indendation
after expansion (the manual per-line \"$>\" indentation still after expansion (the manual per-line \"$>\" indentation still
@ -260,14 +260,15 @@ field"
(defcustom yas/fallback-behavior 'call-other-command (defcustom yas/fallback-behavior 'call-other-command
"How to act when `yas/trigger-key' does *not* expand a snippet. "How to act when `yas/trigger-key' does *not* expand a snippet.
`call-other-command' means try to temporarily disable YASnippet - `call-other-command' means try to temporarily disable YASnippet
and call the next command bound to `yas/trigger-key'. and call the next command bound to `yas/trigger-key'.
`return-nil' means return do nothing. - nil or the symbol `return-nil' mean do nothing. (and
`yas/expand-returns' nil)
An entry (apply COMMAND . ARGS) means interactively call COMMAND, - An entry (apply COMMAND . ARGS) means interactively call
if ARGS is non-nil, call COMMAND non-interactively with ARGS as COMMAND, if ARGS is non-nil, call COMMAND non-interactively
arguments." with ARGS as arguments."
:type '(choice (const :tag "Call previous command" 'call-other-command) :type '(choice (const :tag "Call previous command" 'call-other-command)
(const :tag "Do nothing" 'return-nil)) (const :tag "Do nothing" 'return-nil))
:group 'yasnippet) :group 'yasnippet)
@ -297,10 +298,10 @@ This affects `yas/insert-snippet', `yas/visit-snippet-file'"
When non-nil, submenus for each snippet table will be listed When non-nil, submenus for each snippet table will be listed
under the menu \"Yasnippet\". under the menu \"Yasnippet\".
If set to `real-modes' only submenus whose name more or less - If set to `real-modes' only submenus whose name more or less
corresponds to a major mode are listed. corresponds to a major mode are listed.
If set to `abbreviate', only the current major-mode - If set to `abbreviate', only the current major-mode
menu and the modes set in `yas/mode-symbol' are listed. menu and the modes set in `yas/mode-symbol' are listed.
Any other non-nil value, every submenu is listed." Any other non-nil value, every submenu is listed."
@ -634,10 +635,9 @@ Here's an example:
:help "Display some information about YASsnippet"])) :help "Display some information about YASsnippet"]))
;; Now for the stuff that has direct keybindings ;; Now for the stuff that has direct keybindings
;; ;;
(define-key yas/minor-mode-map (when yas/trigger-key (when (and yas/trigger-key
(read-kbd-macro (stringp yas/trigger-key))
yas/trigger-key)) (define-key yas/minor-mode-map (read-kbd-macro yas/trigger-key) 'yas/expand))
'yas/expand)
(define-key yas/minor-mode-map "\C-c&\C-s" 'yas/insert-snippet) (define-key yas/minor-mode-map "\C-c&\C-s" 'yas/insert-snippet)
(define-key yas/minor-mode-map "\C-c&\C-n" 'yas/new-snippet) (define-key yas/minor-mode-map "\C-c&\C-n" 'yas/new-snippet)
(define-key yas/minor-mode-map "\C-c&\C-v" 'yas/visit-snippet-file) (define-key yas/minor-mode-map "\C-c&\C-v" 'yas/visit-snippet-file)
@ -669,7 +669,8 @@ Key bindings:
;; if a `yas/minor-mode-map' is already built. Else, call ;; if a `yas/minor-mode-map' is already built. Else, call
;; `yas/init-minor-keymap' to build it ;; `yas/init-minor-keymap' to build it
(if (and (cdr yas/minor-mode-map) (if (and (cdr yas/minor-mode-map)
yas/trigger-key) yas/trigger-key
(stringp yas/trigger-key))
(define-key yas/minor-mode-map (read-kbd-macro yas/trigger-key) 'yas/expand) (define-key yas/minor-mode-map (read-kbd-macro yas/trigger-key) 'yas/expand)
(yas/init-minor-keymap)))) (yas/init-minor-keymap))))
@ -1772,7 +1773,11 @@ defined in `yas/fallback-behavior'"
nil) nil)
((eq yas/fallback-behavior 'call-other-command) ((eq yas/fallback-behavior 'call-other-command)
(let* ((yas/minor-mode nil) (let* ((yas/minor-mode nil)
(command (key-binding (read-kbd-macro yas/trigger-key)))) (keys (or (this-command-keys-vector)
(and yas/trigger-key
(stringp yas/trigger-key)
(read-kbd-macro yas/trigger-key))))
(command (key-binding keys)))
(when (commandp command) (when (commandp command)
(setq this-command command) (setq this-command command)
(call-interactively command)))) (call-interactively command))))
@ -1883,21 +1888,36 @@ lurking."
(let ((main-dir (or (and (listp yas/root-directory) (let ((main-dir (or (and (listp yas/root-directory)
(first yas/root-directory)) (first yas/root-directory))
yas/root-directory yas/root-directory
"~/.emacs.d/snippets"))) (setq yas/root-directory "~/.emacs.d/snippets")))
(tables (yas/get-snippet-tables)))
;; HACK! the snippet table created here is a dummy table that
;; holds the correct name so that `yas/make-directory-maybe' can
;; work. The real table, if it does not exist in
;; yas/snippet-tables will be created when the first snippet for
;; that mode is loaded.
;;
(unless (gethash major-mode yas/snippet-tables)
(setq tables (cons (yas/make-snippet-table (symbol-name major-mode))
tables)))
(mapcar #'(lambda (table) (mapcar #'(lambda (table)
(cons table (cons table
(mapcar #'(lambda (subdir) (mapcar #'(lambda (subdir)
(concat main-dir "/" subdir)) (concat main-dir "/" subdir))
(yas/guess-snippet-directories-1 table)))) (yas/guess-snippet-directories-1 table))))
(yas/get-snippet-tables)))) tables)))
(defun yas/make-directory-maybe (table-and-dirs &optional main-table-p) (defun yas/make-directory-maybe (table-and-dirs &optional main-table-string)
"Returns a dir inside TABLE-AND-DIRS, prompts for creation if none exists." "Returns a dir inside TABLE-AND-DIRS, prompts for creation if none exists."
(or (some #'(lambda (dir) (when (file-directory-p dir) dir)) (cdr table-and-dirs)) (or (some #'(lambda (dir) (when (file-directory-p dir) dir)) (cdr table-and-dirs))
(let ((candidate (first (cdr table-and-dirs)))) (let ((candidate (first (cdr table-and-dirs))))
(if (y-or-n-p (format "Guessed directory (%s) for %s table \"%s\" does not exist! Create? " (if (y-or-n-p (format "Guessed directory (%s) for%s%s table \"%s\" does not exist! Create? "
candidate candidate
(or main-table-p (if (gethash (intern (yas/snippet-table-name (car table-and-dirs)))
yas/snippet-tables)
""
" brand new")
(or main-table-string
"") "")
(yas/snippet-table-name (car table-and-dirs)))) (yas/snippet-table-name (car table-and-dirs))))
(progn (progn
@ -1918,7 +1938,8 @@ lurking."
yas/prompt-functions)) yas/prompt-functions))
(first guessed-directories))) (first guessed-directories)))
(chosen)) (chosen))
(setq chosen (yas/make-directory-maybe option)) (setq chosen (yas/make-directory-maybe option (unless choose-instead-of-guess
" main")))
(unless (or chosen (unless (or chosen
choose-instead-of-guess) choose-instead-of-guess)
(if (y-or-n-p (format "Continue guessing for other active tables %s? " (if (y-or-n-p (format "Continue guessing for other active tables %s? "
@ -1939,15 +1960,18 @@ lurking."
(find-file-other-window (concat name (find-file-other-window (concat name
".yasnippet")) ".yasnippet"))
(snippet-mode) (snippet-mode)
(yas/expand-snippet (format (unless (and choose-instead-of-guess
"\ (not (y-or-n-p "Insert a snippet with useful headers? ")))
(yas/expand-snippet (format
"\
# -*- mode: snippet -*- # -*- mode: snippet -*-
# name: %s # name: %s
# key: $1${2: # key: $1${2:
# binding: \"${3:keybinding}\"}${4: # binding: \"${3:keybinding}\"}${4:
# expand-env: ((${5:some-var} ${6:some-value}))} # expand-env: ((${5:some-var} ${6:some-value}))}
# -- # --
$0" name)))))) $0" name))))
(message "[yas] aborted snippet creation."))))
(defun yas/find-snippets (&optional same-window ) (defun yas/find-snippets (&optional same-window )
"Look for user snippets in guessed current mode's directory. "Look for user snippets in guessed current mode's directory.
@ -1968,7 +1992,7 @@ there, otherwise, proposes to create the first option returned by
(let* ((guessed-directories (yas/guess-snippet-directories)) (let* ((guessed-directories (yas/guess-snippet-directories))
(chosen) (chosen)
(buffer)) (buffer))
(setq chosen (yas/make-directory-maybe (first guessed-directories) "main")) (setq chosen (yas/make-directory-maybe (first guessed-directories) " main"))
(unless chosen (unless chosen
(if (y-or-n-p (format "Continue guessing for other active tables %s? " (if (y-or-n-p (format "Continue guessing for other active tables %s? "
(mapcar #'(lambda (table-and-dirs) (mapcar #'(lambda (table-and-dirs)