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.
This commit is contained in:
parent
f602a1f607
commit
f6dc6ac74e
29 changed files with 177 additions and 146 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue