refactor(cli): minor refactors and comment revision

This commit is contained in:
Henrik Lissner 2022-03-31 19:10:10 +02:00
parent cf362bc1a0
commit da1eb4d107
No known key found for this signature in database
GPG key ID: B60957CA074D39A3
2 changed files with 21 additions and 19 deletions

View file

@ -173,19 +173,19 @@ one wants that.")
;; to recentf. ;; to recentf.
find-file-hook find-file-hook
write-file-functions write-file-functions
;; Prevent a possible source of crashes when there's a syntax error ;; Prevent a possible source of crashes when there's a syntax error in
;; in the autoloads file ;; the autoloads file.
debug-on-error debug-on-error
;; Non-nil interferes with autoload generation in Emacs < 29. See ;; Non-nil interferes with autoload generation in Emacs < 29. See
;; raxod502/straight.el#904. ;; raxod502/straight.el#904.
(left-margin 0) (left-margin 0)
;; The following bindings are in `package-generate-autoloads'. ;; The following bindings are in `package-generate-autoloads'.
;; Presumably for a good reason, so I just copied them ;; Presumably for a good reason, so I just copied them.
(backup-inhibited t) (backup-inhibited t)
(version-control 'never) (version-control 'never)
case-fold-search ; reduce magic case-fold-search ; reduce magic
autoload-timestamps ; reduce noise in generated files autoload-timestamps ; reduce noise in generated files
;; Needed for `autoload-generate-file-autoloads' ;; So `autoload-generate-file-autoloads' knows where to write it
(generated-autoload-load-name (file-name-sans-extension file)) (generated-autoload-load-name (file-name-sans-extension file))
(target-buffer (current-buffer)) (target-buffer (current-buffer))
(module (doom-module-from-path file)) (module (doom-module-from-path file))
@ -199,12 +199,15 @@ one wants that.")
file target-buffer module module-enabled-p)))) file target-buffer module module-enabled-p))))
(defun doom-autoloads--scan (files &optional exclude literal) (defun doom-autoloads--scan (files &optional exclude literal)
"Scan and return all autoloaded forms in FILES.
Autoloads will be generated from autoload cookies in FILES (except those that
match one of the regexps in EXCLUDE -- a list of strings). If LITERAL is
non-nil, treat FILES as pre-generated autoload files instead."
(require 'autoload) (require 'autoload)
(let (autoloads) (let (autoloads)
(dolist (file files (nreverse (delq nil autoloads))) (dolist (file files (nreverse (delq nil autoloads)))
(when (and (or (null exclude) (when (and (not (seq-find (doom-rpartial #'string-match-p file) exclude))
(seq-remove (doom-rpartial #'string-match-p file)
exclude))
(file-readable-p file)) (file-readable-p file))
(doom-log "Scanning %s" file) (doom-log "Scanning %s" file)
(setq file (file-truename file)) (setq file (file-truename file))
@ -213,15 +216,14 @@ one wants that.")
(insert-file-contents file) (insert-file-contents file)
(doom-autoloads--scan-file file)) (doom-autoloads--scan-file file))
(save-excursion (save-excursion
(let ((filestr (prin1-to-string file)))
(while (re-search-forward "\\_<load-file-name\\_>" nil t) (while (re-search-forward "\\_<load-file-name\\_>" nil t)
;; `load-file-name' is meaningless in a concatenated ;; `load-file-name' is meaningless in a concatenated
;; mega-autoloads file, so we replace references to it with the ;; mega-autoloads file, but also essential in isolation, so we
;; file they came from. ;; replace references to it with the file they came from.
(let ((ppss (save-excursion (syntax-ppss)))) (let ((ppss (save-excursion (syntax-ppss))))
(or (nth 3 ppss) (or (nth 3 ppss)
(nth 4 ppss) (nth 4 ppss)
(replace-match filestr t t)))))) (replace-match (prin1-to-string file) t t)))))
(let ((load-file-name file) (let ((load-file-name file)
(load-path (load-path
(append (list doom-private-dir) (append (list doom-private-dir)

View file

@ -282,11 +282,11 @@ Note: warnings are not considered failures.")
(defun doom-cli--ci-hook-pre-push (_remote _url) (defun doom-cli--ci-hook-pre-push (_remote _url)
(with-temp-buffer (with-temp-buffer
(let ((z40 "0000000000000000000000000000000000000000") (let ((z40 (make-string 40 ?0))
line error) line error)
(while (setq line (ignore-errors (read-from-minibuffer ""))) (while (setq line (ignore-errors (read-from-minibuffer "")))
(catch 'continue (catch 'continue
(cl-destructuring-bind (local-ref local-sha remote-ref remote-sha) (seq-let (local-ref local-sha remote-ref remote-sha)
(split-string line " ") (split-string line " ")
(unless (or (string-match-p "^refs/heads/\\(master\\|main\\)$" remote-ref) (unless (or (string-match-p "^refs/heads/\\(master\\|main\\)$" remote-ref)
(equal local-sha z40)) (equal local-sha z40))