<commit_before>;; -*- Mode: LISP; Package: LEM -*-

(in-package :lem)

(export '(region-beginning
          region-end
          region-string
          region-count
          delete-region
          apply-region-lines))

(defun region-beginning ()
  (let ((point1 (current-point))
        (point2 (mark-point)))
    (if (point< point1 point2)
        point1
        point2)))

(defun region-end ()
  (let ((point1 (current-point))
        (point2 (mark-point)))
    (if (point< point1 point2)
        point2
        point1)))

(defun region-lines (begin end)
  (when (point< end begin)
    (rotatef begin end))
  (with-points (((linum1 col1) begin)
                ((linum2 col2) end))
    (let ((lines
           (buffer-take-lines (current-buffer)
                              linum1
                              (1+ (- linum2 linum1)))))
      (if (= linum1 linum2)
          (list (subseq (car lines) col1 col2))
          (let ((acc
                 (list (subseq (car lines) col1))))
            (do ((rest (cdr lines) (cdr rest)))
                ((null (cdr rest))
                 (when rest
                   (push (subseq (car rest) 0 col2) acc)))
              (push (car rest) acc))
            (nreverse acc))))))

(defun region-string (begin end)
  (join (string #\newline) (region-lines begin end)))

(defun region-count (begin end)
  (let ((count 0))
    (do ((lines (region-lines begin end) (cdr lines)))
        ((null (cdr lines))
         (incf count (length (car lines))))
      (incf count (1+ (length (car lines)))))
    count))

(defun %delete-region (begin end killp)
  (point-set begin)
  (prog1 (delete-char (region-count begin end) killp)
    (buffer-mark-cancel (current-buffer))))

(defun delete-region (begin end)
  (%delete-region begin end nil))

(defun apply-region-lines (begin end fn)
  (point-set begin)
  (do () ((point<= end (current-point)))
    (let ((linum (current-linum)))
      (beginning-of-line)
      (funcall fn)
      (when (= linum (current-linum))
        (unless (forward-line 1)
          (return))))))<commit_msg>delete-regionを修正<commit_after>;; -*- Mode: LISP; Package: LEM -*-

(in-package :lem)

(export '(region-beginning
          region-end
          region-string
          region-count
          delete-region
          apply-region-lines))

(defun region-beginning ()
  (let ((point1 (current-point))
        (point2 (mark-point)))
    (if (point< point1 point2)
        point1
        point2)))

(defun region-end ()
  (let ((point1 (current-point))
        (point2 (mark-point)))
    (if (point< point1 point2)
        point2
        point1)))

(defun region-lines (begin end)
  (when (point< end begin)
    (rotatef begin end))
  (with-points (((linum1 col1) begin)
                ((linum2 col2) end))
    (let ((lines
           (buffer-take-lines (current-buffer)
                              linum1
                              (1+ (- linum2 linum1)))))
      (if (= linum1 linum2)
          (list (subseq (car lines) col1 col2))
          (let ((acc
                 (list (subseq (car lines) col1))))
            (do ((rest (cdr lines) (cdr rest)))
                ((null (cdr rest))
                 (when rest
                   (push (subseq (car rest) 0 col2) acc)))
              (push (car rest) acc))
            (nreverse acc))))))

(defun region-string (begin end)
  (join (string #\newline) (region-lines begin end)))

(defun region-count (begin end)
  (let ((count 0))
    (do ((lines (region-lines begin end) (cdr lines)))
        ((null (cdr lines))
         (incf count (length (car lines))))
      (incf count (1+ (length (car lines)))))
    count))

(defun delete-region (begin end)
  (when (point< end begin)
    (rotatef begin end))
  (point-set begin)
  (prog1 (delete-char (region-count begin end) nil)
    (buffer-mark-cancel (current-buffer))))

(defun apply-region-lines (begin end fn)
  (point-set begin)
  (do () ((point<= end (current-point)))
    (let ((linum (current-linum)))
      (beginning-of-line)
      (funcall fn)
      (when (= linum (current-linum))
        (unless (forward-line 1)
          (return))))))
{'fraction_non_alphanumeric': 0.15324927255092144, 'fraction_numerical': 0.015033947623666343, 'mean_word_length': 2.0, 'pattern_counts': {'":': 0, '<': 12, '<?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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4636668', 'n_tokens_mistral': 1346, 'n_tokens_neox': 1324, 'n_words': 381}