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:
Henrik Lissner 2018-06-23 16:48:58 +02:00
parent f602a1f607
commit f6dc6ac74e
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395
29 changed files with 177 additions and 146 deletions

View file

@ -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))

View file

@ -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

View file

@ -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

View file

@ -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)))

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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)