<commit_before>;;; live-py-mode.el --- Live Coding in Python

;; Copyright (C) 2015 <NAME>

;; Author: <NAME> <<EMAIL>>
;; Keywords: live coding
;; URL: http://donkirkby.github.io/live-py-plugin/
;; Version: 2015
;; X-Original-Version: 2.8.1
;; Package-Requires: ((emacs "24.1"))

;; This program is distributed under the Eclipse Public License - v 1.0
;; For more information see https://www.eclipse.org/legal/epl-v10.html

;;; Commentary:

;; To use it, open a Python file and run M-x live-py-mode
;; If that doesn't work, put the following in your Emacs configuration file:
;;
;;   (require 'live-py-mode)
;;
;; Requirements: Emacs 24.

;;; Code:

(defvar live-py-timer)
(defvar live-py-output-buffer)
(defvar live-py-output-window)

(defun live-py-after-change-function (start stop len)
  "Run the buffer through the code tracer and show results in the trace buffer."
  (when live-py-timer (cancel-timer live-py-timer))
  (set 'live-py-timer (run-at-time 0.5 nil 'live-py-trace)))


(defun live-py-trace ()
  "Trace the Python code using code_tracer.py."
  (let* ((tracer-path (locate-file "code_tracer.py" load-path))
         (buffer-dir (file-name-directory (buffer-file-name)))
         (command-line (concat "python " tracer-path))
         (pythonpath (concat "PYTHONPATH=" buffer-dir))
         (process-environment (cons pythonpath process-environment))
         )
    (shell-command-on-region 1
                             (+ (buffer-size) 1)
                             command-line
                             live-py-output-buffer))
  (with-current-buffer live-py-output-buffer
    (setq buffer-read-only 1))
  (live-py-synchronize-scroll)
  (set 'live-py-timer nil))


(defun live-py-synchronize-scroll ()
  "Synchronise scrolling between Python and live-py buffers."
  (let ((code-window-start (+ (count-lines 1 (window-start)) 1))
        (position (line-number-at-pos)))
    (unless (window-valid-p live-py-output-window)
      (live-py-show-output-window))
    (with-selected-window live-py-output-window
      (goto-line code-window-start)
      (recenter-top-bottom 0)
      (goto-line position))))


(defun live-py-check-to-scroll ()
  "Check `this-command' to see if a scroll is to be done."
  (cond ((memq this-command '(next-line
                              previous-line
                              scroll-up
                              scroll-up-command
                              scroll-down
                              scroll-down-command
                              beginning-of-buffer
                              end-of-buffer))
         (live-py-synchronize-scroll))))


(defun live-py-show-output-window ()
  "Show the live-py output window."
  (delete-other-windows)
  (get-buffer-create live-py-output-buffer)
  (with-current-buffer live-py-output-buffer
    (toggle-truncate-lines 1))
  (set (make-local-variable 'live-py-output-window)
       (split-window-horizontally)
       (setq show-trailing-whitespace nil))
  (set-window-buffer live-py-output-window live-py-output-buffer))


;;;###autoload
(define-minor-mode live-py-mode
  "Minor mode to do on-the-fly Python tracing.
When called interactively, toggles the minor mode.
With arg, turn mode on if and only if arg is positive."
  :group 'live-py-mode :lighter live-py-mode-line
  (unless (buffer-file-name)
    (error "Current buffer has no associated file!"))
  (cond

   ;; Turning the mode ON.
   (live-py-mode
    ;; create a unique name for the trace output buffer
    (set (make-local-variable 'live-py-output-buffer)
         (concat "*live-py-output_"
                 (file-name-nondirectory (buffer-file-name))
                 "_"
                 (make-temp-name "")<commit_msg>Had to revert #58, because it doesn't compile.<commit_after>;;; live-py-mode.el --- Live Coding in Python

;; Copyright (C) 2015 <NAME>

;; Author: <NAME> <<EMAIL>>
;; Keywords: live coding
;; URL: http://donkirkby.github.io/live-py-plugin/
;; Version: 2015
;; X-Original-Version: 2.8.1
;; Package-Requires: ((emacs "24.1"))

;; This program is distributed under the Eclipse Public License - v 1.0
;; For more information see https://www.eclipse.org/legal/epl-v10.html

;;; Commentary:

;; To use it, open a Python file and run M-x live-py-mode
;; If that doesn't work, put the following in your Emacs configuration file:
;;
;;   (require 'live-py-mode)
;;
;; Requirements: Emacs 24.

;;; Code:

(defvar live-py-timer)
(defvar live-py-output-buffer)
(defvar live-py-output-window)

(defun live-py-after-change-function (start stop len)
  "Run the buffer through the code tracer and show results in the trace buffer."
  (when live-py-timer (cancel-timer live-py-timer))
  (set 'live-py-timer (run-at-time 0.5 nil 'live-py-trace)))


(defun live-py-trace ()
  "Trace the Python code using code_tracer.py."
  (let* ((tracer-path (locate-file "code_tracer.py" load-path))
         (buffer-dir (file-name-directory (buffer-file-name)))
         (command-line (concat "python " tracer-path))
         (pythonpath (concat "PYTHONPATH=" buffer-dir))
         (process-environment (cons pythonpath process-environment))
         )
    (shell-command-on-region 1
                             (+ (buffer-size) 1)
                             command-line
                             live-py-output-buffer))
  (with-current-buffer live-py-output-buffer
    (setq buffer-read-only 1))
  (live-py-synchronize-scroll)
  (set 'live-py-timer nil))


(defun live-py-synchronize-scroll ()
  "Synchronise scrolling between Python and live-py buffers."
  (let ((code-window-start (+ (count-lines 1 (window-start)) 1))
        (position (line-number-at-pos)))
    (unless (window-valid-p live-py-output-window)
      (live-py-show-output-window))
    (with-selected-window live-py-output-window
      (goto-line code-window-start)
      (recenter-top-bottom 0)
      (goto-line position))))


(defun live-py-check-to-scroll ()
  "Check `this-command' to see if a scroll is to be done."
  (cond ((memq this-command '(next-line
                              previous-line
                              scroll-up
                              scroll-up-command
                              scroll-down
                              scroll-down-command
                              beginning-of-buffer
                              end-of-buffer))
         (live-py-synchronize-scroll))))


(defun live-py-show-output-window ()
  "Show the live-py output window."
  (delete-other-windows)
  (get-buffer-create live-py-output-buffer)
  (with-current-buffer live-py-output-buffer
    (toggle-truncate-lines 1))
  (set (make-local-variable 'live-py-output-window)
       (split-window-horizontally))
  (set-window-buffer live-py-output-window live-py-output-buffer))


;;;###autoload
(define-minor-mode live-py-mode
  "Minor mode to do on-the-fly Python tracing.
When called interactively, toggles the minor mode.
With arg, turn mode on if and only if arg is positive."
  :group 'live-py-mode :lighter live-py-mode-line
  (unless (buffer-file-name)
    (error "Current buffer has no associated file!"))
  (cond

   ;; Turning the mode ON.
   (live-py-mode
    ;; create a unique name for the trace output buffer
    (set (make-local-variable 'live-py-output-buffer)
         (concat "*live-py-output_"
                 (file-name-nondirectory (buffer-file-name))
                 "_"
                 (make-temp-name "")
{'fraction_non_alphanumeric': 0.1362530413625304, 'fraction_numerical': 0.008110300081103, 'mean_word_length': 2.3555555555555556, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4493037', 'n_tokens_mistral': 2392, 'n_tokens_neox': 2307, 'n_words': 588}