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

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