|
24 | 24 | #:vi-option-documentation |
25 | 25 | #:reset-vi-option-value |
26 | 26 | #:toggle-vi-option-value |
27 | | - #:execute-set-command)) |
| 27 | + #:execute-set-command |
| 28 | + |
| 29 | + ;; Options |
| 30 | + #:autochdir)) |
28 | 31 | (in-package #:lem-vi-mode/options) |
29 | 32 |
|
30 | 33 | (defstruct vi-option |
|
40 | 43 | (defvar *options* (make-hash-table :test 'equal)) |
41 | 44 | (defvar *option-aliases* (make-hash-table :test 'equal)) |
42 | 45 |
|
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 | | - |
64 | 46 | (defun canonical-option-name (name) |
65 | 47 | (or (gethash name *option-aliases*) |
66 | 48 | name)) |
|
147 | 129 | (null suffix))) |
148 | 130 | (setf (vi-option-value option) t)))))) |
149 | 131 |
|
| 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 | + |
150 | 158 | (defun auto-change-directory (buffer) |
151 | 159 | (change-directory (lem:buffer-directory buffer))) |
152 | 160 |
|
153 | | -(define-vi-option "autochdir" (nil :type boolean :aliases ("acd")) |
| 161 | +(define-vi-option autochdir (nil :type boolean :aliases ("acd")) |
154 | 162 | (:documentation "A flag on whether change the current directory to the buffer directory automatically. |
155 | 163 | Default: nil |
156 | 164 | Aliases: acd") |
|
0 commit comments