Skip to content
This repository

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 January 01, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Sep 30, 2012
Billy Add: some keybinding snippet and function for efficient create new sn…
…ippet in snippet-mode
c2373fc
This page is out of date. Refresh to see the latest.
52  snippets/snippet-mode/.yas-setup.el
... ...
@@ -0,0 +1,52 @@
  1
+;; -*-Emacs-Lisp-*-
  2
+
  3
+(defun yas-strip-selected-text ()
  4
+  "strip leading whitespace, first and last blank line."
  5
+  (replace-regexp-in-string
  6
+   ".*\\(\n\\)\\'" ""
  7
+   (replace-regexp-in-string
  8
+    "\\`\\(\n\\).*" ""
  9
+    (replace-regexp-in-string
  10
+     "\\`\\([ \t]+\\).*" ""
  11
+     yas-selected-text nil nil 1) nil nil 1) nil nil 1))
  12
+
  13
+(defun yas-downcase (string)
  14
+  "split capitalize word with underscore, then downcase."
  15
+  (downcase (replace-regexp-in-string "[a-z]\\([A-Z]\\)" "_\\&" string nil nil 1)))
  16
+
  17
+(defun yas-capitalize (string)
  18
+  "merge underscore-split word into a capitalize form."
  19
+  (replace-regexp-in-string "_\\|@\\|\\$" "" (capitalize string)))
  20
+
  21
+(defun erase (string)
  22
+  "erase those string when this field content is empty."
  23
+  (and (string-match "[^\s\t]" yas-text) string))
  24
+
  25
+(defun erase-if-quote (string)
  26
+  "erase those string when this field content contain quote mark."
  27
+  (and (not (string-match "^[\"']\\|^[\s\t]*$" yas-text)) string))
  28
+
  29
+(defun add_if_comma (string)
  30
+  "add those string when this field content contain a comma."
  31
+  (and (string-match "," yas-text) string))
  32
+
  33
+(defun add (string)
  34
+  "add those string when this field content is empty."
  35
+  (and (not (yas-text)) string))
  36
+
  37
+(defun erase1 (string)
  38
+  "erase those string when region is a one-line string."
  39
+  (and (string-match "\n" yas-selected-text) string))
  40
+
  41
+(defun add1 (string)
  42
+  "add those string when region is a one-line string."
  43
+  (and (not (string-match "\n" yas-selected-text)) string))
  44
+
  45
+(defun end ()
  46
+  "add a trailing newline when region is multi-line string."
  47
+  (and (string-match "\n" yas-selected-text) "
  48
+"))
  49
+
  50
+(defun space ()
  51
+  "add a space when region is multi-line string."
  52
+  (and (string-match "\n" yas-selected-text) " "))
6  snippets/snippet-mode/add
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: add a string when field content is empty.
  3
+# binding: M-c a
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\${${1:1}:$(add "$2")}
6  snippets/snippet-mode/add1
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: add a string when snippet is a one-line string.
  3
+# key: add
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\`(add1 "$2")\`
6  snippets/snippet-mode/binding/c
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: capitalize field
  3
+# binding: C-c c
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\${${1:1}:$(yas-capitalize `(replace-regexp-in-string ".*" "yas-text" yas-selected-text t nil)`)}
6  snippets/snippet-mode/binding/d
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: downcase field.
  3
+# binding: C-c d
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\${${1:1}:$(yas-downcase `(replace-regexp-in-string ".*" "yas-text" yas-selected-text t nil)`)}
6  snippets/snippet-mode/binding/e
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: erase a string when field content is empty.
  3
+# binding: C-c e
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\${${1:1}:$(erase "`(replace-regexp-in-string "\"" "\\\\\\\\\\\\\"" yas-selected-text t nil)`")}
6  snippets/snippet-mode/binding/e1
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: earse a string when region is a one-line string.
  3
+# binding: C-c e
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\`(erase1 "`(replace-regexp-in-string "\"" "\\\\\"" yas-selected-text t nil)`")\`
6  snippets/snippet-mode/binding/e2
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: erase a string when field content contain quote mark.
  3
+# binding: C-c e
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\${${1:1}:$(erase-if-quote "`(replace-regexp-in-string "\"" "\\\\\\\\\\\\\"" yas-selected-text t nil)`")}
6  snippets/snippet-mode/binding/i
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: insert a field skeleton
  3
+# binding: C-c i
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\${${1:1}:`yas-selected-text`}
6  snippets/snippet-mode/binding/m
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: insert a field candidate menu skeleton.
  3
+# binding: C-c m
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\${${1:1}:${2:$}$(yas-choose-value '("`yas-selected-text`" "${3:item}"$4))}
6  snippets/snippet-mode/binding/r
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: insert a field query-replace transformation skeleton.
  3
+# binding: C-c r
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\${${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
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: insert a self input transformation skeleton.
  3
+# binding: C-c s
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\${${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
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: insert a transformation skeleton.
  3
+# binding: C-c t
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\${${1:1}:$(${2:reflection-fn} `(replace-regexp-in-string ".*" "yas-text" yas-selected-text t nil)`)}
6  snippets/snippet-mode/binding/u
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: upcase a field
  3
+# binding: C-c u
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\${${1:1}:$(upcase `(replace-regexp-in-string ".*" "yas-text" yas-selected-text t nil)`)}
5  snippets/snippet-mode/comma
... ...
@@ -0,0 +1,5 @@
  1
+# -*- mode: snippet -*-
  2
+# name: add a string when field content contain comma.
  3
+# key: comma
  4
+# --
  5
+\${${1:1}:$(add-if-comma "$2")}
6  snippets/snippet-mode/end
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: add a trailing newline when region is multi-line string.
  3
+# key: end
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\`(end)\`
6  snippets/snippet-mode/space
... ...
@@ -0,0 +1,6 @@
  1
+# -*- mode: snippet -*-
  2
+# name: add a space when region is multi-line string.
  3
+# key: space
  4
+# contributor: Billy.Zheng/zw963 (zw963@163.com)
  5
+# --
  6
+\`(space)\`
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.