Created
July 9, 2013 15:40
-
-
Save yuutayamada/5958399 to your computer and use it in GitHub Desktop.
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
(require 'zencoding-mode) | |
(eval-when-compile (require 'cl)) | |
(require 'flyspell) | |
(defun my/zencoding-expand () | |
"Execute zencoding if current point is in string and | |
you can execute from minibuffer if you push C-u before this command" | |
(interactive) | |
(lexical-let* | |
((quote "['\"]") | |
(statement "") | |
(correct-condition-p | |
(lambda () | |
(and (flyspell-generic-progmode-verify) | |
(case (face-at-point) | |
(font-lock-string-face t) | |
(font-lock-comment-face nil) | |
(t nil))))) | |
(move-start-point | |
(lambda () | |
(if (funcall correct-condition-p) | |
(while (and (funcall correct-condition-p) | |
(search-backward-regexp quote)))) | |
(forward-char 1))) | |
(move-end-point | |
(lambda () | |
(while (flyspell-generic-progmode-verify) | |
(forward-char 1)) | |
(backward-char 2))) | |
(set-statement | |
(lambda () | |
(funcall move-start-point) | |
(set-mark-command nil) | |
(funcall move-end-point) | |
(kill-region (region-beginning) (region-end)) | |
(setq statement (car kill-ring)))) | |
(do-zencoding-from-minibuffer | |
(lambda () | |
(setq statement (read-from-minibuffer "zencoding: ")) | |
(insert (zencoding-transform (car (zencoding-expr statement)))))) | |
(flyspell-state (if flyspell-mode t nil))) | |
(when (and (funcall correct-condition-p) | |
(case major-mode | |
(js2-mode t) | |
(javascript-mode t) | |
(t nil))) | |
(if current-prefix-arg | |
(funcall do-zencoding-from-minibuffer) | |
(when flyspell-state (turn-off-flyspell)) | |
(funcall move-start-point) | |
(set-mark-command nil) | |
(funcall move-end-point) | |
(funcall set-statement) | |
(insert (replace-regexp-in-string | |
"[\n ]" "" | |
(zencoding-transform (car (zencoding-expr statement))))) | |
(when flyspell-state (turn-on-flyspell)))))) | |
;; if you want to use with yasnippet | |
(defadvice yas-expand-from-trigger-key | |
(around ad-add-zencoding-expand activate) | |
(if (flyspell-generic-progmode-verify) | |
(my/zencoding-expand) | |
ad-do-it)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment