Skip to content

Instantly share code, notes, and snippets.

@jmercouris
Last active December 10, 2017 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmercouris/183f4ab92e36157554100d0d508cf15e to your computer and use it in GitHub Desktop.
Save jmercouris/183f4ab92e36157554100d0d508cf15e to your computer and use it in GitHub Desktop.
(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