<commit_before>;;; fuel-debug-uses.el -- retrieving USING: stanzas

;; Copyright (C) 2008, 2009 <NAME>
;; See http://factorcode.org/license.txt for BSD license.

;; Author: <NAME> <<EMAIL>>
;; Keywords: languages, fuel, factor
;; Start date: Tue Dec 23, 2008 04:23

;;; Comentary:

;; Support for getting and updating factor source vocabulary lists.

;;; Code:

(require 'fuel-debug)
(require 'fuel-eval)
(require 'fuel-popup)
(require 'fuel-font-lock)
(require 'fuel-base)




;;; Customization:

(fuel-font-lock--defface fuel-font-lock-debug-uses-header
  'bold fuel-debug "headers in Uses buffers")

(fuel-font-lock--defface fuel-font-lock-debug-uses-prompt
  'italic fuel-debug "prompts in Uses buffers")



;;; Utility functions:

(defsubst fuel-debug--chomp (s)
  (replace-regexp-in-string "[\n\r\f]" "" s))

(defun fuel-debug--file-lines (file)
  (when (file-readable-p file)
    (with-current-buffer (find-file-noselect file)
      (save-excursion
        (goto-char (point-min))
        (let ((lines) (in-usings))
          (while (not (eobp))
            (when (looking-at "^USING: ") (setq in-usings t))
            (let ((line (fuel-debug--chomp
                         (substring-no-properties (thing-at-point 'line)))))
              (when in-usings (setq line (concat "! " line)))
              (push line lines))
            (when (and in-usings (looking-at ".*\\_<;\\_>")) (setq in-usings nil))
            (forward-line))
          (reverse lines))))))

(defun fuel-debug--uses-filter (restarts)
  (let ((result) (i 1) (rn 0))
    (dolist (r restarts (reverse result))
      (setq rn (1+ rn))
      (when (string-match "Use the .+ vocabulary\\|Defer" r)
        (push (list i rn r) result)
        (setq i (1+ i))))))



;;; Retrieving USINGs:

(fuel-popup--define fuel-debug--uses-buffer
  "*fuel uses*" 'fuel-debug-uses-mode)

(make-variable-buffer-local
 (defvar fuel-debug--uses-file nil))

(make-variable-buffer-local
 (defvar fuel-debug--uses-restarts nil))

(defsubst fuel-debug--uses-insert-title ()
  (insert "Inferring USING: stanza for " fuel-debug--uses-file ".\n\n"))

(defun fuel-debug--uses-prepare (file)
  (fuel--with-popup (fuel-debug--uses-buffer)
    (setq fuel-debug--uses-file file<commit_msg>FUEL: Kind of subtle bug in C-cC-eu caused by syntax table tweakings.<commit_after>;;; fuel-debug-uses.el -- retrieving USING: stanzas

;; Copyright (C) 2008, 2009 <NAME>
;; See http://factorcode.org/license.txt for BSD license.

;; Author: <NAME> <<EMAIL>>
;; Keywords: languages, fuel, factor
;; Start date: Tue Dec 23, 2008 04:23

;;; Comentary:

;; Support for getting and updating factor source vocabulary lists.

;;; Code:

(require 'fuel-debug)
(require 'fuel-eval)
(require 'fuel-popup)
(require 'fuel-font-lock)
(require 'fuel-base)




;;; Customization:

(fuel-font-lock--defface fuel-font-lock-debug-uses-header
  'bold fuel-debug "headers in Uses buffers")

(fuel-font-lock--defface fuel-font-lock-debug-uses-prompt
  'italic fuel-debug "prompts in Uses buffers")



;;; Utility functions:

(defsubst fuel-debug--chomp (s)
  (replace-regexp-in-string "[\n\r\f]" "" s))

(defun fuel-debug--file-lines (file)
  (when (file-readable-p file)
    (with-current-buffer (find-file-noselect file)
      (save-excursion
        (goto-char (point-min))
        (let ((lines) (in-usings))
          (while (not (eobp))
            (when (looking-at "^USING: ") (setq in-usings t))
            (let ((line (fuel-debug--chomp
                         (substring-no-properties (thing-at-point 'line)))))
              (when in-usings (setq line (concat "! " line)))
              (push line lines))
            (when (and in-usings (looking-at "\\(^\\|.* \\);\\( \\|\n\\)"))
              (setq in-usings nil))
            (forward-line))
          (reverse lines))))))

(defun fuel-debug--uses-filter (restarts)
  (let ((result) (i 1) (rn 0))
    (dolist (r restarts (reverse result))
      (setq rn (1+ rn))
      (when (string-match "Use the .+ vocabulary\\|Defer" r)
        (push (list i rn r) result)
        (setq i (1+ i))))))



;;; Retrieving USINGs:

(fuel-popup--define fuel-debug--uses-buffer
  "*fuel uses*" 'fuel-debug-uses-mode)

(make-variable-buffer-local
 (defvar fuel-debug--uses-file nil))

(make-variable-buffer-local
 (defvar fuel-debug--uses-restarts nil))

(defsubst fuel-debug--uses-insert-title ()
  (insert "Inferring USING: stanza for " fuel-debug--uses-file ".\n\n"))

(defun fuel-debug--uses-prepare (file)
  (fuel--with-popup (fuel-debug--uses-buffer)
    (setq fuel-debug--uses-file file
{'fraction_non_alphanumeric': 0.17658686580276742, 'fraction_numerical': 0.009663957830002196, 'mean_word_length': 2.826890756302521, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, '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': '4484664', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1587, 'n_words': 391}