forked from 11111000000/pen.el
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pen-common.el
46 lines (35 loc) · 1.56 KB
/
pen-common.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
(defset pen-common-prompt-functions '(pf-quick-fix-code/1))
(defun pen-run-common-prompt-function ()
(interactive)
(let ((pf (fz pen-common-prompt-functions nil nil "Common prompt function: ")))
(call-interactively 'pf)))
(defun pen-complete-inner (lines-context)
"Complete inner text by providing lines-later-context lines of surrounding context."
(interactive (list 2))
(if (not (listp current-prefix-arg))
(setq lines-context (prefix-numeric-value current-prefix-arg)))
(if (pen-selected)
(call-interactively 'kill-region))
(let ((prefix (pen-preceding-lines lines-context))
(suffix (pen-proceeding-lines lines-context)))
(insert
(if (pen-code-p)
(pf-complete-inner-code/2 prefix suffix)
(pf-complete-inner-prose/2 prefix suffix)))))
(defun pen-complete-prefix (lines-later-context)
"Complete preceding text by providing lines-later-context lines of latter context."
(interactive (list 2))
(if (not (listp current-prefix-arg))
(setq lines-later-context (prefix-numeric-value current-prefix-arg)))
(if (pen-selected)
(call-interactively 'kill-region))
;; Some prior context i.e. is a good idea to avoid getting 'once upon a time'
(let ((prefix (pen-preceding-lines 1))
(suffix (pen-proceeding-lines lines-later-context)))
(insert
(if (pen-code-p)
(pf-complete-inner-code/2 prefix suffix)
(pf-complete-inner-prose/2 prefix suffix)))))
(define-key pen-map (kbd "M-6") 'pen-complete-inner)
(define-key pen-map (kbd "M-l M-{") 'pen-complete-prefix)
(provide 'pen-common)