Skip to content

Commit 8a7f79d

Browse files
committed
Add functions for each vi-mode options, like 'lem-vi-mode:autochdir'.
1 parent b4b18d2 commit 8a7f79d

File tree

2 files changed

+37
-24
lines changed

2 files changed

+37
-24
lines changed

extensions/vi-mode/options.lisp

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,10 @@
2424
#:vi-option-documentation
2525
#:reset-vi-option-value
2626
#:toggle-vi-option-value
27-
#:execute-set-command))
27+
#:execute-set-command
28+
29+
;; Options
30+
#:autochdir))
2831
(in-package #:lem-vi-mode/options)
2932

3033
(defstruct vi-option
@@ -40,27 +43,6 @@
4043
(defvar *options* (make-hash-table :test 'equal))
4144
(defvar *option-aliases* (make-hash-table :test 'equal))
4245

43-
(defmacro define-vi-option (name (default &key (type t) aliases) &rest others)
44-
(once-only (name default)
45-
(with-gensyms (option alias)
46-
`(progn
47-
(dolist (,alias ',aliases)
48-
(setf (gethash ,alias *option-aliases*) ,name))
49-
(check-type ,default ,type)
50-
(let ((,option
51-
(make-vi-option :name ,name
52-
:%value ,default
53-
:default ,default
54-
:type ',type
55-
:aliases ',aliases
56-
:getter ,(when-let (getter-arg (find :getter others :key #'car))
57-
`(lambda () ,@(rest getter-arg)))
58-
:set-hook ,(when-let (set-hook-arg (find :set-hook others :key #'car))
59-
`(lambda ,@(rest set-hook-arg)))
60-
:documentation ,(when-let (doc-arg (find :documentation others :key #'car))
61-
(second doc-arg)))))
62-
(setf (gethash ,name *options*) ,option))))))
63-
6446
(defun canonical-option-name (name)
6547
(or (gethash name *option-aliases*)
6648
name))
@@ -147,10 +129,36 @@
147129
(null suffix)))
148130
(setf (vi-option-value option) t))))))
149131

132+
(defmacro define-vi-option (name (default &key (type t) aliases) &rest others)
133+
(once-only (default)
134+
(with-gensyms (option alias new-value)
135+
(let ((name-str (string-downcase name)))
136+
`(progn
137+
(check-type ,default ,type)
138+
(dolist (,alias ',aliases)
139+
(setf (gethash ,alias *option-aliases*) ,name-str))
140+
(let ((,option
141+
(make-vi-option :name ,name-str
142+
:%value ,default
143+
:default ,default
144+
:type ',type
145+
:aliases ',aliases
146+
:getter ,(when-let (getter-arg (find :getter others :key #'car))
147+
`(lambda () ,@(rest getter-arg)))
148+
:set-hook ,(when-let (set-hook-arg (find :set-hook others :key #'car))
149+
`(lambda ,@(rest set-hook-arg)))
150+
:documentation ,(when-let (doc-arg (find :documentation others :key #'car))
151+
(second doc-arg)))))
152+
(setf (gethash ,name-str *options*) ,option)
153+
(defun ,name ()
154+
(vi-option-value (get-option ,name-str)))
155+
(defun (setf ,name) (,new-value)
156+
(setf (vi-option-value (get-option ,name-str)) ,new-value))))))))
157+
150158
(defun auto-change-directory (buffer)
151159
(change-directory (lem:buffer-directory buffer)))
152160

153-
(define-vi-option "autochdir" (nil :type boolean :aliases ("acd"))
161+
(define-vi-option autochdir (nil :type boolean :aliases ("acd"))
154162
(:documentation "A flag on whether change the current directory to the buffer directory automatically.
155163
Default: nil
156164
Aliases: acd")

extensions/vi-mode/vi-mode.lisp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
:lem
44
:lem-vi-mode/core
55
:lem-vi-mode/ex)
6+
(:import-from #:lem-vi-mode/options
7+
#:autochdir)
68
(:export :vi-mode
79
:define-vi-state
810
:*command-keymap*
911
:*insert-keymap*
10-
:*ex-keymap*))
12+
:*ex-keymap*
13+
14+
;; Options
15+
#:autochdir))

0 commit comments

Comments
 (0)