Skip to content

Commit 07fbbc6

Browse files
committed
fix(UX): Be smart about fill region
1 parent a8a8026 commit 07fbbc6

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

codegpt.el

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,17 @@
8686
(insert ,instruction "\n\n")
8787
,@body)))
8888

89+
(defun codegpt--fill-region (start end)
90+
"Like function `fill-region' (START to END), improve readability."
91+
(save-restriction
92+
(narrow-to-region start end)
93+
(goto-char (point-min))
94+
(while (not (eobp))
95+
(end-of-line)
96+
(when (< fill-column (current-column))
97+
(fill-region (line-beginning-position) (line-end-position)))
98+
(forward-line 1))))
99+
89100
(defun codegpt--internal (instruction start end)
90101
"Do INSTRUCTION with partial code.
91102
@@ -104,7 +115,7 @@ boundaries of that region in buffer."
104115
(result (openai--get-choice choices))
105116
(original-point (point)))
106117
(insert (string-trim result) "\n")
107-
(fill-region original-point (point))))
118+
(codegpt--fill-region original-point (point))))
108119
(unless codegpt-focus-p
109120
(select-window original-window)))
110121
:model codegpt-model

0 commit comments

Comments
 (0)