Make def-setting! behave more like defmacro

set! used to aggressively evaluate its arguments (at expansion-time),
even if placed inside an after! block. This causes unavoidable errors if
those arguments use functions/variables that don't exist yet.

Fixes #112
This commit is contained in:
Henrik Lissner 2017-06-19 00:22:04 +02:00
parent 27cbd36b69
commit 928812da8a
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
12 changed files with 104 additions and 107 deletions

View file

@ -15,11 +15,12 @@ PLIST accepts the following properties:
:when FORM A predicate to determine if the builder is appropriate for this
buffer."
`(dolist (mode ',(if (listp modes) modes (list modes)) +eval-builders)
`(dolist (mode ',(doom-enlist (doom-unquote modes)) +eval-builders)
(unless (assq mode +eval-builders)
(push (list mode) +eval-builders))
(push (cons ',name (append (list :fn #',fn) ',plist))
(cdr (assq mode +eval-builders)))))
(cl-pushnew (cons ,name (append (list :fn ,fn) (list ,@plist)))
(cdr (assq mode +eval-builders))
:test #'eq :key #'car)))
;;
@ -35,9 +36,9 @@ PLIST accepts the following properties:
:init-value nil)
(def-setting! :repl (mode command)
"Define a REPL for a mode. MODE is a major mode and COMMAND is a function that
invokes the repl. Takes the same arguements as `rtog/add-repl'."
`(push ',(cons mode command) +eval-repls))
"Define a REPL for a mode. MODE is a major mode symbol and COMMAND is a
function that creates and returns the REPL buffer."
`(push (cons ,mode ,command) +eval-repls))
(set! :popup
'(:custom (lambda (b &rest _) (buffer-local-value '+eval-repl-mode b)))
@ -67,19 +68,20 @@ invokes the repl. Takes the same arguements as `rtog/add-repl'."
(quickrun-add-command MODE COMMAND :mode MODE).
4. If MODE is not a string and COMMANd is a symbol, add it to
`+eval-runners-alist', which is used by `+eval/region'."
(cond ((symbolp command)
`(push ',(cons mode command) +eval-runners-alist))
((stringp command)
`(after! quickrun
(push ',(cons mode command)
,(if (stringp mode)
'quickrun-file-alist
'quickrun--major-mode-alist))))
((listp command)
`(after! quickrun
(quickrun-add-command
,(symbol-name mode)
',command :mode ',mode)))))
(let ((command (doom-unquote command)))
(cond ((symbolp command)
`(push (cons ,mode ',command) +eval-runners-alist))
((stringp command)
`(after! quickrun
(push (cons ,mode ',command)
,(if (stringp mode)
'quickrun-file-alist
'quickrun--major-mode-alist))))
((listp command)
`(after! quickrun
(quickrun-add-command
,(symbol-name (doom-unquote mode))
',command :mode ,mode))))))
(def-package! quickrun
:commands (quickrun

View file

@ -3,19 +3,14 @@
;; I'm a vimmer at heart. Its modal philosophy suits me better, and this module
;; strives to make Emacs a much better vim than vim was.
(def-setting! :evil-state (&rest mode-state-list)
(def-setting! :evil-state (modes state)
"Set the initialize STATE of MODE using `evil-set-initial-state'."
(if (cl-every #'listp mode-state-list)
`(progn
,@(let (forms)
(dolist (it mode-state-list (nreverse forms))
(unless (consp it)
(error ":evil-state expected cons cells, got %s" it))
(push `(evil-set-initial-state ',(car it) ',(cdr it)) forms))))
(let ((argc (length mode-state-list)))
(unless (= argc 2)
(error ":evil-state expected 2 arguments, got %s" argc)))
`(evil-set-initial-state ',(car mode-state-list) ',(cadr mode-state-list))))
(let ((unquoted-modes (doom-unquote modes)))
(if (listp unquoted-modes)
`(progn
,@(cl-loop for mode in unquoted-modes
collect `(evil-set-initial-state ',mode ,state)))
`(evil-set-initial-state ,modes ,state))))
;;

View file

@ -11,6 +11,5 @@
'("*vc-change-log*" :size 15)
'(vc-annotate-mode :same t))
(set! :evil-state
'(vc-annotate-mode . normal)
'(vc-git-log-view-mode . normal)))
(set! :evil-state 'vc-annotate-mode 'normal)
(set! :evil-state 'vc-git-log-view-mode 'normal))