<commit_before>(defpackage :lem-vi-mode.visual
  (:use :cl
        :lem
        :lem-vi-mode.core)
  (:export :vi-visual-char
           :vi-visual-line
           :vi-visual-block
           :visual-p
           :visual-block-p
           :apply-visual-range))
(in-package :lem-vi-mode.visual)

(defvar *set-visual-function* nil)
(defvar *start-point* nil)
(defvar *visual-overlays* '())

(defvar *visual-keymap* (make-keymap :name '*visual-keymap* :parent *command-keymap*))

(define-key *visual-keymap* "escape" 'vi-visual-end)

(define-vi-state visual (:keymap *visual-keymap*
                         :post-command-hook 'post-command-hook)
  (:disable ()
   (clear-visual-overlays))
  (:enable (function)
   (setf *set-visual-function* function)
   (setf *start-point* (copy-point (current-point) :temporary))))

(defun disable ()
  (clear-visual-overlays))

(defun clear-visual-overlays ()
  (mapc 'delete-overlay *visual-overlays*)
  (setf *visual-overlays* '()))

(defun post-command-hook ()
  (clear-visual-overlays)
  (if (not (eq (current-buffer) (point-buffer *start-point*)))
      (vi-visual-end)
      (funcall *set-visual-function*)))

(defun visual-char ()
  (push (make-overlay *start-point* (current-point) 'region)
        *visual-overlays*))

(defun visual-line ()
  (with-point ((start *start-point*)
               (end (current-point)))
    (when (point< end start) (rotatef start end))
    (line-start start)
    (line-end end)
    (push (make-overlay start end 'region)
          *visual-overlays*)))

(defun visual-block ()
  (with-point ((start *start-point*)
               (end (current-point)))
    (when (point< end start) (rotatef start end))
    (let ((start-column (point-column start))
          (end-column (point-column end)))
      (unless (< start-column end-column)
        (rotatef start-column end-column))
      (apply-region-lines start end
                          (lambda (p)
                            (with-point ((s p) (e p))
                              (move-to-column s start-column)
                              (move-to-column e end-column)
                              (push (make-overlay s e 'region) *visual-overlays*)))))))

(define-command vi-visual-end () ()
  (clear-visual-overlays)
  (change-state 'command))

(define-command vi-visual-char () ()
  (change-state 'visual 'visual-char)
  (message "-- VISUAL --"))

(define-command vi-visual-line () ()<commit_msg>fix range<commit_after>(defpackage :lem-vi-mode.visual
  (:use :cl
        :lem
        :lem-vi-mode.core)
  (:export :vi-visual-char
           :vi-visual-line
           :vi-visual-block
           :visual-p
           :visual-block-p
           :apply-visual-range))
(in-package :lem-vi-mode.visual)

(defvar *set-visual-function* nil)
(defvar *start-point* nil)
(defvar *visual-overlays* '())

(defvar *visual-keymap* (make-keymap :name '*visual-keymap* :parent *command-keymap*))

(define-key *visual-keymap* "escape" 'vi-visual-end)

(define-vi-state visual (:keymap *visual-keymap*
                         :post-command-hook 'post-command-hook)
  (:disable ()
   (clear-visual-overlays))
  (:enable (function)
   (setf *set-visual-function* function)
   (setf *start-point* (copy-point (current-point) :temporary))))

(defun disable ()
  (clear-visual-overlays))

(defun clear-visual-overlays ()
  (mapc 'delete-overlay *visual-overlays*)
  (setf *visual-overlays* '()))

(defun post-command-hook ()
  (clear-visual-overlays)
  (if (not (eq (current-buffer) (point-buffer *start-point*)))
      (vi-visual-end)
      (funcall *set-visual-function*)))

(defun visual-char ()
  (with-point ((p (current-point)))
    (character-offset p 1)
    (push (make-overlay *start-point* p 'region)
          *visual-overlays*)))

(defun visual-line ()
  (with-point ((start *start-point*)
               (end (current-point)))
    (when (point< end start) (rotatef start end))
    (line-start start)
    (line-end end)
    (push (make-overlay start end 'region)
          *visual-overlays*)))

(defun visual-block ()
  (with-point ((start *start-point*)
               (end (current-point)))
    (character-offset end 1)
    (when (point< end start) (rotatef start end))
    (let ((start-column (point-column start))
          (end-column (point-column end)))
      (unless (< start-column end-column)
        (rotatef start-column end-column))
      (apply-region-lines start end
                          (lambda (p)
                            (with-point ((s p) (e p))
                              (move-to-column s start-column)
                              (move-to-column e end-column)
                              (push (make-overlay s e 'region) *visual-overlays*)))))))

(define-command vi-visual-end () ()
  (clear-visual-overlays)
  (change-state 'command))

(define-command vi-visual-char () ()
  (change-state 'visual 'visual-char)
  (message "-- VISUAL --"))

(define-command vi-visual-line () ()
{'fraction_non_alphanumeric': 0.16616069621534102, 'fraction_numerical': 0.0004047763610605141, 'mean_word_length': 2.3988995873452543, 'pattern_counts': {'":': 0, '<': 9, '<?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': '202379', 'n_tokens_mistral': 1739, 'n_tokens_neox': 1652, 'n_words': 348}