summaryrefslogtreecommitdiff
path: root/source/keyscheme.lisp
diff options
context:
space:
mode:
authorAndré A. Gomes <andremegafone@gmail.com>2022-07-14 09:45:39 +0300
committerAndré A. Gomes <andremegafone@gmail.com>2022-07-14 10:22:04 +0300
commit88a35fd0205b563d20d339ad0ca13b65618138f7 (patch)
treee38cf8404b998db696a3b8d37b3dee6480ed3bdb /source/keyscheme.lisp
parent13587820978bde57096f20359074544e5506800e (diff)
Rename scheme.lisp to keyscheme.lisp
This should have been part of PR #2413.
Diffstat (limited to 'source/keyscheme.lisp')
-rw-r--r--source/keyscheme.lisp58
1 files changed, 58 insertions, 0 deletions
diff --git a/source/keyscheme.lisp b/source/keyscheme.lisp
new file mode 100644
index 000000000..9486b9aea
--- /dev/null
+++ b/source/keyscheme.lisp
@@ -0,0 +1,58 @@
+;;;; SPDX-FileCopyrightText: Atlas Engineer LLC
+;;;; SPDX-License-Identifier: BSD-3-Clause
+
+;; We use `uiop:define-package' instead of `nyxt:define-package' since this does
+;; not depend on Nyxt at all.
+(uiop:define-package :nyxt/keyscheme
+ (:use :common-lisp)
+ (:import-from #:serapeum
+ #:export-always
+ #:->)
+ (:documentation "Nyxt type specialization for `keymap' bound values."))
+(in-package :nyxt) ; In case the package is locked.
+(trivial-package-local-nicknames:add-package-local-nickname :keyscheme :nyxt/keyscheme :nyxt)
+(in-package :nyxt/keyscheme)
+
+;; Setting `nkeymaps:keymap' bound-value type to something like `function-symbol'
+;; is not practical because functions defined in the same file as the keymap are
+;; not `fboundp' at compile-time.
+;;
+;; To overcome this limitation, we can first load the system, then set the type
+;; to something more specific and reload the system to catch the type errors.
+
+(export-always 'nyxt-keymap-value)
+#+nyxt-debug-keymap
+(deftype nyxt-keymap-value ()
+ '(or nkeymaps:keymap nyxt:function-symbol nyxt::command))
+
+#-nyxt-debug-keymap
+(deftype nyxt-keymap-value ()
+ '(or nkeymaps:keymap t))
+
+(export-always 'make-keyscheme)
+(defun make-keyscheme (name &rest parents)
+ "Return a new `nkeymaps:keyscheme' object of type `nyxt-keymap-value'.
+The scheme name inherits from the optional PARENTS, ordered by priority.
+
+Example:
+
+ (defvar emacs (make-keyscheme \"emacs\" cua))
+
+In the above, we define a new scheme name called `emacs' which inherits from the
+existing keyscheme `cua'."
+ (the (values nkeymaps:keyscheme &optional)
+ (make-instance 'nkeymaps:keyscheme
+ :name name
+ :parents parents
+ :bound-type 'nyxt-keymap-value)))
+
+(export-always 'default)
+(defvar default (make-keyscheme "default"))
+(export-always 'cua)
+(defvar cua (make-keyscheme "cua" default))
+(export-always 'emacs)
+(defvar emacs (make-keyscheme "emacs" default))
+(export-always 'vi-normal)
+(defvar vi-normal (make-keyscheme "vi-normal" default))
+(export-always 'vi-insert)
+(defvar vi-insert (make-keyscheme "vi-insert"))