Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ GTAGS
GRTAGS
GPATH
.ai.code.notes.org
*.elc
24 changes: 19 additions & 5 deletions ai-code-input.el
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
(require 'imenu)

(declare-function helm-comp-read "helm-mode" (prompt collection &rest args))
(declare-function evil-visual-state-p "evil-core" ())
(declare-function evil-emacs-state "evil-core" ())

;;;###autoload
(defun ai-code-plain-read-string (prompt &optional initial-input candidate-list)
Expand All @@ -26,11 +28,23 @@ This function combines candidate-list with history for better completion."
(delete-dups (append candidate-list
(when (boundp 'ai-code-read-string-history)
ai-code-read-string-history)))))
;; Use completing-read with the combined candidates
(completing-read prompt
completion-candidates
nil nil initial-input
'ai-code-read-string-history)))
;; Use minibuffer-setup-hook to disable highlighting in minibuffer
;; to prevent initial-input from being highlighted
(minibuffer-with-setup-hook
(lambda ()
;; Disable transient-mark-mode locally to prevent highlighting
(setq-local transient-mark-mode nil)
;; If Evil mode is active and in visual state, switch to emacs state
(when (and (fboundp 'evil-visual-state-p)
(evil-visual-state-p))
(evil-emacs-state))
;; Move cursor to end of initial input
(goto-char (point-max)))
;; Use completing-read with the combined candidates
(completing-read prompt
completion-candidates
nil nil initial-input
'ai-code-read-string-history))))

;;;###autoload
(defalias 'ai-code-read-string #'ai-code-plain-read-string)
Expand Down