<commit_before>;;; core/autoload/packages.el -*- lexical-binding: t; -*-

(require 'core-packages)
(load! "cache") ; in case autoloads haven't been generated yet


(defun doom--packages-choose (prompt)
  (let ((table (cl-loop for pkg in package-alist
                        unless (doom-package-built-in-p (cdr pkg))
                        collect (cons (package-desc-full-name (cdr pkg))
                                      (cdr pkg)))))
    (cdr (assoc (completing-read prompt
                                 (mapcar #'car table)
                                 nil t)
                table))))

(defun doom--refresh-pkg-cache ()
  "Clear the cache for `doom-refresh-packages-maybe'."
  (setq doom--refreshed-p nil)
  (doom-cache-set 'last-pkg-refresh nil))

(defun doom--refresh-pkg-contents ()
  (unless (file-exists-p package-user-dir)
    (make-directory package-user-dir t))
  (require 'gnutls)
  (let ((old-gnutls-algorithm-priority gnutls-algorithm-priority))
    ;; See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=3434
    (setq gnutls-algorithm-priority "NORMAL:-VERS-TLS1.3")
    (unwind-protect
        (progn
          (let ((default-keyring (expand-file-name "package-keyring.gpg"
                                                   data-directory)))
            (when (and package-check-signature (file-exists-p default-keyring))
              (condition-case-unless-debug error
                  (package-import-keyring default-keyring)
                (error (message "Cannot import default keyring: %S" (cdr error))))))
          (dolist (archive package-archives)
            (cl-pushnew archive package--downloads-in-progress
                        :test #'equal))
          (dolist (archive package-archives)
            (package--download-one-archive archive "archive-contents" nil)))
      (setq gnutls-algorithm-priority old-gnutls-algorithm-priority))))

;;;###autoload
(defun doom-refresh-packages-maybe (&optional force-p)
  "Refresh ELPA packages, if it hasn't been refreshed recently."
  (when force-p
    (doom--refresh-pkg-cache))
  (unless (or (doom-cache-get 'last-pkg-refresh)
              doom--refreshed-p)
    (condition-case e
        (progn
          (message "Refreshing package archives")
          (doom--refresh-pkg-contents)
          (doom-cache-set 'last-pkg-refresh t 1200))
      ((debug error)
       (message "Trying again %s" e)
       (doom--refresh-pkg-contents)
       (signal 'doom-error e)))))


;;
;;; Package metadata

;;;###autoload
(defun doom-package-plist (package)
  "Returns PACKAGE's `package!' recipe from `doom-packages'."
  (cdr (assq package doom-packages)))

;;;###autoload
(defun doom-package-desc (package)<commit_msg>Fix "err=[-50]" gnutls error<commit_after>;;; core/autoload/packages.el -*- lexical-binding: t; -*-

(require 'core-packages)
(load! "cache") ; in case autoloads haven't been generated yet


(defun doom--packages-choose (prompt)
  (let ((table (cl-loop for pkg in package-alist
                        unless (doom-package-built-in-p (cdr pkg))
                        collect (cons (package-desc-full-name (cdr pkg))
                                      (cdr pkg)))))
    (cdr (assoc (completing-read prompt
                                 (mapcar #'car table)
                                 nil t)
                table))))

(defun doom--refresh-pkg-cache ()
  "Clear the cache for `doom-refresh-packages-maybe'."
  (setq doom--refreshed-p nil)
  (doom-cache-set 'last-pkg-refresh nil))

;;;###autoload
(defun doom-refresh-packages-maybe (&optional force-p)
  "Refresh ELPA packages, if it hasn't been refreshed recently."
  (when force-p
    (doom--refresh-pkg-cache))
  (unless (or (doom-cache-get 'last-pkg-refresh)
              doom--refreshed-p)
    (condition-case e
        (progn
          (message "Refreshing package archives")
          (package-refresh-contents)
          (doom-cache-set 'last-pkg-refresh t 1200))
    ((debug error)
     (doom--refresh-pkg-cache)
     (signal 'doom-error e)))))


;;
;;; Package metadata

;;;###autoload
(defun doom-package-plist (package)
  "Returns PACKAGE's `package!' recipe from `doom-packages'."
  (cdr (assq package doom-packages)))

;;;###autoload
(defun doom-package-desc (package)
{'fraction_non_alphanumeric': 0.14275618374558305, 'fraction_numerical': 0.003769140164899882, 'mean_word_length': 2.2239939255884584, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2818047', 'n_tokens_mistral': 1386, 'n_tokens_neox': 1306, 'n_words': 307}