summaryrefslogtreecommitdiffhomepage
path: root/lib/doc
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-08-13 19:41:47 +0100
committerjao <jao@gnu.org>2022-08-13 19:41:47 +0100
commit65855b5c9980ff282234fb91a82a45d75b67f8c1 (patch)
tree300358c5cefdf3613c88e59bba703549adefcd2c /lib/doc
parent7fd611550b54dd47b1da695bbdf8d2ee9e1746fa (diff)
downloadelibs-65855b5c9980ff282234fb91a82a45d75b67f8c1.tar.gz
elibs-65855b5c9980ff282234fb91a82a45d75b67f8c1.tar.bz2
completion: no auto en eshell
Diffstat (limited to 'lib/doc')
-rw-r--r--lib/doc/jao-doc-session.el75
1 files changed, 75 insertions, 0 deletions
diff --git a/lib/doc/jao-doc-session.el b/lib/doc/jao-doc-session.el
new file mode 100644
index 0000000..9a3193f
--- /dev/null
+++ b/lib/doc/jao-doc-session.el
@@ -0,0 +1,75 @@
+;;; jao-doc-session.el --- persistent document sessions -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 jao
+
+;; Author: jao <mail@jao.io>
+;; Keywords: docs
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+;;; Code:
+
+(defvar jao-doc-session-file "~/.emacs.d/cache/doc-view-session.eld")
+(defvar-local jao-doc-session--is-doc nil)
+
+(defun jao-doc-session-is-doc (&optional buffer)
+ (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-save (&optional skip-current)
+ (interactive)
+ (let ((docs '())
+ (cb (and skip-current (current-buffer))))
+ (dolist (b (buffer-list))
+ (when-let (fn (and (not (eq cb b)) (jao-doc-session-is-doc b)))
+ (add-to-list 'docs fn)))
+ (when (> (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))
+
+(defun jao-doc-session-mark (&optional path)
+ (setq jao-doc-session--is-doc (or path (buffer-file-name)))
+ (jao-doc-session--save-session))
+
+(defun jao-doc-session--save-1 ()
+ (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)
+
+(provide 'jao-doc-session)
+;;; jao-doc-session.el ends here