Add guard clauses for file existence and initialize variables

This commit is contained in:
2026-03-26 01:28:24 -07:00
parent d8531f8e4c
commit 2bad83bff9

View File

@@ -9,8 +9,12 @@
(defcustom stride-nav-file (concat user-emacs-directory "stride-nav.el") (defcustom stride-nav-file (concat user-emacs-directory "stride-nav.el")
"File that Stride reads site navigation info from." "File that Stride reads site navigation info from."
:type 'file
:group 'stride) :group 'stride)
(defvar-local stride-nav '()
"Stride navigation list.")
;; (defcustom stride-nav ;; (defcustom stride-nav
;; (with-temp-buffer ;; (with-temp-buffer
;; (insert-file-contents stride-nav-file) ;; (insert-file-contents stride-nav-file)
@@ -22,6 +26,7 @@
(defun stride-read-file () (defun stride-read-file ()
"Read `stride-nav' from `stride-nav-file' file." "Read `stride-nav' from `stride-nav-file' file."
(interactive) (interactive)
(when (file-exists-p stride-nav-file)
(with-temp-buffer (with-temp-buffer
(insert-file-contents stride-nav-file) (insert-file-contents stride-nav-file)
(setq stride-nav (read (buffer-string))))) (setq stride-nav (read (buffer-string)))))
@@ -32,7 +37,7 @@
(let ((inhibit-message t)) (let ((inhibit-message t))
(with-temp-buffer (with-temp-buffer
(insert (pp stride-nav)) (insert (pp stride-nav))
(write-file stride-nav-file))) ) (write-file stride-nav-file))))
(defun stride-match () (defun stride-match ()
"Return matching stride-nav member." "Return matching stride-nav member."
@@ -67,7 +72,7 @@
;; (eval (nth 1 (stride-match))))) ;; (eval (nth 1 (stride-match)))))
;;; Third version. Only gives eww-reload 3 tries. ;;; Third version. Only gives eww-reload 3 tries.
(let ((status (third (plist-get eww-data :error))) (let ((status (third (plist-get eww-data :error))
(tries (or (plist-get eww-data :tries) 1))) (tries (or (plist-get eww-data :tries) 1)))
(if (eq status 400) (if (eq status 400)
(when (<= tries 3) (when (<= tries 3)
@@ -75,13 +80,12 @@
(message "HTTP/1.1 ERROR 400, retry count: %i" (+ tries 1)) (message "HTTP/1.1 ERROR 400, retry count: %i" (+ tries 1))
(eww-reload)) (eww-reload))
(plist-put eww-data :tries 1) (plist-put eww-data :tries 1)
(eval (second (stride-match))))) (eval (second (stride-match))))))
)
(defun stride-forward () (defun stride-forward ()
"Goes to next chapter if in view, else advances to next page. "Goes to next chapter if in view, else advances to next page.
TODO: move function definition to stride-nav for more flexibility TODO: move function definition to stride-nav for more flexibility
when dealing with dificult sites. then eval the lisp here." when dealing with difficult sites. then eval the lisp here."
(interactive) (interactive)
(move-to-window-line -1) (move-to-window-line -1)
(setq-local bottom (point)) (setq-local bottom (point))
@@ -109,9 +113,10 @@ when dealing with dificult sites. then eval the lisp here."
(if stride-mode (if stride-mode
(progn (progn
(add-hook 'eww-after-render-hook 'stride-eww-after-render-hook nil t) (add-hook 'eww-after-render-hook 'stride-eww-after-render-hook nil t)
(setq stride-nav (with-temp-buffer (when (file-exists-p stride-nav-file)
(with-temp-buffer
(insert-file-contents stride-nav-file) (insert-file-contents stride-nav-file)
(read (buffer-string)))) (setq stride-nav (read (buffer-string)))))
;; (setq-local stride-mode-on t) ;; (setq-local stride-mode-on t)
;; (stride-update) ;; (stride-update)
) )