From f6dc6ac74e6361751e7111e3e7124b40b83eba87 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 23 Jun 2018 16:48:58 +0200 Subject: [PATCH] Refactor out map.el usage After some profiling, it turns out map-put and map-delete are 5-7x slower (more on Emacs 25) than delq, setf/alist-get and add-to-list for small lists (under 250 items), which is exactly how I've been using them. The only caveat is alist-get's signature is different on Emacs 25, thus a polyfill is necessary in core-lib. --- core/autoload/cache.el | 17 +++--- core/autoload/packages.el | 17 +++--- core/core-cli.el | 8 +-- core/core-lib.el | 21 ++++++-- core/core-modules.el | 24 +++++---- core/core-packages.el | 4 +- core/core-ui.el | 16 +++--- modules/app/email/+gmail.el | 23 +++++---- modules/completion/helm/config.el | 2 +- modules/completion/ivy/config.el | 24 ++++----- modules/emacs/eshell/autoload/settings.el | 3 +- modules/feature/evil/config.el | 15 +++--- modules/feature/file-templates/autoload.el | 4 +- modules/feature/lookup/autoload/devdocs.el | 2 +- modules/feature/lookup/autoload/lookup.el | 6 ++- modules/feature/workspaces/config.el | 7 ++- modules/lang/assembly/autoload.el | 2 +- modules/lang/cc/config.el | 60 +++++++++++----------- modules/lang/csharp/config.el | 3 +- modules/lang/data/config.el | 8 +-- modules/lang/erlang/config.el | 2 +- modules/lang/ess/config.el | 2 +- modules/lang/javascript/config.el | 2 +- modules/lang/latex/config.el | 23 ++++----- modules/lang/org/+babel.el | 2 +- modules/lang/org/config.el | 2 +- modules/lang/sh/config.el | 6 +-- modules/tools/editorconfig/config.el | 14 ++--- modules/ui/popup/config.el | 4 +- 29 files changed, 177 insertions(+), 146 deletions(-) diff --git a/core/autoload/cache.el b/core/autoload/cache.el index 1093bf9ce..bf1c46bd5 100644 --- a/core/autoload/cache.el +++ b/core/autoload/cache.el @@ -12,7 +12,7 @@ ;; Like persistent-soft, caches assume a 2-tier structure, where all caches are ;; namespaced by location. -(defvar doom-cache-alists () +(defvar doom-cache-alists '(t) "An alist of alists, containing lists of variables for the doom cache library to persist across Emacs sessions.") @@ -24,7 +24,7 @@ name under `pcache-directory' (by default a subdirectory under (defun doom|save-persistent-cache () "Hook to run when an Emacs session is killed. Saves all persisted variables listed in `doom-cache-alists' to files." - (dolist (alist doom-cache-alists) + (dolist (alist (butlast doom-cache-alists 1)) (cl-loop with key = (car alist) for var in (cdr alist) if (symbol-value var) @@ -54,8 +54,8 @@ Warning: this is incompatible with buffer-local variables." (dolist (var variables) (when (doom-cache-exists var location) (set var (doom-cache-get var location)))) - (map-put doom-cache-alists location - (append variables (cdr (assq location doom-cache-alists))))) + (setf (alist-get location doom-cache-alists) + (append variables (cdr (assq location doom-cache-alists))))) ;;;###autoload (defun doom-cache-desist (location &optional variables) @@ -63,10 +63,11 @@ Warning: this is incompatible with buffer-local variables." `doom-cache-alists', thus preventing them from being saved between sessions. Does not affect the actual variables themselves or their values." (if variables - (map-put doom-cache-alists location - (cl-set-difference (cdr (assq location doom-cache-alists)) - variables)) - (map-delete doom-cache-alists location))) + (setf (alist-get location doom-cache-alists) + (cl-set-difference (cdr (assq location doom-cache-alists)) + variables)) + (delq (assq location doom-cache-alists) + doom-cache-alists))) ;;;###autoload (defun doom-cache-get (key &optional location) diff --git a/core/autoload/packages.el b/core/autoload/packages.el index 21c0f8269..8e4c868b7 100644 --- a/core/autoload/packages.el +++ b/core/autoload/packages.el @@ -345,7 +345,7 @@ example; the package name can be omitted)." (package-install name)) (if (not (package-installed-p name)) (doom--delete-package-files name) - (map-put doom-packages name plist) + (setf (alist-get name alist) plist) name))) ;;;###autoload @@ -388,9 +388,10 @@ package.el as appropriate." (unless (package-installed-p name) (user-error "%s isn't installed" name)) (let ((inhibit-message (not doom-debug-mode)) + (spec (assq name quelpa-cache)) quelpa-p) - (when (assq name quelpa-cache) - (setq quelpa-cache (map-delete quelpa-cache name)) + (when spec + (setq quelpa-cache (delq spec quelpa-cache)) (quelpa-save-cache) (setq quelpa-p t)) (package-delete (cadr (assq name package-alist)) force-p) @@ -439,11 +440,11 @@ calls." "Update `quelpa-cache' upon a successful `package-delete'." (doom-initialize-packages) (let ((name (package-desc-name desc))) - (when (and (not (package-installed-p name)) - (assq name quelpa-cache)) - (setq quelpa-cache (map-delete quelpa-cache name)) - (quelpa-save-cache) - (doom--delete-package-files name)))) + (unless (package-installed-p name) + (when-let* ((spec (assq name quelpa-cache))) + (setq quelpa-cache (delq spec quelpa-cache)) + (quelpa-save-cache) + (doom--delete-package-files name))))) ;; diff --git a/core/core-cli.el b/core/core-cli.el index c57944a37..d1d59dbe2 100644 --- a/core/core-cli.el +++ b/core/core-cli.el @@ -78,10 +78,10 @@ BODY will be run when this dispatcher is called." (append (when aliases `((dolist (alias ',aliases) - (map-put doom--dispatch-alias-alist alias ',cmd)))) - `((map-put doom--dispatch-command-alist ',cmd - (list :desc ,docstring - :body (lambda (args) ,form)))))))) + (setf (alist-get alias doom--dispatch-alias-alist) ',cmd)))) + `((setf (alist-get ',cmd doom--dispatch-command-alist) + (list :desc ,docstring + :body (lambda (args) ,form)))))))) ;; diff --git a/core/core-lib.el b/core/core-lib.el index 3ea39d001..35e09fa9b 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -3,7 +3,6 @@ ;; Built in packages we use a lot of (require 'subr-x) (require 'cl-lib) -(require 'map) (eval-and-compile (unless EMACS26+ @@ -11,7 +10,23 @@ ;; if-let and when-let are deprecated in Emacs 26+ in favor of their ;; if-let* variants, so we alias them for 25 users. (defalias 'if-let* #'if-let) - (defalias 'when-let* #'when-let)))) + (defalias 'when-let* #'when-let) + + ;; `alist-get' doesn't have its 5th argument before Emacs 26 + (defun doom*alist-get (key alist &optional default remove testfn) + "Return the value associated with KEY in ALIST. +If KEY is not found in ALIST, return DEFAULT. +Use TESTFN to lookup in the alist if non-nil. Otherwise, use `assq'. + +This is a generalized variable suitable for use with `setf'. +When using it to set a value, optional argument REMOVE non-nil +means to remove KEY from ALIST if the new value is `eql' to DEFAULT." + (ignore remove) ;;Silence byte-compiler. + (let ((x (if (not testfn) + (assq key alist) + (assoc key alist testfn)))) + (if x (cdr x) default))) + (advice-add #'alist-get :override #'doom*alist-get)))) ;; @@ -402,7 +417,7 @@ The available conditions are: collect `(add-hook ',hook #',hook-name)) `((add-hook 'after-change-major-mode-hook #',hook-name)))))) (match - `(map-put doom-auto-minor-mode-alist ,match ',mode)) + `(add-to-list 'doom-auto-minor-mode-alist '(,match . ,mode))) ((user-error "Invalid `associate!' rules for mode [%s] (:modes %s :match %s :files %s :when %s)" mode modes match files when))))) diff --git a/core/core-modules.el b/core/core-modules.el index 7a9f2e0ec..c320b0216 100644 --- a/core/core-modules.el +++ b/core/core-modules.el @@ -35,8 +35,6 @@ A warning will be put out if these deprecated modules are used.") session of Dooming. Will noop if used more than once, unless FORCE-P is non-nil." (when (or force-p (not doom-init-modules-p)) - ;; Set `doom-init-modules-p' early, so `doom-pre-init-hook' won't infinitely - ;; recurse by accident if any of them need `doom-initialize-modules'. (setq doom-init-modules-p t) (when doom-private-dir (condition-case e @@ -184,7 +182,7 @@ non-nil, return paths of possible modules, activated or otherwise." ;; ;; This will load X on the first invokation of `find-file-hook' (then it will ;; remove itself from the hook/function). -(defvar doom--deferred-packages-alist ()) +(defvar doom--deferred-packages-alist '(t)) (after! use-package-core (add-to-list 'use-package-deferring-keywords :after-call nil #'eq) (setq use-package-keywords @@ -208,15 +206,19 @@ non-nil, return paths of possible modules, activated or otherwise." (if (functionp hook) (advice-remove hook #',fn) (remove-hook hook #',fn))) - (map-delete doom--deferred-packages-alist ',name) + (delq (assq ',name doom--deferred-packages-alist) + doom--deferred-packages-alist) (fmakunbound ',fn)))) - (cl-loop for hook in hooks - collect (if (functionp hook) - `(advice-add #',hook :before #',fn) - `(add-hook ',hook #',fn))) - `((map-put doom--deferred-packages-alist - ',name - '(,@hooks ,@(cdr (assq name doom--deferred-packages-alist))))) + (let (forms) + (dolist (hook hooks forms) + (push (if (functionp hook) + `(advice-add #',hook :before #',fn) + `(add-hook ',hook #',fn)) + forms))) + `((unless (assq ',name doom--deferred-packages-alist) + (push '(,name) doom--deferred-packages-alist)) + (nconc (assq ',name doom--deferred-packages-alist) + '(,@hooks))) (use-package-process-keywords name rest state)))))) diff --git a/core/core-packages.el b/core/core-packages.el index 459f7e308..e256729cb 100644 --- a/core/core-packages.el +++ b/core/core-packages.el @@ -222,8 +222,8 @@ elsewhere." doom-private-dir) (setq plist (plist-put plist :private t))) `(progn - ,(if pkg-pin `(map-put package-pinned-packages ',name ,pkg-pin)) - (map-put doom-packages ',name ',plist) + ,(if pkg-pin `(setf (alist-get ',name package-pinned-packages) ,pkg-pin)) + (setf (alist-get ',name doom-packages) ',plist) (not (memq ',name doom-disabled-packages))))) (defmacro packages! (&rest packages) diff --git a/core/core-ui.el b/core/core-ui.el index 2d8d8821d..5da96c06e 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -67,7 +67,9 @@ Also see `doom-before-switch-buffer-hook'.") enable-recursive-minibuffers nil frame-inhibit-implied-resize t ;; remove continuation arrow on right fringe - fringe-indicator-alist (map-delete fringe-indicator-alist 'continuation) + fringe-indicator-alist + (delq (assq 'continuation fringe-indicator-alist) + fringe-indicator-alist) highlight-nonselected-windows nil image-animate-loop t indicate-buffer-boundaries nil @@ -126,13 +128,13 @@ Also see `doom-before-switch-buffer-hook'.") (format "%s modeline segment" name)))) (cond ((and (symbolp (car body)) (not (cdr body))) - (map-put doom--modeline-var-alist name (car body)) - `(map-put doom--modeline-var-alist ',name ',(car body))) + (add-to-list 'doom--modeline-var-alist (cons name (car body))) + `(add-to-list 'doom--modeline-var-alist (cons ',name ',(car body)))) (t - (map-put doom--modeline-fn-alist name sym) + (add-to-list 'doom--modeline-fn-alist (cons name sym)) `(progn (fset ',sym (lambda () ,docstring ,@body)) - (map-put doom--modeline-fn-alist ',name ',sym) + (add-to-list 'doom--modeline-fn-alist (cons ',name ',sym)) ,(unless (bound-and-true-p byte-compile-current-file) `(let (byte-compile-warnings) (byte-compile #',sym)))))))) @@ -549,7 +551,7 @@ frame's window-system, the theme will be reloaded.") (custom-set-faces (when (fontp doom-font) (let ((xlfd (font-xlfd-name doom-font))) - (map-put default-frame-alist 'font xlfd) + (add-to-list 'default-frame-alist (cons 'font xlfd)) `(fixed-pitch ((t (:font ,xlfd)))))) (when (fontp doom-variable-pitch-font) `(variable-pitch ((t (:font ,(font-xlfd-name doom-variable-pitch-font)))))) @@ -712,7 +714,7 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original (defun doom|init-ui () "Initialize Doom's user interface by applying all its advice and hooks." ;; Make `next-buffer', `other-buffer', etc. ignore unreal buffers. - (map-put default-frame-alist 'buffer-predicate #'doom-buffer-frame-predicate) + (add-to-list 'default-frame-alist (cons 'buffer-predicate #'doom-buffer-frame-predicate)) ;; Switch to `doom-fallback-buffer' if on last real buffer (advice-add #'kill-this-buffer :around #'doom*switch-to-fallback-buffer-maybe) ;; Don't kill the fallback buffer diff --git a/modules/app/email/+gmail.el b/modules/app/email/+gmail.el index 9d647b206..3f44d8cd7 100644 --- a/modules/app/email/+gmail.el +++ b/modules/app/email/+gmail.el @@ -12,17 +12,18 @@ (defun +email--mark-seen (docid msg target) (mu4e~proc-move docid (mu4e~mark-check-target target) "+S-u-N")) - (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. - (map-put mu4e-marks 'refile - (list :char '("r" . "▶") :prompt "refile" - :show-target (lambda (_target) "archive") - :action #'+email--mark-seen)) + (delq (assq 'delete mu4e-marks) mu4e-marks) + (setf (alist-get 'trash mu4e-marks) + (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. + (alist-get 'refile mu4e-marks) + (list :char '("d" . "▼") + :prompt "dtrash" + :dyn-target (lambda (_target msg) (mu4e-get-trash-folder msg)) + :action #'+email--mark-seen)) ;; This hook correctly modifies gmail flags on emails when they are marked. ;; Without it, refiling (archiving), trashing, and flagging (starring) email diff --git a/modules/completion/helm/config.el b/modules/completion/helm/config.el index 19dd7b65f..e4a36f758 100644 --- a/modules/completion/helm/config.el +++ b/modules/completion/helm/config.el @@ -28,7 +28,7 @@ :config (helm-mode +1) ;; helm is too heavy for find-file-at-point - (map-put helm-completing-read-handlers-alist 'find-file-at-point nil)) + (add-to-list 'helm-completing-read-handlers-alist (cons #'find-file-at-point nil))) (def-package! helm diff --git a/modules/completion/ivy/config.el b/modules/completion/ivy/config.el index 36b7a550a..b837fc80d 100644 --- a/modules/completion/ivy/config.el +++ b/modules/completion/ivy/config.el @@ -191,21 +191,21 @@ immediately runs it on the current candidate (ending the ivy session)." (internal-border-width . 10))) ;; ... let's do it manually - (dolist (fn (list 'ivy-posframe-display-at-frame-bottom-left - 'ivy-posframe-display-at-frame-center - 'ivy-posframe-display-at-point - 'ivy-posframe-display-at-frame-bottom-window-center - 'ivy-posframe-display - 'ivy-posframe-display-at-window-bottom-left - 'ivy-posframe-display-at-window-center - '+ivy-display-at-frame-center-near-bottom)) - (map-put ivy-display-functions-props fn '(:cleanup ivy-posframe-cleanup))) - - (map-put ivy-display-functions-alist 't '+ivy-display-at-frame-center-near-bottom) + (unless (assq 'ivy-posframe-display-at-frame-bottom-left ivy-display-functions-props) + (dolist (fn (list 'ivy-posframe-display-at-frame-bottom-left + 'ivy-posframe-display-at-frame-center + 'ivy-posframe-display-at-point + 'ivy-posframe-display-at-frame-bottom-window-center + 'ivy-posframe-display + 'ivy-posframe-display-at-window-bottom-left + 'ivy-posframe-display-at-window-center + '+ivy-display-at-frame-center-near-bottom)) + (push (cons fn '(:cleanup ivy-posframe-cleanup)) ivy-display-functions-props)) + (push '(t . +ivy-display-at-frame-center-near-bottom) ivy-display-functions-props)) ;; posframe doesn't work well with async sources (dolist (fn '(swiper counsel-rg counsel-ag counsel-pt counsel-grep counsel-git-grep)) - (map-put ivy-display-functions-alist fn nil))) + (setf (alist-get fn ivy-display-functions-alist) nil))) (def-package! flx diff --git a/modules/emacs/eshell/autoload/settings.el b/modules/emacs/eshell/autoload/settings.el index 1bec69ce6..5b1ad3b2f 100644 --- a/modules/emacs/eshell/autoload/settings.el +++ b/modules/emacs/eshell/autoload/settings.el @@ -7,7 +7,8 @@ (signal 'wrong-number-of-arguments (list 'even (length aliases)))) (after! eshell (while aliases - (map-put +eshell-aliases (pop aliases) (list (pop aliases)))) + (setf (alist-get (pop aliases) +eshell-aliases nil nil #'equal) + (pop aliases))) (when (boundp 'eshell-command-aliases-list) (if +eshell--default-aliases (setq eshell-command-aliases-list diff --git a/modules/feature/evil/config.el b/modules/feature/evil/config.el index 9b187cd2b..e0dba46f5 100644 --- a/modules/feature/evil/config.el +++ b/modules/feature/evil/config.el @@ -231,12 +231,12 @@ variable for an explanation of the defaults (in comments). See (cons (format "(%s " (or (read-string "(") "")) ")")) ;; Add escaped-sequence support to embrace - (map-put (default-value 'embrace--pairs-list) - ?\\ (make-embrace-pair-struct - :key ?\\ - :read-function #'+evil--embrace-escaped - :left-regexp "\\[[{(]" - :right-regexp "\\[]})]"))) + (setf (alist-get ?\\ (default-value 'embrace--pairs-list)) + (make-embrace-pair-struct + :key ?\\ + :read-function #'+evil--embrace-escaped + :left-regexp "\\[[{(]" + :right-regexp "\\[]})]"))) (def-package! evil-escape @@ -332,8 +332,7 @@ the new algorithm is confusing, like in python or ruby." ;; Add custom commands to whitelisted commands (dolist (fn '(doom/backward-to-bol-or-indent doom/forward-to-last-non-comment-or-eol doom/backward-kill-to-bol-and-indent)) - (map-put evil-mc-custom-known-commands - fn '((:default . evil-mc-execute-default-call)))) + (add-to-list 'evil-mc-custom-known-commands `(,fn (:default . evil-mc-execute-default-call)))) ;; Activate evil-mc cursors upon switching to insert mode (defun +evil-mc|resume-cursors () (setq evil-mc-frozen nil)) diff --git a/modules/feature/file-templates/autoload.el b/modules/feature/file-templates/autoload.el index be789d92d..ce4976584 100644 --- a/modules/feature/file-templates/autoload.el +++ b/modules/feature/file-templates/autoload.el @@ -2,7 +2,9 @@ (defun +file-templates--set (pred plist) (if (null (car-safe plist)) - (setq +file-templates-alist (map-delete +file-templates-alist pred)) + (setq +file-templates-alist + (delq (assoc pred +file-templates-alist) + +file-templates-alist)) (push `(,pred ,@plist) +file-templates-alist))) ;;;###autodef diff --git a/modules/feature/lookup/autoload/devdocs.el b/modules/feature/lookup/autoload/devdocs.el index 3558b4cbd..6a046c648 100644 --- a/modules/feature/lookup/autoload/devdocs.el +++ b/modules/feature/lookup/autoload/devdocs.el @@ -9,7 +9,7 @@ DOCSET (a string). See `devdocs-alist' for the defaults. " (after! (:when (boundp 'devdocs-alist)) (dolist (mode (doom-enlist modes)) - (map-put devdocs-alist mode docset)))) + (setf (alist-get mode devdocs-alist) docset)))) ;;;###autoload (def-setting! :devdocs (modes docset) diff --git a/modules/feature/lookup/autoload/lookup.el b/modules/feature/lookup/autoload/lookup.el index b69fbcce7..da7216698 100644 --- a/modules/feature/lookup/autoload/lookup.el +++ b/modules/feature/lookup/autoload/lookup.el @@ -72,7 +72,7 @@ properties: "Search on: " (mapcar #'car +lookup-provider-url-alist) nil t))) - (map-put +lookup--last-provider key provider) + (setf (alist-get +lookup--last-provider key) provider) provider)))) (defun +lookup--symbol-or-region (&optional initial) @@ -318,7 +318,9 @@ for the provider." (user-error "The search query is empty")) (funcall +lookup-open-url-fn (format url (url-encode-url search)))) (error - (map-delete +lookup--last-provider major-mode) + (setq +lookup--last-provider + (delq (assq major-mode +lookup--last-provider) + +lookup--last-provider)) (signal (car e) (cdr e))))) ;;;###autoload diff --git a/modules/feature/workspaces/config.el b/modules/feature/workspaces/config.el index bc225158a..cc3e1e227 100644 --- a/modules/feature/workspaces/config.el +++ b/modules/feature/workspaces/config.el @@ -30,7 +30,8 @@ stored in `persp-save-dir'.") ;; particularly useful for the `+workspace/restart-emacs-then-restore' command. (defun +workspaces-restore-last-session (&rest _) (add-hook 'emacs-startup-hook #'+workspace/load-session 'append)) -(map-put command-switch-alist "--restore" #'+workspaces-restore-last-session) +(add-to-list 'command-switch-alist (cons "--restore" #'+workspaces-restore-last-session)) + ;; ;; Plugins @@ -41,7 +42,9 @@ stored in `persp-save-dir'.") :init (defun +workspaces|init () ;; Remove default buffer predicate so persp-mode can put in its own - (setq default-frame-alist (map-delete default-frame-alist 'buffer-predicate)) + (setq default-frame-alist + (delq (assq 'buffer-predicate default-frame-alist) + default-frame-alist)) (add-hook 'after-make-frame-functions #'+workspaces|init-frame) (require 'persp-mode) (unless (daemonp) diff --git a/modules/lang/assembly/autoload.el b/modules/lang/assembly/autoload.el index 38b582a66..29e8ded24 100644 --- a/modules/lang/assembly/autoload.el +++ b/modules/lang/assembly/autoload.el @@ -1,4 +1,4 @@ ;;; lang/assembly/autoload.el -*- lexical-binding: t; -*- ;;;###autoload -(map-put auto-mode-alist "\\.hax\\'" 'haxor-mode) +(add-to-list 'auto-mode-alist '("\\.hax\\'" . haxor-mode)) diff --git a/modules/lang/cc/config.el b/modules/lang/cc/config.el index e05acbec6..6c5d6d7d9 100644 --- a/modules/lang/cc/config.el +++ b/modules/lang/cc/config.el @@ -83,35 +83,37 @@ compilation database is present in the project.") +cc|fontify-constants)) ;; Custom style, based off of linux - (map-put c-style-alist "doom" - `((c-basic-offset . ,tab-width) - (c-comment-only-line-offset . 0) - (c-hanging-braces-alist (brace-list-open) - (brace-entry-open) - (substatement-open after) - (block-close . c-snug-do-while) - (arglist-cont-nonempty)) - (c-cleanup-list brace-else-brace) - (c-offsets-alist - (statement-block-intro . +) - (knr-argdecl-intro . 0) - (substatement-open . 0) - (substatement-label . 0) - (statement-cont . +) - (case-label . +) - ;; align args with open brace OR don't indent at all (if open - ;; brace is at eolp and close brace is after arg with no trailing - ;; comma) - (arglist-intro . +) - (arglist-close +cc-lineup-arglist-close 0) - ;; don't over-indent lambda blocks - (inline-open . 0) - (inlambda . 0) - ;; indent access keywords +1 level, and properties beneath them - ;; another level - (access-label . -) - (inclass +cc-c++-lineup-inclass +) - (label . 0)))) + (unless (assoc "doom" c-style-alist) + (push '("doom" + (c-basic-offset . ,tab-width) + (c-comment-only-line-offset . 0) + (c-hanging-braces-alist (brace-list-open) + (brace-entry-open) + (substatement-open after) + (block-close . c-snug-do-while) + (arglist-cont-nonempty)) + (c-cleanup-list brace-else-brace) + (c-offsets-alist + (statement-block-intro . +) + (knr-argdecl-intro . 0) + (substatement-open . 0) + (substatement-label . 0) + (statement-cont . +) + (case-label . +) + ;; align args with open brace OR don't indent at all (if open + ;; brace is at eolp and close brace is after arg with no trailing + ;; comma) + (arglist-intro . +) + (arglist-close +cc-lineup-arglist-close 0) + ;; don't over-indent lambda blocks + (inline-open . 0) + (inlambda . 0) + ;; indent access keywords +1 level, and properties beneath them + ;; another level + (access-label . -) + (inclass +cc-c++-lineup-inclass +) + (label . 0))) + c-style-alist)) ;;; Keybindings ;; Disable electric keys because it interferes with smartparens and custom diff --git a/modules/lang/csharp/config.el b/modules/lang/csharp/config.el index 760db1493..f8927b350 100644 --- a/modules/lang/csharp/config.el +++ b/modules/lang/csharp/config.el @@ -1,6 +1,7 @@ ;;; lang/csharp/config.el -*- lexical-binding: t; -*- -(map-put auto-mode-alist '"\\.shader$" 'dshader-mode) ; unity shaders +;; unity shaders +(add-to-list 'auto-mode-alist '("\\.shader$" . shader-mode)) (def-package! omnisharp diff --git a/modules/lang/data/config.el b/modules/lang/data/config.el index 9786197f2..cc3e79889 100644 --- a/modules/lang/data/config.el +++ b/modules/lang/data/config.el @@ -1,10 +1,10 @@ ;;; lang/data/config.el -*- lexical-binding: t; -*- ;; Built in plugins -(dolist (spec '(("/sxhkdrc\\'" . conf-mode) - ("\\.\\(?:hex\\|nes\\)\\'" . hexl-mode) - ("\\.plist\\'" . nxml-mode))) - (map-put auto-mode-alist (car spec) (cdr spec))) +(unless after-init-time + (push '("/sxhkdrc\\'" . conf-mode) auto-mode-alist) + (push '("\\.\\(?:hex\\|nes\\)\\'" . hexl-mode) auto-mode-alist) + (push '("\\.plist\\'" . nxml-mode) auto-mode-alist)) (after! nxml-mode (set-company-backend! 'nxml-mode '(company-nxml company-yasnippet))) diff --git a/modules/lang/erlang/config.el b/modules/lang/erlang/config.el index 933c455f4..1f4a062b8 100644 --- a/modules/lang/erlang/config.el +++ b/modules/lang/erlang/config.el @@ -5,7 +5,7 @@ "/rebar\\.config\\(?:\\.script\\)?$" ;; erlang configs "/\\(?:app\\|sys\\)\\.config$")) - (map-put auto-mode-alist regexp 'erlang-mode)) + (add-to-list 'auto-mode-alist (cons regexp 'erlang-mode))) (def-package! flycheck-rebar3 diff --git a/modules/lang/ess/config.el b/modules/lang/ess/config.el index f3e78ccc1..f3ee2b564 100644 --- a/modules/lang/ess/config.el +++ b/modules/lang/ess/config.el @@ -31,7 +31,7 @@ ("\\.[Jj][Mm][Dd]\\'" . ess-jags-mode)) :init (unless (featurep! :lang julia) - (map-put auto-mode-alist "\\.jl\'" 'ess-julia-mode)) + (add-to-list 'auto-mode-alist '("\\.jl\\'" . ess-julia-mode))) :config (add-hook 'ess-mode-hook #'doom|enable-line-numbers) (setq ess-offset-continued 'straight diff --git a/modules/lang/javascript/config.el b/modules/lang/javascript/config.el index eda3a2268..1ea7896d5 100644 --- a/modules/lang/javascript/config.el +++ b/modules/lang/javascript/config.el @@ -66,7 +66,7 @@ magic-mode-regexp-match-limit t) (progn (goto-char (match-beginning 1)) (not (sp-point-in-string-or-comment))))) - (map-put magic-mode-alist #'+javascript-jsx-file-p 'rjsx-mode) + (add-to-list 'magic-mode-alist '(+javascript-jsx-file-p . rjsx-mode)) :config (set-electric! 'rjsx-mode :chars '(?\} ?\) ?. ?>)) (add-hook! 'rjsx-mode-hook diff --git a/modules/lang/latex/config.el b/modules/lang/latex/config.el index 265529304..6030884dc 100644 --- a/modules/lang/latex/config.el +++ b/modules/lang/latex/config.el @@ -75,33 +75,30 @@ (setcar (cdr (assoc "Check" TeX-command-list)) "chktex -v6 %s") ;; Set a custom item indentation (dolist (env '("itemize" "enumerate" "description")) - (map-put LaTeX-indent-environment-list - env '(+latex/LaTeX-indent-item))) + (add-to-list 'LaTeX-indent-environment-list `(,env +latex/LaTeX-indent-item))) ;; ;; Use Okular if the user says so. (when (featurep! +okular) ;; Configure Okular as viewer. Including a bug fix ;; (https://bugs.kde.org/show_bug.cgi?id=373855) - (map-put TeX-view-program-list - "Okular" '(("okular --unique file:%o" (mode-io-correlate "#src:%n%a")))) - (map-put TeX-view-program-list 'output-pdf '("Okular"))) + (add-to-list 'TeX-view-program-list '("Okular" ("okular --unique file:%o" (mode-io-correlate "#src:%n%a")))) + (add-to-list 'TeX-view-program-selection '(output-pdf "Okular"))) ;; Or Skim (when (featurep! +skim) - (map-put TeX-view-program-list - "Skim" '("/Applications/Skim.app/Contents/SharedSupport/displayline -b -g %n %o %b")) - (map-put TeX-view-program-selection 'output-pdf '("Skim"))) + (add-to-list 'TeX-view-program-list '("Skim" "/Applications/Skim.app/Contents/SharedSupport/displayline -b -g %n %o %b")) + (add-to-list 'TeX-view-program-selection 'output-pdf '("Skim"))) ;; Or Zathura (when (featurep! +zathura) - (map-put TeX-view-program-selection 'output-pdf '("Zathura"))) + (add-to-list 'TeX-view-program-selection '(output-pdf "Zathura"))) ;; Or PDF-tools, but only if the module is also loaded (when (and (featurep! :tools pdf) (featurep! +pdf-tools)) - (map-put TeX-view-program-list "PDF Tools" '("TeX-pdf-tools-sync-view")) - (map-put TeX-view-program-selection 'output-pdf '("PDF Tools")) + (add-to-list 'TeX-view-program-list ("PDF Tools" "TeX-pdf-tools-sync-view")) + (add-to-list 'TeX-view-program-selection '(output-pdf "PDF Tools")) ;; Enable auto reverting the PDF document with PDF Tools (add-hook 'TeX-after-compilation-finished-functions #'TeX-revert-document-buffer))) @@ -124,8 +121,8 @@ :init (setq latex-preview-pane-multifile-mode 'auctex) :config - (map-put TeX-view-program-list "preview-pane" '(latex-preview-pane-mode)) - (map-put TeX-view-program-selection 'output-pdf '("preview-pane")) + (add-to-list 'TeX-view-program-list '("preview-pane" latex-preview-pane-mode)) + (add-to-list 'TeX-view-program-selection '(output-pdf "preview-pane")) (define-key! doc-view-mode-map (kbd "ESC") #'delete-window "q" #'delete-window diff --git a/modules/lang/org/+babel.el b/modules/lang/org/+babel.el index 0af4f6389..ab151c4bd 100644 --- a/modules/lang/org/+babel.el +++ b/modules/lang/org/+babel.el @@ -36,7 +36,7 @@ string). Stops at the first function to return non-nil.") (or (cdr (assq lang +org-babel-mode-alist)) lang))) nil t))) - (map-put org-babel-load-languages lang t)) + (add-to-list 'org-babel-load-languages (cons lang t))) t))) (advice-add #'org-babel-confirm-evaluate :around #'+org*babel-lazy-load-library) diff --git a/modules/lang/org/config.el b/modules/lang/org/config.el index 358728c5e..da6baa883 100644 --- a/modules/lang/org/config.el +++ b/modules/lang/org/config.el @@ -341,7 +341,7 @@ between the two." (defun +org|setup-hacks () "Getting org to behave." ;; Don't open separate windows - (map-put org-link-frame-setup 'file #'find-file) + (setf (alist-get 'file org-link-frame-setup) #'find-file) ;; Let OS decide what to do with files when opened (setq org-file-apps `(("pdf" . default) diff --git a/modules/lang/sh/config.el b/modules/lang/sh/config.el index 9e1f09dd3..2c1d7e748 100644 --- a/modules/lang/sh/config.el +++ b/modules/lang/sh/config.el @@ -22,9 +22,9 @@ (setq sh-indent-after-continuation 'always) ;; recognize function names with dashes in them - (map-put sh-imenu-generic-expression - 'sh '((nil "^\\s-*function\\s-+\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*\\(?:()\\)?" 1) - (nil "^\\s-*\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*()" 1))) + (add-to-list 'sh-imenu-generic-expression + '(sh (nil "^\\s-*function\\s-+\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*\\(?:()\\)?" 1) + (nil "^\\s-*\\([[:alpha:]_-][[:alnum:]_-]*\\)\\s-*()" 1))) ;; `sh-set-shell' is chatty about setting up indentation rules (advice-add #'sh-set-shell :around #'doom*shut-up) diff --git a/modules/tools/editorconfig/config.el b/modules/tools/editorconfig/config.el index 318ff7dc2..82d4966f0 100644 --- a/modules/tools/editorconfig/config.el +++ b/modules/tools/editorconfig/config.el @@ -21,11 +21,12 @@ :after-call (doom-before-switch-buffer after-find-file) :config ;; Register missing indent variables - (setq editorconfig-indentation-alist - (append '((mips-mode mips-tab-width) - (haxor-mode haxor-tab-width) - (nasm-mode nasm-basic-offset)) - editorconfig-indentation-alist)) + (unless (assq 'mips-mode editorconfig-indentation-alist) + (setq editorconfig-indentation-alist + (append '((mips-mode mips-tab-width) + (haxor-mode haxor-tab-width) + (nasm-mode nasm-basic-offset)) + editorconfig-indentation-alist))) (defun doom*editorconfig-smart-detection (orig-fn &rest args) "Retrieve the properties for the current file. If it doesn't have an @@ -51,7 +52,8 @@ extension, try to guess one." ;; editorconfig to ignore indentation there. I prefer dynamic indentation ;; support built into Emacs. (dolist (mode '(emacs-lisp-mode lisp-mode)) - (map-delete editorconfig-indentation-alist mode)) + (delq (assq mode editorconfig-indentation-alist) + editorconfig-indentation-alist)) ;; (editorconfig-mode +1)) diff --git a/modules/ui/popup/config.el b/modules/ui/popup/config.el index 97a38f3cc..b07ebe2b6 100644 --- a/modules/ui/popup/config.el +++ b/modules/ui/popup/config.el @@ -70,8 +70,8 @@ adjustment.") window--sides-inhibit-check nil) (+popup|cleanup-rules) (dolist (prop +popup-window-parameters) - (setq window-persistent-parameters - (map-delete window-persistent-parameters prop)))))) + (delq (assq prop window-persistent-parameters) + window-persistent-parameters))))) (define-minor-mode +popup-buffer-mode "Minor mode for individual popup windows.