From 36184e0bc784dd3e6731284c60466e0db0ae5eb9 Mon Sep 17 00:00:00 2001 From: Zhang Chiyuan Date: Fri, 8 Aug 2008 05:04:42 +0000 Subject: [PATCH] forget to commit for 0.5.6? --- doc/changelog.rst | 20 ++++++++++++++++++++ doc/faq.rst | 42 ++++++++++++++++++++++++++++++++++++++++++ yasnippet.el | 23 ++++++++++++++++++----- 3 files changed, 80 insertions(+), 5 deletions(-) diff --git a/doc/changelog.rst b/doc/changelog.rst index f70305f..a990e80 100644 --- a/doc/changelog.rst +++ b/doc/changelog.rst @@ -6,6 +6,26 @@ ChangeLog :Contact: pluskid@gmail.com :Date: 2008-03-22 +0.5.6 / 2008-08-07 +================== + +* Added a buffer local variable ``yas/dont-activate`` to turn off + ``yas/minor-mode`` in some major modes. See `Issue 29 + `_. +* Make the environment of elisp evaluation more friendly to + ``(current-column)``. +* Fixed the regular expression bug in python-mode snippets. +* Use filename or full key extension for snippet name if no ``name`` + property is defined. + +0.5.5 / 2008-05-29 +================== + +* Tweak ``yas/extra-mode-hooks`` so that it can be more easily + customized. +* Add an entry in FAQ about why ``TAB`` key doesn't work in some + modes. + 0.5.4 / 2008-05-15 ================== diff --git a/doc/faq.rst b/doc/faq.rst index e136cd0..f5b18e3 100644 --- a/doc/faq.rst +++ b/doc/faq.rst @@ -17,3 +17,45 @@ the snippet file. Note some editors will automatically add a newline for you. In Emacs, if you set ``require-final-newline`` to ``t``, it will add the final newline for you automatically. + +Why TAB key doesn't expand a snippet? +===================================== + +First check the mode line to see if there's ``yas``. If no, then try +``M-x yas/minor-mode-on`` to manually turn on ``yas/minor-mode`` and +try to expand the snippet again. If it works, then, you can add the +following code to your ``.emacs`` *before* loading YASnippet: + +.. sourcecode:: lisp + + (setq yas/extra-mode-hooks '(the-major-mode)) + +where ``the-major-mode`` is the major mode in which ``yas/minor-mode`` +isn't enabled by default. + +If ``yas/minor-mode`` is on but the snippet still not expanded. Then +try to see what command is bound to the ``TAB`` key: press ``C-h k`` +and then press ``TAB``. Emacs will show you the result. + +You'll see a buffer prompted by Emacs saying that ``TAB runs the +command ...``. Alternatively, you might see `` runs the command +...``, note the difference between ``TAB`` and ```` where the +latter has priority. If you see ```` bound to a command other +than ``yas/expand``, (e.g. in ``org-mode``) you can try the following +code to work around: + +.. sourcecode:: lisp + + (add-hook 'org-mode-hook + '(lambda () + (make-variable-buffer-local 'yas/trigger-key) + (setq yas/trigger-key [tab]))) + +replace ``org-mode-hook`` with the major mode hook you are dealing +with (``C-h m`` to see what major mode you are in). + +If it says ``TAB`` but YASnippet still doesn't work, check your +configuration and you may also ask for help on the `discussion group +`_. 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``). diff --git a/yasnippet.el b/yasnippet.el index 845b7da..c225653 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -3,7 +3,7 @@ ;; Copyright 2008 pluskid ;; ;; Author: pluskid -;; Version: 0.5.4 +;; Version: 0.5.6 ;; X-URL: http://code.google.com/p/yasnippet/ ;; This file is free software; you can redistribute it and/or modify @@ -40,6 +40,10 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; User customizable variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(defvar yas/dont-activate nil + "If set to t, don't activate yas/minor-mode automatically.") +(make-variable-buffer-local 'yas/dont-activate) + (defvar yas/key-syntaxes (list "w" "w_" "w_." "^ ") "A list of syntax of a key. This list is tried in the order to try to find a key. For example, if the list is '(\"w\" \"w_\"). @@ -107,10 +111,14 @@ them. `yas/window-system-popup-function' is used instead when in a window system.") (defvar yas/extra-mode-hooks - '(ruby-mode-hook actionscript-mode-hook ox-mode-hook python-mode-hook) + '() "A list of mode-hook that should be hooked to enable yas/minor-mode. Most modes need no special consideration. Some mode (like ruby-mode) doesn't call `after-change-major-mode-hook' need to be hooked explicitly.") +(mapc '(lambda (x) + (add-to-list 'yas/extra-mode-hooks + x)) + '(ruby-mode-hook actionscript-mode-hook ox-mode-hook python-mode-hook)) (defvar yas/after-exit-snippet-hook '() @@ -178,7 +186,7 @@ to expand. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Internal variables ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -(defvar yas/version "0.5.4") +(defvar yas/version "0.5.6") (defvar yas/snippet-tables (make-hash-table) "A hash table of snippet tables corresponding to each major-mode.") @@ -252,6 +260,11 @@ You can customize the key through `yas/trigger-key'." :group 'editing (define-key yas/minor-mode-map yas/trigger-key 'yas/expand)) +(defun yas/minor-mode-auto-on () + "Turn on YASnippet minor mode unless `yas/dont-activate' is +set to t." + (unless yas/dont-activate + (yas/minor-mode-on))) (defun yas/minor-mode-on () "Turn on YASnippet minor mode." (interactive) @@ -1054,10 +1067,10 @@ content of the file is the template." (defun yas/initialize () "Do necessary initialization." (add-hook 'after-change-major-mode-hook - 'yas/minor-mode-on) + 'yas/minor-mode-auto-on) (dolist (hook yas/extra-mode-hooks) (add-hook hook - 'yas/minor-mode-on)) + 'yas/minor-mode-auto-on)) (add-hook 'yas/minor-mode-on-hook 'yas/ensure-minor-mode-priority) (when yas/use-menu