<commit_before>(defpackage :lem-lisp-syntax.indent
  (:use :cl :lem-base)
  (:export :*get-method-function*
           :set-indentation
           :update-system-indentation
           :indentation-update
           :calc-indent))
(in-package :lem-lisp-syntax.indent)

(defparameter *body-indent* 2)
(defparameter *max-depth* 4)

(defvar *get-method-function* nil)
(defvar *static-indent-table* (make-hash-table :test 'equal))
(defvar *dynamic-indent-table* (make-hash-table :test 'equal))

(defvar *lambda-list-indentation* t)
(defvar *lambda-list-keyword-parameter-alignment* t)
(defvar *lambda-list-keyword-alignment* t)

(defvar *loop-indent-subclauses* nil)
(defvar *simple-loop-indentation* 2)

(defun get-indentation (name)
  (or (gethash name *static-indent-table*)
      (caar (gethash name *dynamic-indent-table*))))

(defun set-indentation (name method)
  (setf (gethash name *static-indent-table*) method))

(defun update-system-indentation (name indent packages)
  (let ((list (gethash name *dynamic-indent-table*))
        ok)
    (if (null list)
        (setf (gethash name *dynamic-indent-table*)
              (list (cons indent packages)))
        (dolist (spec list)
          (cond ((equal (car spec) indent)
                 (setf (cdr spec)
                       (nunion (cdr spec) packages))
                 (setf ok t))
                (t
                 (setf (cdr spec)
                       (nset-difference (cdr spec) packages :test #'equal))))))
    (unless ok
      (setf (gethash name *dynamic-indent-table*)
            (cons (cons indent packages) list)))))

(defun indentation-update ()
  (do-all-symbols (symbol)
    (let ((key (string-downcase symbol)))
      (alexandria:when-let ((indent (swank::symbol-indentation symbol)))
        (update-system-indentation key
                                   indent
                                   (list (package-name (symbol-package symbol))))))))

(mapc (lambda (elt)
        (let ((name (car elt))
              (method (if (stringp (cdr elt))
                          (get-indentation (cdr elt))
                          (cadr elt))))
          (set-indentation name method)))
      '(("block" 1)
        ("case"        (4 &rest (&whole 2 &rest 1)))
        ("ccase" . "case")
        ("ecase" . "case")
        ("typecase" . "case")
        ("etypecase" . "case")
        ("ctypecase" . "case")
        ("catch" 1)
        ("cond"        (&rest (&whole 2 &rest 1)))
        ("defvar"      (4 2 2))
        ("defclass"    (6 4 (&whole 2 &rest 1) (&whole 2 &rest 1)))
        ("defconstant" . "defvar")
        ("defcustom"   (4 2 2 2))
        ("defparameter" . "defvar")
        ("defconst"     . "defcustom")
        ("define-condition"  . "defclass")
        ("define-modify-macro" (4 &lambda &body))
        ("defsetf"     (4 &lambda 4 &body))
        ("defun"       (4 &lambda &body))
        ("defgeneric"  (4 &lambda &body))
        ("define-setf-method" . "defun")
        ("define-setf-expander" . "defun")
        ("defmacro" . "defun")
        ("defsubst" . "defun")
        ("deftype" . "defun")
        ("defmethod" lisp-indent-defmethod)
        ("defpackage"  (4 &rest (&whole 2 &rest defpackage-body)))
        ("defstruct"   ((&whole 4 &rest (&whole 2 &rest 1))
                        &rest (&whole 2 &rest 1)))
        ("destructuring-bind"
         ((&whole 6 &rest 1) 4 &body))
        ;("do"          lisp-indent-do)
        ("do" 2)
        ("do*" . "do")
        ("dolist"      1)
        ("dotimes" . "dolist")
        ("eval-when"   1)
        ("flet"        ((&whole 4 &rest (&whole 1 &lambda &body)) &body))
        ("labels" . "flet")
        ("macrolet" . "flet")
        ("generic-flet" . "flet")
        ("generic-labels" . "flet")
        ("handler-case" (4 &rest (&whole 2 &lambda &body)))
        ("restart-case" . "handler-case")
        ;; `else-body' style
        ("if"          (nil nil &body))
        ;; single-else style (then and else equally indented)
        ("if"          (&rest nil))
        ;("lambda"      (&lambda &rest lisp-indent-function-lambda-hack))
        ("lambda" (&lambda &body))
        ("let"         ((&whole 4 &rest (&whole 1 2)) &body))
        ("let*" . "let")
        ("compiler-let" . "let") ;barf
        ("handler-bind" . "let")
        ("restart-bind" . "let")
        ("locally" 1)
        ("loop"         lisp-indent-loop)
        ;("loop" (&rest &body))
        (":method" lisp-indent-defmethod) ; in `defgeneric'
        ("multiple-value-bind" ((&whole 6 &rest 1) 4 &body))
        ("multiple-value-call" (4 &body))
        ("multiple-value-prog1" 1)
        ("multiple-value-setq" (4 2))
        ("multiple-value-setf" . "multiple-value-setq")
        ("pprint-logical-block" (4 2))
        ("print-unreadable-object" ((&whole 4 1 &rest 1) &body))
        ;; Combines the worst features of BLOCK, LET and TAGBODY
        ("prog"        (&lambda &rest lisp-indent-tagbody))
        ("prog*" . "prog")
        ("prog1" 1)
        ("prog2" 2)
        ("progn" (&rest &body))
        ("progv"       (4 4 &body))
        ("return" 0)
        ("return-from" (nil &body))
        ("symbol-macrolet" . "let")
        ("tagbody"     lisp-indent-tagbody)
        ("throw" 1)
        ("unless" 1)
        ("unwind-protect" (5 &body))
        ("when" 1)
        ("with-accessors" . "multiple-value-bind")
        ("with-condition-restarts" . "multiple-value-bind")
        ("with-compilation-unit" (&lambda &body))
        ("with-output-to-string" (4 2))
        ("with-slots" . "multiple-value-bind")
        ("with-standard-io-syntax" (2))))<commit_msg>tweak<commit_after>(defpackage :lem-lisp-syntax.indent
  (:use :cl :lem-base)
  (:export :*get-method-function*
           :set-indentation
           :update-system-indentation
           :indentation-update
           :calc-indent))
(in-package :lem-lisp-syntax.indent)

(defparameter *body-indent* 2)
(defparameter *max-depth* 4)

(defvar *get-method-function* nil)
(defvar *static-indent-table* (make-hash-table :test 'equal))
(defvar *dynamic-indent-table* (make-hash-table :test 'equal))

(defvar *lambda-list-indentation* t)
(defvar *lambda-list-keyword-parameter-alignment* t)
(defvar *lambda-list-keyword-alignment* t)

(defvar *loop-indent-subclauses* nil)
(defvar *simple-loop-indentation* 2)

(defun get-indentation (name)
  (or (gethash name *static-indent-table*)
      (caar (gethash name *dynamic-indent-table*))))

(defun set-indentation (name method)
  (setf (gethash name *static-indent-table*) method))

(defun update-system-indentation (name indent packages)
  (let ((list (gethash name *dynamic-indent-table*))
        ok)
    (if (null list)
        (setf (gethash name *dynamic-indent-table*)
              (list (cons indent packages)))
        (dolist (spec list)
          (cond ((equal (car spec) indent)
                 (setf (cdr spec)
                       (nunion (cdr spec) packages))
                 (setf ok t))
                (t
                 (setf (cdr spec)
                       (nset-difference (cdr spec) packages :test #'equal))))))
    (unless ok
      (setf (gethash name *dynamic-indent-table*)
            (cons (cons indent packages) list)))))

(defun indentation-update ()
  (do-all-symbols (symbol)
    (let ((key (string-downcase symbol)))
      (alexandria:when-let ((indent (swank::symbol-indentation symbol)))
        (update-system-indentation key
                                   indent
                                   (list (package-name (symbol-package symbol))))))))

(mapc (lambda (elt)
        (let ((name (car elt))
              (method (if (stringp (cdr elt))
                          (get-indentation (cdr elt))
                          (cadr elt))))
          (set-indentation name method)))
      '(("block" 1)
        ("case"        (4 &rest (&whole 2 &rest 1)))
        ("ccase" . "case")
        ("ecase" . "case")
        ("typecase" . "case")
        ("etypecase" . "case")
        ("ctypecase" . "case")
        ("catch" 1)
        ("cond"        (&rest (&whole 2 &rest 1)))
        ("defvar"      (4 2 2))
        ("defclass"    (6 4 (&whole 2 &rest 1) (&whole 2 &rest 1)))
        ("defconstant" . "defvar")
        ("defcustom"   (4 2 2 2))
        ("defparameter" . "defvar")
        ("defconst"     . "defcustom")
        ("define-condition"  . "defclass")
        ("define-modify-macro" (4 &lambda &body))
        ("defsetf"     (4 &lambda 4 &body))
        ("defun"       (4 &lambda &body))
        ("defgeneric"  (4 &lambda &body))
        ("define-setf-method" . "defun")
        ("define-setf-expander" . "defun")
        ("defmacro" . "defun")
        ("defsubst" . "defun")
        ("deftype" . "defun")
        ("defmethod" lisp-indent-defmethod)
        ("defpackage"  (4 &rest (&whole 2 &rest defpackage-body)))
        ("defstruct"   ((&whole 4 &rest (&whole 2 &rest 1))
                        &rest (&whole 2 &rest 1)))
        ("destructuring-bind"
         ((&whole 6 &rest 1) 4 &body))
        ;("do"          lisp-indent-do)
        ("do" 2)
        ("do*" . "do")
        ("dolist"      1)
        ("dotimes" . "dolist")
        ("eval-when"   1)
        ("flet"        ((&whole 4 &rest (&whole 1 &lambda &body)) &body))
        ("labels" . "flet")
        ("macrolet" . "flet")
        ("generic-flet" . "flet")
        ("generic-labels" . "flet")
        ("handler-case" (4 &rest (&whole 2 &lambda &body)))
        ("restart-case" . "handler-case")
        ;; `else-body' style
        ("if"          (nil nil &body))
        ;; single-else style (then and else equally indented)
        ("if"          (&rest nil))
        ;("lambda"      (&lambda &rest lisp-indent-function-lambda-hack))
        ("lambda" (&lambda &body))
        ("let"         ((&whole 4 &rest (&whole 1 2)) &body))
        ("let*" . "let")
        ("compiler-let" . "let") ;barf
        ("handler-bind" . "let")
        ("restart-bind" . "let")
        ("locally" 1)
        ("loop"         lisp-indent-loop)
        ;("loop" (&rest &body))
        (":method" lisp-indent-defmethod) ; in `defgeneric'
        (":default-initargs" (&rest 1))
        ("multiple-value-bind" ((&whole 6 &rest 1) 4 &body))
        ("multiple-value-call" (4 &body))
        ("multiple-value-prog1" 1)
        ("multiple-value-setq" (4 2))
        ("multiple-value-setf" . "multiple-value-setq")
        ("pprint-logical-block" (4 2))
        ("print-unreadable-object" ((&whole 4 1 &rest 1) &body))
        ;; Combines the worst features of BLOCK, LET and TAGBODY
        ("prog"        (&lambda &rest lisp-indent-tagbody))
        ("prog*" . "prog")
        ("prog1" 1)
        ("prog2" 2)
        ("progn" (&rest &body))
        ("progv"       (4 4 &body))
        ("return" 0)
        ("return-from" (nil &body))
        ("symbol-macrolet" . "let")
        ("tagbody"     lisp-indent-tagbody)
        ("throw" 1)
        ("unless" 1)
        ("unwind-protect" (5 &body))
        ("when" 1)
        ("with-accessors" . "multiple-value-bind")
        ("with-condition-restarts" . "multiple-value-bind")
        ("with-compilation-unit" (&lambda &body))
        ("with-output-to-string" (4 2))
        ("with-slots" . "multiple-value-bind")
        ("with-standard-io-syntax" (2))))
{'fraction_non_alphanumeric': 0.17723880597014927, 'fraction_numerical': 0.013592750533049041, 'mean_word_length': 1.9170769629437678, 'pattern_counts': {'":': 3, '<': 3, '<?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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5771783', 'n_tokens_mistral': 3862, 'n_tokens_neox': 3650, 'n_words': 906}