-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasi-session.el
72 lines (55 loc) · 2.34 KB
/
easi-session.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
;;; easi-session.el --- Session managment facilities -*- lexical-binding: t; -*-
;; Copyright (C) 2023 Hugo Heagren
;; Author: Hugo Heagren <[email protected]>
;; 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/>.
;;; Commentary:
;; This module provides code for managing Ease's sessions -- mutable
;; data structures used internally to keep track of state when using
;; Easi.
;;; Code:
(require 'cl-lib)
(defvar easi-session-list nil
"List of easi sessions. Each is an `easi-session-state'.")
(cl-defstruct (easi-session-state
(:constructor easi-session-state-create))
"Holds current easi search and presentation state."
window-config
query searchables results
results-buffers result-buffers
buffer-presenters
(page 1)
results-thread)
;; TODO this should probably be a method
(defun easi-session--current-buffer-presenter (session)
"Get results presenter for current buffer in SESSION."
(alist-get (current-buffer)
(easi-session-state-buffer-presenters session)))
(defun easi-session--get-current ()
"Return first session with current buffer.
Search the \"result-buffers\" and \"results-buffers\" slots of
each item in `easi-session-list' and return first where current
buffer appears."
(let ((buf (current-buffer)))
(cl-find-if
(lambda (session)
(or (memq buf (easi-session-state-result-buffers session))
(memq buf (easi-session-state-results-buffers session))))
easi-session-list)))
(defun easi-session--get-create-current ()
"Get current session, creating one if necessary.
If a session is created, it is added to `easi-session-list'."
(or (easi-session--get-current)
(let* ((session (easi-session-state-create)))
(push session easi-session-list)
session)))
(provide 'easi-session)
;;; easi-session.el ends here