<commit_before>;;; ldg-context.el --- Helper code for use with the "ledger" command-line tool

;; Copyright (C) 2003-2013 <NAME> (<EMAIL> AT gnu DOT org)

;; This file is not part of GNU Emacs.

;; This is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free
;; Software Foundation; either version 2, or (at your option) any later
;; version.
;;
;; This is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;; for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.


;;; Commentary:
;;  Provide facilities for reflection in ledger buffers

;;; Code:

(eval-when-compile
  (require 'cl))

;; *-string constants are assembled in the single-line-config macro to
;; form the regex and list of elements
(defconst indent-string "\\(^[ \t]+\\)")
(defconst status-string "\\([*! ]?\\)")
(defconst account-string "[\\[(]?\\(.*?\\)[])]?[ \t]\\{2\\}")
(defconst amount-string "[ \t]?\\(-?[0-9]+\\.[0-9]*\\)")
(defconst comment-string "[ \t]*;[ \t]*\\(.*?\\)")
(defconst nil-string "[ \t]+")
(defconst commodity-string "\\(.+?\\)")
(defconst date-string "^\\(\\([0-9]\\{4\\}[/-]\\)?[01]?[0-9][/-][0123]?[0-9]\\)")
(defconst code-string "\\((\\(.*\\))\\)?")
(defconst payee-string "\\(.*\\)")

(defmacro line-regex (&rest elements)
  (let (regex-string)
    (concat (dolist (e elements regex-string)
	      (setq regex-string 
		    (concat regex-string 
			    (eval 
			     (intern 
			      (concat (symbol-name e) "-string")))))) "[ \t]*$")))

(defmacro single-line-config2 (&rest elements)
"Take list of ELEMENTS and return regex and element list for use in context-at-point"
  (let (regex-string)
    `'(,(concat (dolist (e elements regex-string)
	   (setq regex-string 
		 (concat regex-string 
			 (eval 
			  (intern 
			   (concat (symbol-name e) "-string")))))) "[ \t]*$")
       ,elements)))

(defmacro single-line-config (&rest elements)
  "Take list of ELEMENTS and return regex and element list for use in context-at-point"
  `'(,(eval `(line-regex ,@elements))		  
     ,elements))

(defconst ledger-line-config
  (list (list 'xact (list (single-line-config date nil status nil nil code payee comment)
			  (single-line-config date nil status nil nil code payee)))
	(list 'acct-transaction (list (single-line-config indent comment)
				      (single-line-config indent status account commodity amount nil comment)
				      (single-line-config indent status account commodity amount)
				      (single-line-config indent status account amount nil commodity comment)
				      (single-line-config indent status account amount nil commodity)
				      (single-line-config indent status account amount)
				      (single-line-config indent status account comment)
				      (single-line-config indent status account)))))

(defun ledger-extract-context-info (line-type pos)
  "Get context info for current line with LINE-TYPE.

Assumes point is at beginning of line, and the POS argument specifies
where the \"users\" point was."
  (let ((linfo (assoc line-type ledger-line-config))
        found field fields)
    (dolist (re-info (nth 1 linfo))
      (let ((re (nth 0 re-info))<commit_msg>More regex fine tuning<commit_after>;;; ldg-context.el --- Helper code for use with the "ledger" command-line tool

;; Copyright (C) 2003-2013 <NAME> (<EMAIL>w AT gnu DOT org)

;; This file is not part of GNU Emacs.

;; This is free software; you can redistribute it and/or modify it under
;; the terms of the GNU General Public License as published by the Free
;; Software Foundation; either version 2, or (at your option) any later
;; version.
;;
;; This is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
;; FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
;; for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING.  If not, write to the
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
;; MA 02111-1307, USA.


;;; Commentary:
;;  Provide facilities for reflection in ledger buffers

;;; Code:

(eval-when-compile
  (require 'cl))

;; *-string constants are assembled in the single-line-config macro to
;; form the regex and list of elements
(defconst indent-string "\\(^[ \t]+\\)")
(defconst status-string "\\([*! ]?\\)")
(defconst account-string "[\\[(]?\\(.*?\\)[])]?")
(defconst amount-string "[ \t]?\\(-?[0-9]+\\.[0-9]*\\)")
(defconst comment-string "[ \t]*;[ \t]*\\(.*?\\)")
(defconst nil-string "\\([ \t]+\\)")
(defconst commodity-string "\\(.+?\\)")
(defconst date-string "^\\(\\([0-9]\\{4\\}[/-]\\)?[01]?[0-9][/-][0123]?[0-9]\\)")
(defconst code-string "\\((\\(.*\\))\\)?")
(defconst payee-string "\\(.*\\)")

(defmacro line-regex (&rest elements)
  (let (regex-string)
    (concat (dolist (e elements regex-string)
	      (setq regex-string 
		    (concat regex-string 
			    (eval 
			     (intern 
			      (concat (symbol-name e) "-string")))))) "[ \t]*$")))

(defmacro single-line-config2 (&rest elements)
"Take list of ELEMENTS and return regex and element list for use in context-at-point"
  (let (regex-string)
    `'(,(concat (dolist (e elements regex-string)
	   (setq regex-string 
		 (concat regex-string 
			 (eval 
			  (intern 
			   (concat (symbol-name e) "-string")))))) "[ \t]*$")
       ,elements)))

(defmacro single-line-config (&rest elements)
  "Take list of ELEMENTS and return regex and element list for use in context-at-point"
  `'(,(eval `(line-regex ,@elements))		  
     ,elements))

(defconst ledger-line-config
  (list (list 'xact (list (single-line-config date nil status nil nil code payee comment)
			  (single-line-config date nil status nil nil code payee)))
	(list 'acct-transaction (list (single-line-config indent comment)
				      (single-line-config indent status account nil commodity amount nil comment)
				      (single-line-config indent status account nil commodity amount)
				      (single-line-config indent status account nil amount nil commodity comment)
				      (single-line-config indent status account nil amount nil commodity)
				      (single-line-config indent status account nil amount)
				      (single-line-config indent status account nil comment)
				      (single-line-config indent status account)))))

(defun ledger-extract-context-info (line-type pos)
  "Get context info for current line with LINE-TYPE.

Assumes point is at beginning of line, and the POS argument specifies
where the \"users\" point was."
  (let ((linfo (assoc line-type ledger-line-config))
        found field fields)
    (dolist (re-info (nth 1 linfo))
      (let ((re (nth 0 re-info))
{'fraction_non_alphanumeric': 0.15405252753459475, 'fraction_numerical': 0.012284665348771533, 'mean_word_length': 3.3083941605839415, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2054051', 'n_tokens_mistral': 2366, 'n_tokens_neox': 2151, 'n_words': 797}