Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add: some keybinding snippet for efficient create a new snippet in snippet-mode #293

Closed
wants to merge 1 commit into from

4 participants

Billy João Távora Noam Postavsky Le Wang
Billy

Add: some keybinding snippet for efficient create a new snippet in snippet-mode

Billy

Hi, I have resubmit my commit.

  1. change hot-key prefix with C-c.
  2. change function name with yas-??-??
  3. change some comment.
  4. add .yas-setup.el in snippet-mode directory.

You can have a look ...

João Távora

Thanks. I will have a decent look at this, but it will not be in the near future.

Le Wang

don't define functions outside of the yas namespace.

Billy

thanks. I will resend pull quest when I change my code..

Noam Postavsky
Collaborator

Closing. Yasnippet repository no longer has snippets, consider submitting to https://github.com/AndreaCrotti/yasnippet-snippets instead.

Noam Postavsky npostavs closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 30, 2012
  1. Billy
This page is out of date. Refresh to see the latest.
52 snippets/snippet-mode/.yas-setup.el
View
@@ -0,0 +1,52 @@
+;; -*-Emacs-Lisp-*-
+
+(defun yas-strip-selected-text ()
+ "strip leading whitespace, first and last blank line."
+ (replace-regexp-in-string
+ ".*\\(\n\\)\\'" ""
+ (replace-regexp-in-string
+ "\\`\\(\n\\).*" ""
+ (replace-regexp-in-string
+ "\\`\\([ \t]+\\).*" ""
+ yas-selected-text nil nil 1) nil nil 1) nil nil 1))
+
+(defun yas-downcase (string)
+ "split capitalize word with underscore, then downcase."
+ (downcase (replace-regexp-in-string "[a-z]\\([A-Z]\\)" "_\\&" string nil nil 1)))
+
+(defun yas-capitalize (string)
+ "merge underscore-split word into a capitalize form."
+ (replace-regexp-in-string "_\\|@\\|\\$" "" (capitalize string)))
+
+(defun erase (string)
+ "erase those string when this field content is empty."
+ (and (string-match "[^\s\t]" yas-text) string))
+
+(defun erase-if-quote (string)
+ "erase those string when this field content contain quote mark."
+ (and (not (string-match "^[\"']\\|^[\s\t]*$" yas-text)) string))
+
+(defun add_if_comma (string)
+ "add those string when this field content contain a comma."
+ (and (string-match "," yas-text) string))
+
+(defun add (string)
+ "add those string when this field content is empty."
+ (and (not (yas-text)) string))
+
+(defun erase1 (string)
+ "erase those string when region is a one-line string."
+ (and (string-match "\n" yas-selected-text) string))
+
+(defun add1 (string)
+ "add those string when region is a one-line string."
+ (and (not (string-match "\n" yas-selected-text)) string))
+
+(defun end ()
+ "add a trailing newline when region is multi-line string."
+ (and (string-match "\n" yas-selected-text) "
+"))
+
+(defun space ()
+ "add a space when region is multi-line string."
+ (and (string-match "\n" yas-selected-text) " "))
6 snippets/snippet-mode/add
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: add a string when field content is empty.
+# binding: M-c a
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\${${1:1}:$(add "$2")}
6 snippets/snippet-mode/add1
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: add a string when snippet is a one-line string.
+# key: add
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\`(add1 "$2")\`
6 snippets/snippet-mode/binding/c
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: capitalize field
+# binding: C-c c
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\${${1:1}:$(yas-capitalize `(replace-regexp-in-string ".*" "yas-text" yas-selected-text t nil)`)}
6 snippets/snippet-mode/binding/d
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: downcase field.
+# binding: C-c d
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\${${1:1}:$(yas-downcase `(replace-regexp-in-string ".*" "yas-text" yas-selected-text t nil)`)}
6 snippets/snippet-mode/binding/e
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: erase a string when field content is empty.
+# binding: C-c e
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\${${1:1}:$(erase "`(replace-regexp-in-string "\"" "\\\\\\\\\\\\\"" yas-selected-text t nil)`")}
6 snippets/snippet-mode/binding/e1
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: earse a string when region is a one-line string.
+# binding: C-c e
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\`(erase1 "`(replace-regexp-in-string "\"" "\\\\\"" yas-selected-text t nil)`")\`
6 snippets/snippet-mode/binding/e2
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: erase a string when field content contain quote mark.
+# binding: C-c e
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\${${1:1}:$(erase-if-quote "`(replace-regexp-in-string "\"" "\\\\\\\\\\\\\"" yas-selected-text t nil)`")}
6 snippets/snippet-mode/binding/i
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: insert a field skeleton
+# binding: C-c i
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\${${1:1}:`yas-selected-text`}
6 snippets/snippet-mode/binding/m
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: insert a field candidate menu skeleton.
+# binding: C-c m
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\${${1:1}:${2:$}$(yas-choose-value '("`yas-selected-text`" "${3:item}"$4))}
6 snippets/snippet-mode/binding/r
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: insert a field query-replace transformation skeleton.
+# binding: C-c r
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\${${1:1}:$(replace-regexp-in-string "${2:[a-zA-Z_]+}" "${3:}" `(replace-regexp-in-string ".*" "yas-text" yas-selected-text t nil)` t nil)}
6 snippets/snippet-mode/binding/s
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: insert a self input transformation skeleton.
+# binding: C-c s
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\${${1:1}:`yas-selected-text`$(${3:reflection-fn} `(replace-regexp-in-string ".*" "yas-text" yas-selected-text t nil)`)}
6 snippets/snippet-mode/binding/t
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: insert a transformation skeleton.
+# binding: C-c t
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\${${1:1}:$(${2:reflection-fn} `(replace-regexp-in-string ".*" "yas-text" yas-selected-text t nil)`)}
6 snippets/snippet-mode/binding/u
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: upcase a field
+# binding: C-c u
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\${${1:1}:$(upcase `(replace-regexp-in-string ".*" "yas-text" yas-selected-text t nil)`)}
5 snippets/snippet-mode/comma
View
@@ -0,0 +1,5 @@
+# -*- mode: snippet -*-
+# name: add a string when field content contain comma.
+# key: comma
+# --
+\${${1:1}:$(add-if-comma "$2")}
6 snippets/snippet-mode/end
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: add a trailing newline when region is multi-line string.
+# key: end
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\`(end)\`
6 snippets/snippet-mode/space
View
@@ -0,0 +1,6 @@
+# -*- mode: snippet -*-
+# name: add a space when region is multi-line string.
+# key: space
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
+# --
+\`(space)\`
Something went wrong with that request. Please try again.