<commit_before>;;;; SPDX-FileCopyrightText: Atlas Engineer LLC
;;;; SPDX-License-Identifier: BSD-3-Clause

(in-package :nyxt)

(define-class application-profile (nfiles:profile)
  ((nfiles:name "nyxt"))
  (:export-class-name-p t)
  (:export-accessor-names-p t)
  (:accessor-name-transformer (class*:make-name-transformer name))
  (:documentation "We define our own 'default profile' (instead of using
`nfiles:profile' directly) so that we can specialize the methods."))

(export-always '*global-profile*)
(defvar *global-profile* (make-instance 'application-profile)
  "The profile to use in the absence of buffers and on browser-less variables.")

(define-class nyxt-file (nfiles:file)
  ((nfiles:profile *global-profile*)
   (editable-p
    t
    :type boolean
    :documentation "If the file can be editted using a text editor.
It's not always the case, take the socket for instance."))
  (:export-class-name-p t)
  (:export-accessor-names-p t)
  (:accessor-name-transformer (class*:make-name-transformer name))
  (:documentation "All Nyxt files."))

(define-class nyxt-lisp-file (nyxt-file nfiles:lisp-file)
  ()
  (:export-class-name-p t)
  (:export-accessor-names-p t)
  (:accessor-name-transformer (class*:make-name-transformer name))
  (:documentation "Nyxt Lisp files."))

(define-class nosave-profile (nfiles:read-only-profile application-profile)
  ((nfiles:name "nosave"))
  (:export-class-name-p t)
  (:export-accessor-names-p t)
  (:accessor-name-transformer (class*:make-name-transformer name))
  (:documentation "We define our own 'default profile' (instead of using
`nfiles:profile' directly) so that we can specialize the methods."))

(defmethod nfiles:resolve ((profile application-profile) (file nyxt-file))
  "Prefix FILE base-path with PROFILE's `nfiles:name'."
  (unless (or (uiop:absolute-pathname-p (nfiles:base-path file))
              (string=
               (nfiles:name profile)
               (second (pathname-directory (uiop:ensure-directory-pathname
                                            (nfiles:base-path file))))))
    (setf (slot-value file 'nfiles:base-path)
          (sera:path-join
           (uiop:ensure-directory-pathname (nfiles:name profile))
           (nfiles:base-path file))))
  (call-next-method))

(defmethod nfiles:serialize ((profile application-profile) (file nyxt-lisp-file) &key)
  ;; TODO: Error handling!
  (s-serialization:serialize-sexp (nfiles:content file) nil))

(defmethod nfiles:deserialize ((profile application-profile) (file nyxt-lisp-file) raw-content &key)
  (s-serialization:deserialize-sexp raw-content))<commit_msg>user-files: Ensure nyxt-lisp-files default to the Nyxt package.<commit_after>;;;; SPDX-FileCopyrightText: Atlas Engineer LLC
;;;; SPDX-License-Identifier: BSD-3-Clause

(in-package :nyxt)

(define-class application-profile (nfiles:profile)
  ((nfiles:name "nyxt"))
  (:export-class-name-p t)
  (:export-accessor-names-p t)
  (:accessor-name-transformer (class*:make-name-transformer name))
  (:documentation "We define our own 'default profile' (instead of using
`nfiles:profile' directly) so that we can specialize the methods."))

(export-always '*global-profile*)
(defvar *global-profile* (make-instance 'application-profile)
  "The profile to use in the absence of buffers and on browser-less variables.")

(define-class nyxt-file (nfiles:file)
  ((nfiles:profile *global-profile*)
   (editable-p
    t
    :type boolean
    :documentation "If the file can be editted using a text editor.
It's not always the case, take the socket for instance."))
  (:export-class-name-p t)
  (:export-accessor-names-p t)
  (:accessor-name-transformer (class*:make-name-transformer name))
  (:documentation "All Nyxt files."))

(define-class nyxt-lisp-file (nyxt-file nfiles:lisp-file)
  ()
  (:export-class-name-p t)
  (:export-accessor-names-p t)
  (:accessor-name-transformer (class*:make-name-transformer name))
  (:documentation "Nyxt Lisp files."))

(define-class nosave-profile (nfiles:read-only-profile application-profile)
  ((nfiles:name "nosave"))
  (:export-class-name-p t)
  (:export-accessor-names-p t)
  (:accessor-name-transformer (class*:make-name-transformer name))
  (:documentation "We define our own 'default profile' (instead of using
`nfiles:profile' directly) so that we can specialize the methods."))

(defmethod nfiles:resolve ((profile application-profile) (file nyxt-file))
  "Prefix FILE base-path with PROFILE's `nfiles:name'."
  (unless (or (uiop:absolute-pathname-p (nfiles:base-path file))
              (string=
               (nfiles:name profile)
               (second (pathname-directory (uiop:ensure-directory-pathname
                                            (nfiles:base-path file))))))
    (setf (slot-value file 'nfiles:base-path)
          (sera:path-join
           (uiop:ensure-directory-pathname (nfiles:name profile))
           (nfiles:base-path file))))
  (call-next-method))

(defmethod nfiles:serialize ((profile application-profile) (file nyxt-lisp-file) &key)
  ;; TODO: Error handling!
  ;; We need to make sure current package is :nyxt so that symbols are printed
  ;; with consistent namespaces.
  (let ((*package* (find-package :nyxt))
        (*print-length* nil))
    (s-serialization:serialize-sexp (nfiles:content file) nil)))

(defmethod nfiles:deserialize ((profile application-profile) (file nyxt-lisp-file) raw-content &key)
  ;; We need to make sure current package is :nyxt so that symbols are printed
  ;; with consistent namespaces.
  (let ((*package* (find-package :nyxt)))
    (s-serialization:deserialize-sexp raw-content)))
{'fraction_non_alphanumeric': 0.13970983342289092, 'fraction_numerical': 0.0003582303421099767, 'mean_word_length': 3.9723953695458594, 'pattern_counts': {'":': 0, '<': 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': '1840448', 'n_tokens_mistral': 1811, 'n_tokens_neox': 1747, 'n_words': 464}