-
Notifications
You must be signed in to change notification settings - Fork 10
/
parinfer-mode.el
35 lines (30 loc) · 1.41 KB
/
parinfer-mode.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
(require 'parinferlib)
(defun parinfer-mode-insert-result (result)
(if (and (plist-get result :success)
(not (and (= (char-before (point)) 10)
(= (char-after (point)) 41))))
(let ((old-buffer (current-buffer))
(old-point (point)))
(with-temp-buffer
(insert (plist-get result :text))
(copy-to-buffer old-buffer (point-min) (point-max)))
(goto-char old-point))))
(defun parinfer-mode-indent-mode ()
(parinfer-mode-insert-result (parinferlib-indent-mode (buffer-string)
(current-column)
(- (line-number-at-pos) 1)
nil)))
(defun parinfer-mode-paren-mode ()
(parinfer-mode-insert-result (parinferlib-paren-mode (buffer-string)
(current-column)
(- (line-number-at-pos) 1)
nil)))
(define-minor-mode parinfer-mode
"Uses Parinfer to Format lispy code"
:lighter " parinfer "
(if parinfer-mode
(progn
(parinfer-mode-paren-mode)
(add-hook 'post-self-insert-hook 'parinfer-mode-indent-mode nil t))
(remove-hook 'post-self-insert-hook 'parinfer-mode-indent-mode t)))
(provide 'parinfer-mode)