Skip to content

Commit

Permalink
Persist buffer modes in history.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ambrevar committed Nov 7, 2022
1 parent 0254795 commit 2b6e80d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
17 changes: 16 additions & 1 deletion source/buffer.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,19 @@ buffer, with a meaningful result."
To access all modes, including disabled ones, use `slot-value'."
(sera:filter #'enabled-p (slot-value buffer 'modes)))

(defmethod (setf modes) (value (buffer modable-buffer))
"Only return enabled modes.
To access all modes, including disabled ones, use `slot-value'."
(setf (slot-value buffer 'modes) value)
(files:with-file-content (history (history-file buffer)
:default (make-history-tree))
(let ((buffer-history-entry (or (htree:data (gethash (id buffer) (htree:owners history)))
(make-instance 'buffer-history-entry))))
(setf (modes buffer-history-entry)
(mapcar 'name (modes buffer)))
(setf (htree:data (gethash (id buffer) (htree:owners history)))
buffer-history-entry))))

(define-class input-buffer (buffer)
((keyscheme
keyscheme:cua
Expand Down Expand Up @@ -787,7 +800,9 @@ Return the created buffer."
:creator-id (when (and parent-buffer
(not (nosave-buffer-p buffer))
(not (nosave-buffer-p parent-buffer)))
(id parent-buffer))))))
(id parent-buffer))
:data (make-instance 'buffer-history-entry
:modes (mapcar 'name (modes buffer)))))))
buffer)

(define-command update-document-model (&key (buffer (current-buffer)))
Expand Down
11 changes: 10 additions & 1 deletion source/history.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ It's a list of a form (Y &OPTIONAL X)."))
Entry for the global history.
The total number of visit for a given URL is (+ explicit-visits implicit-visits)."))

(define-class buffer-history-entry () ; TODO: Export?
((modes
'()
:type (list-of symbol)
:documentation "List of modes that were last active for buffer."))
(:accessor-name-transformer (class*:make-name-transformer name))
(:documentation "Buffer state to restore when restoring history."))

(export-always 'equals)
(defmethod equals ((e1 history-entry) (e2 history-entry))
(quri:uri= (url e1) (url e2)))
Expand Down Expand Up @@ -344,7 +352,8 @@ Return non-NIL of history was restored, NIL otherwise."
:url (url (htree:data current-node))
:load-url-p nil)))
(setf (gethash owner-id old-id->new-id) (id new-buffer))
(setf (gethash (id new-buffer) new-owners) owner))))))
(setf (gethash (id new-buffer) new-owners) owner)
(enable-modes (modes (htree:data owner)) new-buffer))))))
(alex:hash-table-alist (htree:owners history)))
(maphash (lambda (_ owner)
(declare (ignore _))
Expand Down

0 comments on commit 2b6e80d

Please sign in to comment.