<commit_before>;;;; minibuffer.lisp --- major mode for input

(in-package :next)

(defvar minibuffer-mode-map (make-hash-table :test 'equalp))

(defclass minibuffer-mode (mode)
  ((completion-function :accessor completion-function)
   (callback-function :accessor callback-function)
   (callback-buffer :accessor callback-buffer)
   (setup-function :accessor setup-function)
   (cleanup-function :accessor cleanup-function)))

(defmethod input ((self minibuffer-mode) callback &key completion setup cleanup)
  (with-slots (callback-function completion-function callback-buffer setup-function cleanup-function) self
    (setf callback-function callback)
    (setf completion-function completion)
    (setf setup-function setup)
    (setf cleanup-function cleanup)
    (setf callback-buffer *active-buffer*)
    (interface:minibuffer-set-completion-function completion)
    (funcall setup-function))
  (set-active-buffer *minibuffer*)
  (interface:minibuffer-show))

(defmethod return-input ((self minibuffer-mode))
  (set-active-buffer (callback-buffer self))
  (with-slots (completion-function callback-function cleanup-function) self
      (if completion-function
      (funcall callback-function
	       (nth 0 (funcall completion-function
			       (interface:minibuffer-get-input))))
      (funcall callback-function
	       (interface:minibuffer-get-input)))
      (when cleanup-function
	(funcall cleanup-function)))
  (interface:minibuffer-hide))

(defmethod cancel-input ((self minibuffer-mode))
  (set-active-buffer (callback-buffer self))
  (with-slots (cleanup-function) self
    (when cleanup-function
      (funcall cleanup-function)))
  (interface:minibuffer-hide))

(defun minibuffer-mode ()
  "Base mode for input"
  (make-instance 'minibuffer-mode
		 :name "minibuffer"
		 :keymap minibuffer-mode-map
		 :view (interface:make-minibuffer)))<commit_msg>minibuffer calls default setup function which erases previous input<commit_after>;;;; minibuffer.lisp --- major mode for input

(in-package :next)

(defvar minibuffer-mode-map (make-hash-table :test 'equalp))

(defclass minibuffer-mode (mode)
  ((completion-function :accessor completion-function)
   (callback-function :accessor callback-function)
   (callback-buffer :accessor callback-buffer)
   (setup-function :accessor setup-function)
   (cleanup-function :accessor cleanup-function)))

(defmethod input ((self minibuffer-mode) callback &key completion (setup #'erase-input) cleanup)
  (with-slots (callback-function completion-function callback-buffer setup-function cleanup-function) self
    (setf callback-function callback)
    (setf completion-function completion)
    (setf setup-function setup)
    (setf cleanup-function cleanup)
    (setf callback-buffer *active-buffer*)
    (interface:minibuffer-set-completion-function completion)
    (funcall setup-function))
  (set-active-buffer *minibuffer*)
  (interface:minibuffer-show))

(defmethod return-input ((self minibuffer-mode))
  (set-active-buffer (callback-buffer self))
  (with-slots (completion-function callback-function cleanup-function) self
      (if completion-function
      (funcall callback-function
	       (nth 0 (funcall completion-function
			       (interface:minibuffer-get-input))))
      (funcall callback-function
	       (interface:minibuffer-get-input)))
      (when cleanup-function
	(funcall cleanup-function)))
  (interface:minibuffer-hide))

(defmethod cancel-input ((self minibuffer-mode))
  (set-active-buffer (callback-buffer self))
  (with-slots (cleanup-function) self
    (when cleanup-function
      (funcall cleanup-function)))
  (interface:minibuffer-hide))

(defun erase-input ()
  (interface:minibuffer-set-input ""))

(defun minibuffer-mode ()
  "Base mode for input"
  (make-instance 'minibuffer-mode
		 :name "minibuffer"
		 :keymap minibuffer-mode-map
		 :view (interface:make-minibuffer)))
{'fraction_non_alphanumeric': 0.11970010341261635, 'fraction_numerical': 0.000517063081695967, 'mean_word_length': 4.433988764044944, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '92939', 'n_tokens_mistral': 1173, 'n_tokens_neox': 1140, 'n_words': 265}