From 3acb8c577306a48b6e4f8aa7735e851886ae3d57 Mon Sep 17 00:00:00 2001 From: thisirs Date: Mon, 5 Aug 2013 00:26:49 +0200 Subject: [PATCH 1/3] Make default snippet customizable --- yasnippet.el | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/yasnippet.el b/yasnippet.el index f44a994..0a94ffb 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -187,6 +187,19 @@ as the default for storing the user's new snippets." (defvaralias 'yas/root-directory 'yas-snippet-dirs) +(defcustom yas-new-snippet-default "\ +# -*- mode: snippet -*- +# name: $1 +# key: ${2:${1:$(replace-regexp-in-string \"\\\\\\\\(\\\\\\\\w+\\\\\\\\).*\" \"\\\\\\\\1\" yas-text)}}${3: +# binding: ${4:direct-keybinding}}${5: +# expand-env: ((${6:some-var} ${7:some-value}))}${8: +# type: command} +# -- +$0" + "Default snippet to use when creating a new snippet." + :type 'string + :group 'yasnippet) + (defcustom yas-prompt-functions '(yas-x-prompt yas-dropdown-prompt yas-completing-prompt @@ -2514,15 +2527,7 @@ NO-TEMPLATE is non-nil." (set (make-local-variable 'yas--guessed-modes) (mapcar #'(lambda (d) (yas--table-mode (car d))) guessed-directories)) - (unless no-template (yas-expand-snippet "\ -# -*- mode: snippet -*- -# name: $1 -# key: ${2:${1:$(replace-regexp-in-string \"\\\\\\\\(\\\\\\\\w+\\\\\\\\).*\" \"\\\\\\\\1\" yas-text)}}${3: -# binding: ${4:direct-keybinding}}${5: -# expand-env: ((${6:some-var} ${7:some-value}))}${8: -# type: command} -# -- -$0")))) + (unless no-template (yas-expand-snippet yas-new-snippet-default)))) (defun yas--compute-major-mode-and-parents (file) "Given FILE, find the nearest snippet directory for a given mode. From 80bb95326b38de8109309f8d84b5e2f49fe92ebb Mon Sep 17 00:00:00 2001 From: thisirs Date: Mon, 19 Aug 2013 22:47:14 +0200 Subject: [PATCH 2/3] Factor out embedded elisp code * yasnippet.el (yas--key-from-desc): Added --- yasnippet.el | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/yasnippet.el b/yasnippet.el index 0a94ffb..738a63f 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -190,7 +190,7 @@ as the default for storing the user's new snippets." (defcustom yas-new-snippet-default "\ # -*- mode: snippet -*- # name: $1 -# key: ${2:${1:$(replace-regexp-in-string \"\\\\\\\\(\\\\\\\\w+\\\\\\\\).*\" \"\\\\\\\\1\" yas-text)}}${3: +# key: ${2:${1:$(yas--key-from-desc yas-text)}}${3: # binding: ${4:direct-keybinding}}${5: # expand-env: ((${6:some-var} ${7:some-value}))}${8: # type: command} @@ -1523,6 +1523,10 @@ Here's a list of currently recognized directives: (cdr where) (yas--template-expand-env yas--current-template))))))) +(defun yas--key-from-desc (text) + "Return a yasnippet key from a description string TEXT." + (replace-regexp-in-string "\\(\\w+\\).*" "\\1" text)) + ;;; Popping up for keys and templates From 501857e767962be05ac5979b87ba52cc5190b5ea Mon Sep 17 00:00:00 2001 From: thisirs Date: Mon, 19 Aug 2013 22:52:19 +0200 Subject: [PATCH 3/3] Assume NO-TEMPLATE is non-nil if `yas-new-snippet-default' is nil --- yasnippet.el | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/yasnippet.el b/yasnippet.el index 738a63f..b279f12 100644 --- a/yasnippet.el +++ b/yasnippet.el @@ -196,7 +196,8 @@ as the default for storing the user's new snippets." # type: command} # -- $0" - "Default snippet to use when creating a new snippet." + "Default snippet to use when creating a new snippet. If nil, +don't use any snippet." :type 'string :group 'yasnippet) @@ -2531,7 +2532,8 @@ NO-TEMPLATE is non-nil." (set (make-local-variable 'yas--guessed-modes) (mapcar #'(lambda (d) (yas--table-mode (car d))) guessed-directories)) - (unless no-template (yas-expand-snippet yas-new-snippet-default)))) + (if (and (not no-template) yas-new-snippet-default) + (yas-expand-snippet yas-new-snippet-default)))) (defun yas--compute-major-mode-and-parents (file) "Given FILE, find the nearest snippet directory for a given mode.