-
Notifications
You must be signed in to change notification settings - Fork 2
/
zencoding-builder.el
49 lines (41 loc) · 1.84 KB
/
zencoding-builder.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
;; (require 'zencoding-builder)
;; (define-key zencoding-mode-keymap (kbd "M-RET") 'zencoding-builder)
(defvar zencoding-builder-start-point nil)
(make-variable-buffer-local 'zencoding-builder-start-point)
(defvar zencoding-builder-end-point nil)
(make-variable-buffer-local 'zencoding-builder-end-point)
(defvar zencoding-builder-window nil)
(make-variable-frame-local 'zencoding-builder-window)
(defun zencoding-expand-from-minibuffer ()
(condition-case v
(let ((expr (with-selected-window (minibuffer-window) (minibuffer-contents)))
markup markup-filled)
(when expr
(setq markup (if (equal expr "") ""
(zencoding-transform (car (zencoding-expr expr)))))
(setq markup-filled (replace-regexp-in-string "><" ">\n<" markup))
(with-selected-window zencoding-builder-window
(delete-region zencoding-builder-start-point zencoding-builder-end-point)
(insert markup-filled)
(indent-region zencoding-builder-start-point (point))
(setq zencoding-builder-end-point (point)))))
(error (zencoding-builder-cleanup))))
(defun zencoding-builder-setup ()
(setq zencoding-builder-start-point (point)
zencoding-builder-end-point (point)
zencoding-builder-buffer (current-buffer)
zencoding-builder-window (selected-window))
(add-hook 'post-command-hook 'zencoding-expand-from-minibuffer))
(defun zencoding-builder-cleanup ()
(remove-hook 'post-command-hook 'zencoding-expand-from-minibuffer)
(setq zencoding-builder-start-point nil
zencoding-builder-end-point nil
zencoding-builder-window nil))
(defun zencoding-builder ()
(interactive)
(zencoding-builder-setup)
(condition-case v
(read-string "zen: ")
(quit (zencoding-builder-cleanup)))
(zencoding-builder-cleanup))
(provide 'zencoding-builder)