General refactor (use map.el more)

+ map-delete is shorter and faster than assq-delete-all
+ map-put is simpler than the delete-then-set workflow
+ map-merge is great for merging default and user settings
This commit is contained in:
Henrik Lissner 2018-01-06 23:54:12 -05:00
parent 2eeb6ce0d9
commit 392f04446f
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
7 changed files with 27 additions and 42 deletions

View file

@ -205,7 +205,7 @@ Used by `doom//packages-install'."
(when (and (not (package-installed-p name)) (when (and (not (package-installed-p name))
(quelpa-setup-p) (quelpa-setup-p)
(assq name quelpa-cache)) (assq name quelpa-cache))
(setq quelpa-cache (assq-delete-all name quelpa-cache)) (map-delete quelpa-cache name)
(quelpa-save-cache) (quelpa-save-cache)
(let ((path (expand-file-name (symbol-name name) quelpa-build-dir))) (let ((path (expand-file-name (symbol-name name) quelpa-build-dir)))
(when (file-exists-p path) (when (file-exists-p path)
@ -304,7 +304,7 @@ package.el as appropriate."
(unless (quelpa-setup-p) (unless (quelpa-setup-p)
(error "Could not initialize QUELPA")) (error "Could not initialize QUELPA"))
(when (assq name quelpa-cache) (when (assq name quelpa-cache)
(setq quelpa-cache (assq-delete-all name quelpa-cache)) (map-delete quelpa-cache name)
(quelpa-save-cache) (quelpa-save-cache)
(setq quelpa-p t)) (setq quelpa-p t))
(package-delete (cadr (assq name package-alist)) force-p) (package-delete (cadr (assq name package-alist)) force-p)

View file

@ -146,8 +146,7 @@ extension, try to guess one."
;; editorconfig to ignore indentation. I prefer dynamic indentation support ;; editorconfig to ignore indentation. I prefer dynamic indentation support
;; built into Emacs. ;; built into Emacs.
(dolist (mode '(emacs-lisp-mode lisp-mode)) (dolist (mode '(emacs-lisp-mode lisp-mode))
(setq editorconfig-indentation-alist (map-delete editorconfig-indentation-alist mode))
(assq-delete-all mode editorconfig-indentation-alist)))
(defvar whitespace-style) (defvar whitespace-style)
(defun doom|editorconfig-whitespace-mode-maybe (&rest _) (defun doom|editorconfig-whitespace-mode-maybe (&rest _)

View file

@ -463,12 +463,8 @@ Accepts the following properties:
(when-let* ((val (plist-get plist prop))) (when-let* ((val (plist-get plist prop)))
(plist-put plist prop (eval val)))) (plist-put plist prop (eval val))))
`(progn `(progn
(when ,(and pkg-pin t) ,(if (and pkg-pin t) `(map-put package-pinned-packages ',name ,pkg-pin))
(cl-pushnew (cons ',name ,pkg-pin) package-pinned-packages (map-put doom-packages ',name ',plist))))
:test #'eq :key #'car))
(when ,(and old-plist t)
(assq-delete-all ',name doom-packages))
(push ',(cons name plist) doom-packages))))
(defmacro depends-on! (module submodule) (defmacro depends-on! (module submodule)
"Declares that this module depends on another. "Declares that this module depends on another.

View file

@ -119,25 +119,20 @@ default/fallback account."
;; However, the real magic happens in `+email|gmail-fix-flags'. ;; However, the real magic happens in `+email|gmail-fix-flags'.
;; ;;
;; Gmail will handle the rest. ;; Gmail will handle the rest.
(setq mu4e-marks (assq-delete-all 'delete mu4e-marks)) (defun +email--mark-seen (docid msg target)
(setq mu4e-marks (assq-delete-all 'trash mu4e-marks)) (mu4e~proc-move docid (mu4e~mark-check-target target) "+S-u-N"))
(push '(trash :char ("d" . "")
:prompt "dtrash"
:dyn-target (lambda (target msg) (mu4e-get-trash-folder msg))
:action
(lambda (docid msg target)
(mu4e~proc-move docid (mu4e~mark-check-target target) "+S-u-N")))
mu4e-marks)
(map-delete mu4e-marks 'delete)
(map-put mu4e-marks 'trash
(list :char '("d" . "")
:prompt "dtrash"
:dyn-target (lambda (target msg) (mu4e-get-trash-folder msg))
:action #'+email--mark-seen))
;; Refile will be my "archive" function. ;; Refile will be my "archive" function.
(setq mu4e-marks (assq-delete-all 'refile mu4e-marks)) (map-put mu4e-marks 'refile
(push '(refile :char ("r" . "") (list :char '("r" . "") :prompt "refile"
:prompt "refile"
:show-target (lambda (target) "archive") :show-target (lambda (target) "archive")
:action :action #'+email--mark-seen))
(lambda (docid msg target)
(mu4e~proc-move docid (mu4e~mark-check-target target) "+S-u-N")))
mu4e-marks)
;; This hook correctly modifies gmail flags on emails when they are marked. ;; This hook correctly modifies gmail flags on emails when they are marked.
;; Without it, refiling (archiving), trashing, and flagging (starring) email ;; Without it, refiling (archiving), trashing, and flagging (starring) email

View file

@ -14,8 +14,7 @@
"Search on: " "Search on: "
(mapcar #'car +lookup-provider-url-alist) (mapcar #'car +lookup-provider-url-alist)
nil t))) nil t)))
(push (cons key provider) (map-put +lookup--last-provider key provider)))))
(assq-delete-all key +lookup--last-provider))))))
(defun +lookup--symbol-or-region (&optional initial) (defun +lookup--symbol-or-region (&optional initial)
(cond (initial) (cond (initial)
@ -227,8 +226,7 @@ for the provider."
(user-error "The search query is empty")) (user-error "The search query is empty"))
(funcall +lookup-open-url-fn (format url (url-encode-url search)))) (funcall +lookup-open-url-fn (format url (url-encode-url search))))
('error ('error
(setq +lookup--last-provider (map-delete +lookup--last-provider major-mode))))
(assq-delete-all major-mode +lookup--last-provider)))))
;;;###autoload ;;;###autoload
(defun +lookup/online-select () (defun +lookup/online-select ()

View file

@ -76,13 +76,11 @@ and enables `+popup-buffer-mode'."
"Merge `+popup-default-alist' and `+popup-default-parameters' with ALIST." "Merge `+popup-default-alist' and `+popup-default-parameters' with ALIST."
(if (not alist) (if (not alist)
(setq alist +popup-default-alist) (setq alist +popup-default-alist)
(require 'map)
(let* ((alist (map-merge 'list +popup-default-alist alist)) (let* ((alist (map-merge 'list +popup-default-alist alist))
(params (map-merge 'list (params (map-merge 'list
+popup-default-parameters +popup-default-parameters
(cdr (assq 'window-parameters alist))))) (cdr (assq 'window-parameters alist)))))
(setq alist (assq-delete-all 'window-parameters alist)) (map-put alist 'window-parameters params)
(push (cons 'window-parameters params) alist)
(nreverse alist)))) (nreverse alist))))
@ -151,7 +149,7 @@ current buffer."
(remove-hook 'doom-escape-hook #'+popup|close-on-escape) (remove-hook 'doom-escape-hook #'+popup|close-on-escape)
(setq display-buffer-alist +popup--old-display-buffer-alist) (setq display-buffer-alist +popup--old-display-buffer-alist)
(dolist (prop +popup-window-parameters) (dolist (prop +popup-window-parameters)
(assq-delete-all prop window-persistent-parameters))))) (map-delete prop window-persistent-parameters)))))
;;;###autoload ;;;###autoload
(define-minor-mode +popup-buffer-mode (define-minor-mode +popup-buffer-mode

View file

@ -100,14 +100,13 @@ ALIST supports one custom parameter: `size', which will resolve to
`(let ((alist ,alist) `(let ((alist ,alist)
(parameters ,parameters)) (parameters ,parameters))
,(when alist ,(when alist
'(when-let* ((size (cdr (assq 'size alist)))) `(when-let* ((size (cdr (assq 'size alist)))
(setq alist (assq-delete-all 'size alist)) (side (cdr (assq 'side (append alist +popup-default-alist)))))
(push (cons (pcase (cdr (or (assq 'side alist) (map-delete alist 'size)
(assq 'side +popup-default-alist))) (map-put alist (if (memq side '(left right))
((or `left `right) 'window-width) 'window-width
(_ 'window-height)) 'window-height)
size) size)))
alist)))
(prog1 (push (append (list ,condition '(+popup-buffer)) (prog1 (push (append (list ,condition '(+popup-buffer))
alist alist
(list (cons 'window-parameters parameters))) (list (cons 'window-parameters parameters)))