Created
September 14, 2012 15:39
-
-
Save coldnew/3722722 to your computer and use it in GitHub Desktop.
a org-mode easy-template like plugin for yasnippet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun coldnew/major-mode-expand () | |
"Try to complete a structure template before point like org-mode does. | |
This looks for strings like \"<e\" on an otherwise empty line and | |
expands them. | |
Before use this function, you muse setup `major-mode-name'-expand-alist variable. | |
Take emacs-lisp-mode as example, if you wand to use <r to expand your snippet `require' | |
in yasnippet, you muse setup the emacs-lisp-mode-expand-alist variable. | |
(setq emacs-lisp-expand-alist '((\"r\" . \"require\")))" | |
(let* ((l (buffer-substring (point-at-bol) (point))) | |
(expand-symbol (intern (concat (symbol-name major-mode) "-expand-alist"))) | |
(expand-alist (if (boundp expand-symbol) (symbol-value expand-symbol) nil)) | |
a) | |
(when (and (looking-at "[ \t]*$") | |
(string-match "^[ \t]*<\\([a-zA-Z]+\\)$" l) | |
(setq a (assoc (match-string 1 l) expand-alist))) | |
(backward-delete-char (1+ (length (car-safe a)))) | |
(insert (cdr-safe a)) | |
t))) | |
(defadvice yas-expand (before coldnew/major-mode-expand activate) (coldnew/major-mode-expand)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment