[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 0f67c07 030/177: Merge pull request #424 from ljos/de/acti
From: |
João Távora |
Subject: |
[elpa] master 0f67c07 030/177: Merge pull request #424 from ljos/de/activate-extra-mode |
Date: |
Sat, 28 Mar 2015 15:40:36 +0000 |
branch: master
commit 0f67c07dddeaf1f5c4a8eb1ad7d25828475d51f0
Merge: 6ee3d2e d5d6e45
Author: João Távora <address@hidden>
Commit: João Távora <address@hidden>
Merge pull request #424 from ljos/de/activate-extra-mode
Feature: de/activate-extra-mode
---
yasnippet-tests.el | 25 ++++++++++++++++++++++
yasnippet.el | 58 +++++++++++++++++++++++++++++++++++++++------------
2 files changed, 69 insertions(+), 14 deletions(-)
diff --git a/yasnippet-tests.el b/yasnippet-tests.el
index 6147b1d..1d770b4 100644
--- a/yasnippet-tests.el
+++ b/yasnippet-tests.el
@@ -601,6 +601,31 @@ TODO: be meaner"
(should (eq (key-binding [(tab)]) 'yas-expand))
(should (eq (key-binding (kbd "TAB")) 'yas-expand))))
+(ert-deftest test-yas-activate-extra-modes ()
+ "Given a symbol, `yas-activate-extra-mode' should be able to
+add the snippets associated with the given mode."
+ (with-temp-buffer
+ (emacs-lisp-mode)
+ (yas-minor-mode-on)
+ (yas-activate-extra-mode 'markdown-mode)
+ (should (eq 'markdown-mode (car yas--extra-modes)))
+ (yas-should-expand '(("_" . "_Text_ ")))
+ (yas-should-expand '(("car" . "(car )")))))
+
+(ert-deftest test-yas-deactivate-extra-modes ()
+ "Given a symbol, `yas-deactive-extra-mode' should be able to
+remove one of the extra modes that is present in the current
+buffer."
+ (with-temp-buffer
+ (emacs-lisp-mode)
+ (yas-minor-mode-on)
+ (yas-activate-extra-mode 'markdown-mode)
+ (should (eq 'markdown-mode (car yas--extra-modes)))
+ (yas-deactivate-extra-mode 'markdown-mode)
+ (should-not (eq 'markdown-mode (car yas--extra-modes)))
+ (yas-should-not-expand '("_"))
+ (yas-should-expand '(("car" . "(car )")))))
+
;;; Helpers
;;;
diff --git a/yasnippet.el b/yasnippet.el
index c7aecfa..eb7afc6 100644
--- a/yasnippet.el
+++ b/yasnippet.el
@@ -3,7 +3,7 @@
;; Copyright (C) 2008-2013 Free Software Foundation, Inc.
;; Authors: pluskid <address@hidden>, João Távora <address@hidden>
;; Maintainer: João Távora <address@hidden>
-;; Version: 0.8.0
+;; Version: 0.8.1
;; Package-version: 0.8.0
;; X-URL: http://github.com/capitaomorte/yasnippet
;; Keywords: convenience, emulation
@@ -48,13 +48,6 @@
;; The deprecated `yas/root-directory' aliases this variable
;; for backward-compatibility.
;;
-;; `yas-extra-modes'
-;;
-;; A local variable that you can set in a hook to override
-;; snippet-lookup based on major mode. It is a list of
-;; symbols that correspond to subdirectories of
-;; `yas-snippet-dirs' and is used for deciding which
-;; snippets to consider for the active buffer.
;;
;; Major commands are:
;;
@@ -68,6 +61,11 @@
;;
;; Prompts you for a directory hierarchy of snippets to load.
;;
+;; M-x yas-activate-extra-mode
+;;
+;; Prompts you for an extra mode to add snippets for in the
+;; current buffer.
+;;
;; M-x yas-insert-snippet
;;
;; Prompts you for possible snippet expansion if that is
@@ -309,7 +307,7 @@ When non-nil, submenus for each snippet table will be listed
under the menu \"Yasnippet\".
- If set to `abbreviate', only the current major-mode
-menu and the modes set in `yas-extra-modes' are listed.
+menu and the modes set in `yas--extra-modes' are listed.
- If set to `full', every submenu is listed
@@ -657,11 +655,12 @@ snippet itself contains a condition that returns the
symbol
(defvar yas-minor-mode-map (yas--init-minor-keymap)
"The keymap used when `yas-minor-mode' is active.")
-(defvar yas-extra-modes nil
- "A list of modes for which to also lookup snippets.
+(defvar yas--extra-modes nil
+ "An internal list of modes for which to also lookup snippets.
This variable probably makes more sense as buffer-local, so
ensure your use `make-local-variable' when you set it.")
+(define-obsolete-variable-alias 'yas-extra-modes 'yas--extra-modes "0.8.1")
(defvar yas--tables (make-hash-table)
"A hash table of mode symbols to `yas--table' objects.")
@@ -713,7 +712,7 @@ and friends."
unless (memq neighbour explored)
append (funcall dfs neighbour explored)))))
- (remove-duplicates (append yas-extra-modes
+ (remove-duplicates (append yas--extra-modes
(funcall dfs major-mode)))))
(defvar yas-minor-mode-hook nil
@@ -762,6 +761,37 @@ Key bindings:
(remove-hook 'post-command-hook 'yas--post-command-handler t)
(remove-hook 'emulation-mode-map-alists 'yas--direct-keymaps))))
+(defun yas-activate-extra-mode (mode)
+ "Activates the snippets for the given `mode' in the buffer.
+
+The function can be called in the hook of a minor mode to
+activate snippets associated with that mode."
+ (interactive
+ (let (modes
+ symbol)
+ (maphash (lambda (k _)
+ (setq modes (cons (list k) modes)))
+ yas--parents)
+ (setq symbol (completing-read
+ "Activate mode: " modes nil t))
+ (list
+ (when (not (string= "" symbol))
+ (intern symbol)))))
+ (when mode
+ (make-variable-buffer-local 'yas--extra-modes)
+ (add-to-list 'yas--extra-modes mode)
+ (yas--load-pending-jits)))
+
+(defun yas-deactivate-extra-mode (mode)
+ "Deactivates the snippets for the given `mode' in the buffer."
+ (interactive
+ (list (intern
+ (completing-read
+ "Deactivate mode: " (mapcar #'list yas--extra-modes) nil t))))
+ (setq yas--extra-modes
+ (remove mode
+ yas--extra-modes)))
+
(defvar yas-dont-activate '(minibufferp)
"If non-nil don't let `yas-global-mode' affect some buffers.
@@ -889,8 +919,8 @@ Has the following fields:
`yas--table-name'
A symbol name normally corresponding to a major mode, but can
- also be a pseudo major-mode to be referenced in
- `yas-extra-modes', for example.
+ also be a pseudo major-mode to be used in
+ `yas-activate-extra-mode', for example.
`yas--table-hash'
- [elpa] master d7b2b89 027/177: widen before deleting regions, (continued)
- [elpa] master d7b2b89 027/177: widen before deleting regions, João Távora, 2015/03/28
- [elpa] master 84b7e69 025/177: Merge pull request #423 from npostavs/load-snippet-ui, João Távora, 2015/03/28
- [elpa] master 43a484e 028/177: add: external test for issue #404, João Távora, 2015/03/28
- [elpa] master d5d6e45 026/177: Feature: de/activate-extra-mode, João Távora, 2015/03/28
- [elpa] master 6ee3d2e 029/177: Closes #404: merge remote-tracking branch 'npostavs/widen', João Távora, 2015/03/28
- [elpa] master a4a7e5e 032/177: fix typo: .yas.parents -> .yas-parents, João Távora, 2015/03/28
- [elpa] master fdd550a 035/177: Fix screencast link., João Távora, 2015/03/28
- [elpa] master bc4cfbb 033/177: yas/ -> yas-, João Távora, 2015/03/28
- [elpa] master b20f0a4 034/177: fix exporting of doc strings for org manual, João Távora, 2015/03/28
- [elpa] master f5457df 031/177: Go back to org manual, João Távora, 2015/03/28
- [elpa] master 0f67c07 030/177: Merge pull request #424 from ljos/de/activate-extra-mode,
João Távora <=
- [elpa] master 8e8320f 036/177: remove reference to yas-trigger-key, João Távora, 2015/03/28
- [elpa] master 042837d 038/177: Migrate to snippets maintained by the TextMate community, João Távora, 2015/03/28
- [elpa] master 81e26b4 039/177: Merge pull request #431 from ignisf/update-snippet-submodules, João Távora, 2015/03/28
- [elpa] master c7c6516 040/177: don't use link abbreviations, João Távora, 2015/03/28
- [elpa] master d451fef 041/177: rename manual.org to index.org, João Távora, 2015/03/28
- [elpa] master 5acc976 043/177: split symbol reference into separate file, João Távora, 2015/03/28
- [elpa] master fd8423c 045/177: fix links, João Távora, 2015/03/28
- [elpa] master 7b82424 046/177: move index.org subsection into snippet-expansion.org, João Távora, 2015/03/28
- [elpa] master 3002594 037/177: Merge pull request #430 from npostavs/org-doc, João Távora, 2015/03/28
- [elpa] master 875ef77 044/177: move index.org subsection into snippet-organization.org, João Távora, 2015/03/28