Last active
December 10, 2017 17:04
-
-
Save jmercouris/183f4ab92e36157554100d0d508cf15e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defclass buffer () | |
((name :accessor name :initarg :name) | |
(mode :accessor mode :initarg :mode) | |
(view :accessor view :initarg :view) | |
(modes :accessor modes :initarg :modes))) | |
(defmethod print-object ((self buffer) stream) | |
(format stream "~s" (name self))) | |
(defmethod add-mode ((self buffer) mode &optional (overwrite nil)) | |
(let ((found-mode (find mode (modes self) | |
:test #'(lambda (class mode) (typep mode class))))) | |
(unless found-mode | |
(push mode (modes self))) | |
(when (and found-mode overwrite) | |
(setf (modes self) | |
(remove-if #'(lambda (item) (typep item 'mode)) (modes self))) | |
(push mode (modes self))))) | |
(defmethod switch-mode ((self buffer) mode-class) | |
(let ((found-mode | |
(find mode-class (modes self) | |
:test #'(lambda (class mode) (typep mode class))))) | |
(if found-mode | |
(setf (mode self) found-mode) | |
nil))) | |
(defmethod add-or-switch-to-mode ((self buffer) mode) | |
(add-mode self mode) | |
(switch-mode self (class-of mode))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment