summaryrefslogtreecommitdiffhomepage
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/doc/jao-doc-session.el40
1 files changed, 11 insertions, 29 deletions
diff --git a/lib/doc/jao-doc-session.el b/lib/doc/jao-doc-session.el
index 669b191..877a8cb 100644
--- a/lib/doc/jao-doc-session.el
+++ b/lib/doc/jao-doc-session.el
@@ -1,6 +1,6 @@
;;; jao-doc-session.el --- persistent document sessions -*- lexical-binding: t; -*-
-;; Copyright (C) 2022 jao
+;; Copyright (C) 2022, 2024 jao
;; Author: jao <mail@jao.io>
;; Keywords: docs
@@ -20,30 +20,18 @@
;;; Code:
-(defvar jao-doc-session-file "~/.emacs.d/cache/doc-view-session.eld")
+(persist-defvar jao-doc-session nil "Documents session")
+
(defvar-local jao-doc-session--is-doc nil)
(defun jao-doc-session-is-doc (&optional buffer)
+ "Check whether the given or current buffer belong to the doc session."
(buffer-local-value 'jao-doc-session--is-doc (or buffer (current-buffer))))
-(defun jao-doc-session--read-file (file)
- (let ((buff (find-file-noselect file)))
- (ignore-errors
- (with-current-buffer buff
- (goto-char (point-min)))
- (read buff))))
-
-(defun jao-doc-session--save-to-file (file value)
- (with-current-buffer (find-file-noselect file)
- (erase-buffer)
- (insert (format "%S" value))
- (save-buffer)))
-
-(defun jao-doc-session (&optional file)
- (let ((file (or file jao-doc-session-file)))
- (jao-doc-session--read-file file)))
+(defun jao-doc-session (&optional file) jao-doc-session)
(defun jao-doc-session-save (&optional skip-current force)
+ "Traverse all current buffers and update the value of `jao-doc-session'."
(interactive)
(let ((docs '())
(cb (and skip-current (current-buffer))))
@@ -51,27 +39,21 @@
(when-let (fs (and (not (eq cb b)) (jao-doc-session-is-doc b)))
(dolist (f fs) (add-to-list 'docs f))))
(when (or force (> (length docs) 0))
- (jao-doc-session--save-to-file jao-doc-session-file docs))))
-
-(defun jao-doc-session--save-session ()
- (let ((inhibit-message t)
- (message-log-max nil))
- (when (not jao-doc-session-inhibit-save) (jao-doc-session-save))
- t))
+ (setq jao-doc-session docs))))
(defun jao-doc-session-mark (&optional path)
+ "Mark the current buffer's file, or PATH, as persistent across sessions."
(unless (listp jao-doc-session--is-doc)
(setq jao-doc-session--is-doc (ensure-list jao-doc-session--is-doc)))
(cl-pushnew (or path (buffer-file-name)) jao-doc-session--is-doc)
- (jao-doc-session--save-session))
+ (jao-doc-session-save))
-(defun jao-doc-session--save-1 ()
+(defun jao-doc-session--maybe-save ()
(when (jao-doc-session-is-doc) (jao-doc-session-save t)))
(defvar jao-doc-session-inhibit-save nil)
-(add-hook 'kill-emacs-query-functions #'jao-doc-session--save-session)
-(add-hook 'kill-buffer-hook #'jao-doc-session--save-1)
+(add-hook 'kill-buffer-hook #'jao-doc-session--maybe-save)
(provide 'jao-doc-session)
;;; jao-doc-session.el ends here