Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 16 additions & 16 deletions copilot-balancer.el
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
(puthash ?\( ?\) h)
(puthash ?\[ ?\] h)
(puthash ?\{ ?\} h)

(puthash ?\) ?\( h)
(puthash ?\} ?\{ h)
(puthash ?\] ?\[ h)

(puthash ?\N{QUOTATION MARK} ?\N{QUOTATION MARK} h)

h)
"Hash table of lisp pairs to balance.")

Expand Down Expand Up @@ -65,12 +65,12 @@
(number-to-string end)
"\n")
(insert "deleted text:<STX>" deleted-text "<EOT>\n")


(insert "completion:<STX>" completion "<EOT>\n")
(insert "trimmed-completion:<STX>" trimmed-completion "<EOT>\n")
(insert "\n")

(insert "prefix-pairs:<STX>" (prin1-to-string prefix-pairs) "<EOT>\n")
(insert "completion-pairs:<STX>" (prin1-to-string completion-pairs) "<EOT>\n")
(insert "meta-prefix-pairs:<STX>" (prin1-to-string meta-prefix-pairs) "<EOT>\n")
Expand All @@ -79,14 +79,14 @@

(insert "in-string:" (prin1-to-string in-string) "\n")
(insert "end-is-missing-double-quote:" (prin1-to-string end-is-missing-double-quote) "\n")

(insert "flipped-suffix-pairs:<STX>" (prin1-to-string flipped-suffix-pairs) "<EOT>\n")

(insert "completion-suffix-str:<STX>"
(prin1-to-string completion-suffix-str) "<EOT>\n")
(insert "new-completion:<STX>" new-completion "<EOT>\n")
(insert "\n")

(insert "prefix:\n<STX>" (substring prefix 0 (min 100 (length prefix))) "\n<EOT>\n")
(insert "suffix:<STX>" suffix
"\n<EOT>\n")
Expand Down Expand Up @@ -179,7 +179,7 @@ Special care has to be taken to ignore pairs in the middle of strings."
(save-excursion
(save-restriction
(widen)

(beginning-of-line)
(while (and (< 1 (point))
(not (looking-at-p copilot-balancer-top-level-form-start-regexp)))
Expand All @@ -191,7 +191,7 @@ Special care has to be taken to ignore pairs in the middle of strings."
(save-excursion
(save-restriction
(widen)

(let* ((last-line-number (line-number-at-pos (point-max)))
(on-last-line? (lambda ()
(= (line-number-at-pos (point)) last-line-number))))
Expand All @@ -203,7 +203,7 @@ Special care has to be taken to ignore pairs in the middle of strings."
(not (looking-at-p copilot-balancer-top-level-form-start-regexp)))
(forward-line 1)
(beginning-of-line))

;; then find the end of the top level form by going backwards
(unless (funcall on-last-line?)
(forward-line -1)
Expand All @@ -217,7 +217,7 @@ Special care has to be taken to ignore pairs in the middle of strings."
(end-of-line)
(unless (bolp) (backward-char))))
(end-of-line)

(buffer-substring-no-properties x (point))))))

(defun copilot-balancer-see-string-end-p (p point-upper-bound)
Expand Down Expand Up @@ -292,7 +292,7 @@ Special care has to be taken to ignore pairs in the middle of strings."
(copilot-balancer-remove-last meta-prefix-pairs)
nil)
(list trimmed-completion meta-prefix-pairs in-string)))

(`(,suffix-pairs . _)
(-> (copilot-balancer-extract-pairs suffix)
(copilot-balancer-collapse-matching-pairs in-string)))
Expand All @@ -305,7 +305,7 @@ Special care has to be taken to ignore pairs in the middle of strings."
(rem-flipped-completion-suffix (car xy))
(completion-suffix (mapcar #'copilot-balancer-get-other-pair
rem-flipped-completion-suffix))

(completion-suffix-str (apply #'string (nreverse completion-suffix)))
(new-completion (concat trimmed-completion
completion-suffix-str))
Expand All @@ -317,7 +317,7 @@ Special care has to be taken to ignore pairs in the middle of strings."
meta-prefix-pairs flipped-suffix-pairs
rem-flipped-completion-suffix new-completion)))
(copilot-balancer--debug debug-vars)

(list start end new-completion)))

(defun copilot-balancer-fix-completion (start end completion)
Expand Down