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:
parent
27cbd36b69
commit
928812da8a
12 changed files with 104 additions and 107 deletions
|
@ -12,20 +12,27 @@
|
|||
;; Config
|
||||
;;
|
||||
|
||||
(defvar +email--accounts nil)
|
||||
(def-setting! :email (label letvars &optional default-p)
|
||||
"Registers an email address for mu4e. The LABEL is a string. LETVARS are a
|
||||
list of cons cells (VARIABLE . VALUE) -- you may want to modify:
|
||||
|
||||
(def-setting! :email (label letvars &optional default)
|
||||
"Registers an email address for mu4e."
|
||||
(let ((name (or (cdr (assq 'user-full-name letvars)) user-full-name))
|
||||
(address (cdr (assq 'user-mail-address letvars))))
|
||||
(dolist (var letvars)
|
||||
(let ((val (cdr var)))
|
||||
(when (and (stringp val) (string-match-p "%s" val))
|
||||
(setcdr var (format val label)))))
|
||||
`(progn
|
||||
(push ',(cons label letvars) +email--accounts)
|
||||
,(when address
|
||||
`(add-to-list 'mu4e-user-mail-address-list ,address))
|
||||
+ `user-full-name' (this or the global `user-full-name' is required)
|
||||
+ `user-mail-address' (required)
|
||||
+ `smtpmail-smtp-user' (required for sending mail from Emacs)
|
||||
|
||||
OPTIONAL:
|
||||
+ `mu4e-sent-folder'
|
||||
+ `mu4e-drafts-folder'
|
||||
+ `mu4e-trash-folder'
|
||||
+ `mu4e-refile-folder'
|
||||
+ `mu4e-compose-signature'
|
||||
|
||||
DEFAULT-P is a boolean. If non-nil, it marks that email account as the
|
||||
default/fallback account."
|
||||
`(after! mu4e
|
||||
(let ((account-vars ,letvars))
|
||||
(when-let (address (cdr (assq 'user-mail-address account-vars)))
|
||||
(cl-pushnew address mu4e-user-mail-address-list :test #'equal))
|
||||
(let ((context (make-mu4e-context
|
||||
:name ,label
|
||||
:enter-func (lambda () (mu4e-message "Switched to %s" ,label))
|
||||
|
@ -33,10 +40,11 @@
|
|||
:match-func
|
||||
(lambda (msg)
|
||||
(when msg
|
||||
(string-prefix-p (format "/%s" ,label) (mu4e-message-field msg :maildir))))
|
||||
:vars ',letvars)))
|
||||
(string-prefix-p (format "/%s" ,label)
|
||||
(mu4e-message-field msg :maildir))))
|
||||
:vars ,letvars)))
|
||||
(push context mu4e-contexts)
|
||||
,(when default
|
||||
,(when default-p
|
||||
`(setq-default mu4e-context-current context))))))
|
||||
|
||||
|
||||
|
|
|
@ -15,9 +15,6 @@
|
|||
(defvar +irc-notifications-watch-strings nil
|
||||
"TODO")
|
||||
|
||||
(defvar +irc-connections nil
|
||||
"A list of connections set with :irc. W")
|
||||
|
||||
(defvar +irc-defer-notifications nil
|
||||
"How long to defer enabling notifications, in seconds (e.g. 5min = 300).
|
||||
Useful for ZNC users who want to avoid the deluge of notifications during buffer
|
||||
|
@ -25,8 +22,9 @@ playback.")
|
|||
|
||||
(def-setting! :irc (server letvars)
|
||||
"Registers an irc server for circe."
|
||||
`(cl-pushnew (cons ,server ,letvars) +irc-connections
|
||||
:test #'equal :key #'car))
|
||||
`(after! circe
|
||||
(cl-pushnew (cons ,server ,letvars) circe-network-options
|
||||
:test #'equal :key #'car)))
|
||||
|
||||
(defvar +irc--defer-timer nil)
|
||||
|
||||
|
@ -39,10 +37,6 @@ playback.")
|
|||
:commands (circe circe-server-buffers)
|
||||
:init (setq circe-network-defaults nil)
|
||||
:config
|
||||
;; change hands
|
||||
(setq circe-network-options +irc-connections)
|
||||
(defvaralias '+irc-connections 'circe-network-options)
|
||||
|
||||
(defsubst +irc--pad (left right)
|
||||
(format (format "%%%ds | %%s" +irc-left-padding)
|
||||
(concat "*** " left) right))
|
||||
|
|
|
@ -2,17 +2,15 @@
|
|||
|
||||
(def-setting! :company-backend (modes backends)
|
||||
"Register company BACKENDS to MODES."
|
||||
(let* ((modes (if (listp modes) modes (list modes)))
|
||||
(backends (if (listp backends) backends (list backends)))
|
||||
(let* ((modes (doom-enlist (doom-unquote modes)))
|
||||
(backends (doom-enlist (doom-unquote backends)))
|
||||
(def-name (intern (format "doom--init-company-%s"
|
||||
(mapconcat #'identity (mapcar #'symbol-name modes) "-")))))
|
||||
;; TODO more type checks
|
||||
(mapconcat #'symbol-name modes "-")))))
|
||||
`(prog1
|
||||
(defun ,def-name ()
|
||||
(when (memq major-mode ',modes)
|
||||
(when (memq major-mode ,modes)
|
||||
(require 'company)
|
||||
(unless (member ',backends company-backends)
|
||||
(setq-local company-backends (append '((,@backends)) company-backends)))))
|
||||
(cl-pushnew ,backends company-backends :test #'equal)))
|
||||
(add-hook! ,modes #',def-name))))
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))))
|
||||
|
||||
|
||||
;;
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -22,15 +22,15 @@
|
|||
"Declare :words (list of strings) or :chars (lists of chars) in MODES that
|
||||
trigger electric indentation."
|
||||
(declare (indent 1))
|
||||
(let ((modes (if (listp modes) modes (list modes)))
|
||||
(chars (plist-get plist :chars))
|
||||
(words (plist-get plist :words)))
|
||||
(let ((modes (doom-enlist (doom-unquote modes)))
|
||||
(chars (doom-unquote (plist-get plist :chars)))
|
||||
(words (doom-unquote (plist-get plist :words))))
|
||||
(when (or chars words)
|
||||
(let ((fn-name (intern (format "doom--electric-%s" (string-join (mapcar #'symbol-name modes) "-")))))
|
||||
(let ((fn-name (intern (format "doom--init-electric-%s" (mapconcat #'symbol-name modes "-")))))
|
||||
`(progn
|
||||
(defun ,fn-name ()
|
||||
(electric-indent-local-mode +1)
|
||||
,(if chars `(setq electric-indent-chars ',chars))
|
||||
,(if words `(setq doom-electric-indent-words ',words)))
|
||||
,@(if chars `((setq electric-indent-chars ',chars)))
|
||||
,@(if words `((setq doom-electric-indent-words ',words))))
|
||||
(add-hook! ,modes #',fn-name))))))
|
||||
|
||||
|
|
|
@ -9,17 +9,13 @@
|
|||
(def-setting! :rotate (modes &rest plist)
|
||||
"Declare :symbols, :words or :patterns that `rotate-text' will cycle through."
|
||||
(declare (indent 1))
|
||||
(let ((modes (if (listp modes) modes (list modes)))
|
||||
(symbols (plist-get plist :symbols))
|
||||
(words (plist-get plist :words))
|
||||
(patterns (plist-get plist :patterns)))
|
||||
(when (or symbols words patterns)
|
||||
(let ((fn-name (intern (format "doom--rotate-%s" (string-join (mapcar #'symbol-name modes) "-")))))
|
||||
`(progn
|
||||
(defun ,fn-name ()
|
||||
(require 'rotate-text)
|
||||
,(if symbols `(setq rotate-text-local-symbols ',symbols))
|
||||
,(if words `(setq rotate-text-local-words ',words))
|
||||
,(if patterns `(setq rotate-text-local-patterns ',patterns)))
|
||||
(add-hook! ,modes #',fn-name))))))
|
||||
(let* ((modes (doom-enlist (doom-unquote modes)))
|
||||
(fn-name (intern (format "doom--rotate-%s" (mapconcat #'symbol-name modes "-")))))
|
||||
`(progn
|
||||
(defun ,fn-name ()
|
||||
(let ((plist (list ,@plist)))
|
||||
(setq rotate-text-local-symbols (plist-get plist :symbols)
|
||||
rotate-text-local-words (plist-get plist :words)
|
||||
rotate-text-local-patterns (plist-get plist :patterns))))
|
||||
(add-hook! ,modes #',fn-name))))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue