<commit_before>;;; (C) <EMAIL>
;;; gerbil editing mode
(require 'scheme)
(require 'cmuscheme)

(defun gerbil-mode ()
  (interactive)
  (kill-all-local-variables)
  (gerbil-mode-init)
  (scheme-mode-variables)
  (run-hooks 'scheme-mode-hook)
  (gerbil-init)
  (run-hooks 'gerbil-mode-hook))

(defun gerbil-mode-init ()
  (use-local-map scheme-mode-map)
  (setq major-mode 'gerbil-mode)
  (setq mode-name "Gerbil"))

(defgroup gerbil nil
  "Editing Gerbil code"
  :group 'scheme)

(defcustom gerbil-mode-hook nil
  "hook run when entering `gerbil-mode'.
The hook is run after scheme-mode-hook."
  :type 'hook
  :group 'gerbil)

(defun gerbil-import-file (fname)
  (comint-check-source fname)
  (comint-send-string
   (scheme-proc)
   (concat "(import \"" fname "\")\n")))

(defun gerbil-reload-file (fname)
  (comint-check-source fname)
  (comint-send-string
   (scheme-proc)
   (concat "(reload \"" fname "\")\n")))

(defun gerbil-import-current-buffer ()
  (interactive)
  (gerbil-import-file buffer-file-name))

(defun gerbil-reload-current-buffer ()
  (interactive)
  (gerbil-reload-file buffer-file-name))

(defun gerbil-compile-current-buffer ()
  (interactive)
  (let ((fname buffer-file-name)
        (buf (get-buffer-create "*gerbil-compile*")))
    (with-current-buffer buf
      (goto-char (point-max))
      (insert  "> gxc " fname "\n"))
    (let ((proc (start-process "gxc" buf "gxc" fname)))
      (set-process-sentinel proc 'gerbil-compile-sentinel)
      (display-buffer buf))))

(defvar gerbil-error-locat-rx
  "\\(\\\"\\(\\\\\\\\\\|\\\\\"\\|[^\\\"\n]\\)+\\\"\\)@\\([0-9]+\\)\\.\\([0-9]+\\)[^0-9]")

(defun gerbil-compile-sentinel (proc evt)
  (let ((buf (process-buffer proc)))
    (when buf
      (cond
       ((equal evt "finished\n")
        (kill-buffer buf))
       ((or (string-prefix-p "exited" evt)
            (string-prefix-p "failed" evt))
        (with-current-buffer buf
          (goto-char (point-max))
          (when (re-search-backward gerbil-error-locat-rx nil t)
            (let ((loc (gerbil-extract-locat (buffer-substring (point) (point-max)))))
              (with-current-buffer (car loc)
                (goto-line (cadr loc))
                (forward-char (- (caddr loc) 1))
                (mark-sexp))))))
       (t
        (with-current-buffer buf
          (goto-char (point-max))
          (insert "\nProcess " evt)))))))

(defun gerbil-extract-locat (str)
  (and (string-match gerbil-error-locat-rx str)
       (let* ((name (substring str
                               (match-beginning 1)
                               (match-end 1)))
              (line (substring str
                               (match-beginning 3)
                               (match-end 3)))
              (col (substring str
                              (match-beginning 4)
                              (match-end 4))))
         (list (read name) (read line) (read col)))))

(defun gerbil-put (syms prop v)
  (dolist (x syms)
    (put x prop v)))

(defun gerbil-put-indent (syms v)
  (gerbil-put syms 'scheme-indent-function v))<commit_msg>gerbil.el: more precise error location, ignoring history<commit_after>;;; (C) <EMAIL>
;;; gerbil editing mode
(require 'scheme)
(require 'cmuscheme)

(defun gerbil-mode ()
  (interactive)
  (kill-all-local-variables)
  (gerbil-mode-init)
  (scheme-mode-variables)
  (run-hooks 'scheme-mode-hook)
  (gerbil-init)
  (run-hooks 'gerbil-mode-hook))

(defun gerbil-mode-init ()
  (use-local-map scheme-mode-map)
  (setq major-mode 'gerbil-mode)
  (setq mode-name "Gerbil"))

(defgroup gerbil nil
  "Editing Gerbil code"
  :group 'scheme)

(defcustom gerbil-mode-hook nil
  "hook run when entering `gerbil-mode'.
The hook is run after scheme-mode-hook."
  :type 'hook
  :group 'gerbil)

(defun gerbil-import-file (fname)
  (comint-check-source fname)
  (comint-send-string
   (scheme-proc)
   (concat "(import \"" fname "\")\n")))

(defun gerbil-reload-file (fname)
  (comint-check-source fname)
  (comint-send-string
   (scheme-proc)
   (concat "(reload \"" fname "\")\n")))

(defun gerbil-import-current-buffer ()
  (interactive)
  (gerbil-import-file buffer-file-name))

(defun gerbil-reload-current-buffer ()
  (interactive)
  (gerbil-reload-file buffer-file-name))

(defun gerbil-compile-current-buffer ()
  (interactive)
  (let ((fname buffer-file-name)
        (buf (get-buffer-create "*gerbil-compile*")))
    (with-current-buffer buf
      (goto-char (point-max))
      (insert  "> gxc " fname "\n"))
    (let ((proc (start-process "gxc" buf "gxc" fname)))
      (set-process-sentinel proc 'gerbil-compile-sentinel)
      (display-buffer buf))))

(defvar gerbil-compile-mark-rx
  "^> gxc")
(defvar gerbil-error-locat-rx
  "\\(\\\"\\(\\\\\\\\\\|\\\\\"\\|[^\\\"\n]\\)+\\\"\\)@\\([0-9]+\\)\\.\\([0-9]+\\)[^0-9]")

(defun gerbil-compile-sentinel (proc evt)
  (let ((buf (process-buffer proc)))
    (when buf
      (cond
       ((equal evt "finished\n")
        (kill-buffer buf))
       ((or (string-prefix-p "exited" evt)
            (string-prefix-p "failed" evt))
        (with-current-buffer buf
          (goto-char (point-max))
          (when (re-search-backward gerbil-compile-mark-rx nil t)
            (let (limit (point))
              (goto-char (point-max))
              (when (re-search-backward gerbil-error-locat-rx limit t)
                (let ((loc (gerbil-extract-locat (buffer-substring (point) (point-max)))))
                  (with-current-buffer (car loc)
                    (goto-line (cadr loc))
                    (forward-char (- (caddr loc) 1))
                    (mark-sexp))))))))
       (t
        (with-current-buffer buf
          (goto-char (point-max))
          (insert "\nProcess " evt)))))))

(defun gerbil-extract-locat (str)
  (and (string-match gerbil-error-locat-rx str)
       (let* ((name (substring str
                               (match-beginning 1)
                               (match-end 1)))
              (line (substring str
                               (match-beginning 3)
                               (match-end 3)))
              (col (substring str
                              (match-beginning 4)
                              (match-end 4))))
         (list (read name) (read line) (read col)))))

(defun gerbil-put (syms prop v)
  (dolist (x syms)
    (put x prop v)))

(defun gerbil-put-indent (syms v)
  (gerbil-put syms 'scheme-indent-function v))
{'fraction_non_alphanumeric': 0.17498045347928068, 'fraction_numerical': 0.004065676309616888, 'mean_word_length': 2.138370951913641, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 8, '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': '1400567', 'n_tokens_mistral': 2242, 'n_tokens_neox': 2219, 'n_words': 486}