-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathevalator-history.el
66 lines (57 loc) · 2.27 KB
/
evalator-history.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
;;; evalator-history.el --- History helpers
;;
;; Author: Sean Irby
;; Copyright © , Sean Irby
;;
;; 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 GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; This file is not a part of GNU Emacs
;;
;;; Commentary:
;;
;;; Code:
(require 'cl-lib)
(require 'evalator-utils)
(require 'evalator-state)
(require 'helm)
(defun evalator-history ()
"Return history vector."
(plist-get evalator-state :history))
(defun evalator-history-index ()
"Return current history index."
(plist-get evalator-state :history-index))
(defun evalator-history-push! (candidates expression)
"Push the CANDIDATES and EXPRESSION onto history.
Increments the history index."
(evalator-utils-put! evalator-state
:history
(vconcat (cl-subseq (evalator-history) 0 (+ 1 (evalator-history-index)))
(list (list :candidates candidates :expression expression))))
(evalator-utils-put! evalator-state :history-index (+ 1 (evalator-history-index))))
(defun evalator-history-current (&optional k)
"Retrieve active history element. Accepts an optional keyword K."
(let ((h (elt (evalator-history) (evalator-history-index))))
(if k (plist-get h k) h)))
(defun evalator-history-expression-chain ()
"Return a list of all expressions in history except for the first.
The first expression is always an empty string so it is ignored."
(cdr (mapcar
(lambda (h)
(plist-get h :expression))
(plist-get evalator-state :history))))
(provide 'evalator-history)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; evalator-history.el ends here