From f5c1332a31a66335aa16b8a5d1bc432036fd6561 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sat, 9 Oct 2021 19:55:47 +0200 Subject: [PATCH] refactor: minor refactors & nit picks across core --- core/core-cli.el | 17 ++++++++++------- core/core-keybinds.el | 4 ++-- core/core-lib.el | 6 ++++-- core/core-packages.el | 28 +++++++++++++--------------- core/core-projects.el | 14 ++++++-------- core/core-ui.el | 15 ++++++--------- 6 files changed, 41 insertions(+), 43 deletions(-) diff --git a/core/core-cli.el b/core/core-cli.el index 05a26b13b..2ebd05ed6 100644 --- a/core/core-cli.el +++ b/core/core-cli.el @@ -65,13 +65,6 @@ purpose.") (require 'core-packages) (doom-initialize-core-packages) -;; Don't generate superfluous files when writing temp buffers -(setq make-backup-files nil) -;; Stop user configuration from interfering with package management -(setq enable-dir-local-variables nil) -;; Reduce ambiguity, embrace specificity. It's more predictable. -(setq-default case-fold-search nil) - ;; Default to using all cores, rather than half of them, since we compile things ;; ahead-of-time in a non-interactive session. (defadvice! doom--comp-use-all-cores-a (&rest _) @@ -249,5 +242,15 @@ best to run Doom out of ~/.emacs.d and ~/.doom.d." (maphash (doom-module-loader doom-cli-file) doom-modules) (load! doom-cli-file doom-private-dir t) + +;; Don't generate superfluous files when writing temp buffers +(setq make-backup-files nil) +;; Stop user configuration from interfering with package management +(setq enable-dir-local-variables nil) +;; Reduce ambiguity, embrace specificity. It's more predictable. +(setq-default case-fold-search nil) +;; Don't clog the user's trash with anything we clean up in this session. +(setq delete-by-moving-to-trash nil) + (provide 'core-cli) ;;; core-cli.el ends here diff --git a/core/core-keybinds.el b/core/core-keybinds.el index f7f326cb4..c29228b66 100644 --- a/core/core-keybinds.el +++ b/core/core-keybinds.el @@ -221,10 +221,10 @@ localleader prefix." which-key-min-display-lines 6 which-key-side-window-slot -10) :config - (defvar doom--initial-which-key-replacement-alist which-key-replacement-alist) + (put 'which-key-replacement-alist 'initial-value which-key-replacement-alist) (add-hook! 'doom-before-reload-hook (defun doom-reset-which-key-replacements-h () - (setq which-key-replacement-alist doom--initial-which-key-replacement-alist))) + (setq which-key-replacement-alist (get 'which-key-replacement-alist 'initial-value)))) ;; general improvements to which-key readability (which-key-setup-side-window-bottom) (setq-hook! 'which-key-init-buffer-hook line-spacing 3) diff --git a/core/core-lib.el b/core/core-lib.el index 4bc25c25d..c9f39e767 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -564,7 +564,6 @@ reverse this and trigger `after!' blocks at a more reasonable time." ;;; Hooks -(defvar doom--transient-counter 0) (defmacro add-transient-hook! (hook-or-function &rest forms) "Attaches a self-removing function to HOOK-OR-FUNCTION. @@ -577,7 +576,10 @@ advised)." (let ((append (if (eq (car forms) :after) (pop forms))) ;; Avoid `make-symbol' and `gensym' here because an interned symbol is ;; easier to debug in backtraces (and is visible to `describe-function') - (fn (intern (format "doom--transient-%d-h" (cl-incf doom--transient-counter))))) + (fn (intern (format "doom--transient-%d-h" + (put 'add-transient-hook! 'counter + (1+ (or (get 'add-transient-hook! 'counter) + 0))))))) `(let ((sym ,hook-or-function)) (defun ,fn (&rest _) ,(format "Transient hook for %S" (doom-unquote hook-or-function)) diff --git a/core/core-packages.el b/core/core-packages.el index c0b6f1a53..f1eac4f4f 100644 --- a/core/core-packages.el +++ b/core/core-packages.el @@ -53,20 +53,18 @@ uses a straight or package.el command directly).") ;;; package.el ;; Ensure that, if we do need package.el, it is configured correctly. You really -;; shouldn't be using it, but it may be convenient for quick package testing. +;; shouldn't be using it, but it may be convenient for quickly testing packages. (setq package-enable-at-startup nil package-user-dir (concat doom-local-dir "elpa/") - package-gnupghome-dir (expand-file-name "gpg" package-user-dir) - ;; I omit Marmalade because its packages are manually submitted rather - ;; than pulled, so packages are often out of date with upstream. - package-archives - (let ((proto (if gnutls-verify-error "https" "http"))) - (list (cons "gnu" (concat proto "://elpa.gnu.org/packages/")) - (cons "melpa" (concat proto "://melpa.org/packages/")) - (cons "org" (concat proto "://orgmode.org/elpa/"))))) + package-gnupghome-dir (expand-file-name "gpg" package-user-dir)) -;; package.el has no business modifying the user's init.el -(advice-add #'package--ensure-init-file :override #'ignore) +(after! package + (let ((s (if gnutls-verify-error "s" ""))) + (prependq! package-archives + ;; I omit Marmalade because its packages are manually submitted + ;; rather than pulled, and so often out of date. + `(("melpa" . ,(format "http%s://melpa.org/packages/" s)) + ("org" . ,(format "http%s://orgmode.org/elpa/" s)))))) ;; Refresh package.el the first time you call `package-install', so it can still ;; be used (e.g. to temporarily test packages). Remember to run 'doom sync' to @@ -564,10 +562,10 @@ Only use this macro in a module's (or your private) packages.el file." This unpins packages, so that 'doom upgrade' downloads their latest version. It can be used one of five ways: -+ To disable pinning wholesale: (unpin! t) -+ To unpin individual packages: (unpin! packageA packageB ...) -+ To unpin all packages in a group of modules: (unpin! :lang :tools ...) -+ To unpin packages in individual modules: +- To disable pinning wholesale: (unpin! t) +- To unpin individual packages: (unpin! packageA packageB ...) +- To unpin all packages in a group of modules: (unpin! :lang :tools ...) +- To unpin packages in individual modules: (unpin! (:lang python javascript) (:tools docker)) Or any combination of the above. diff --git a/core/core-projects.el b/core/core-projects.el index 094bb98f3..610929175 100644 --- a/core/core-projects.el +++ b/core/core-projects.el @@ -94,19 +94,17 @@ debian, and derivatives). On most it's 'fd'.") (setq compilation-buffer-name-function #'projectile-compilation-buffer-name compilation-save-buffers-predicate #'projectile-current-project-buffer-p) - ;; Override projectile's dirconfig file '.projectile' with doom's project marker '.project'. + ;; Support the more generic .project files as an alternative to .projectile (defadvice! doom--projectile-dirconfig-file-a () :override #'projectile-dirconfig-file - (cond - ;; Prefers '.projectile' to maintain compatibility with existing projects. - ((file-exists-p! (or ".projectile" ".project") (projectile-project-root))) - ((expand-file-name ".project" (projectile-project-root))))) + (cond ((file-exists-p! (or ".projectile" ".project") (projectile-project-root))) + ((expand-file-name ".project" (projectile-project-root))))) ;; Disable commands that won't work, as is, and that Doom already provides a ;; better alternative for. - (put 'projectile-ag 'disabled "Use +{ivy,helm}/project-search instead") - (put 'projectile-ripgrep 'disabled "Use +{ivy,helm}/project-search instead") - (put 'projectile-grep 'disabled "Use +{ivy,helm}/project-search instead") + (put 'projectile-ag 'disabled "Use +default/search-project instead") + (put 'projectile-ripgrep 'disabled "Use +default/search-project instead") + (put 'projectile-grep 'disabled "Use +default/search-project instead") ;; Treat current directory in dired as a "file in a project" and track it (add-hook 'dired-before-readin-hook #'projectile-track-known-projects-find-file-hook) diff --git a/core/core-ui.el b/core/core-ui.el index 96eba921b..7a3f42b98 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -302,16 +302,14 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original ;; so these are just clutter (the scrollbar also impacts performance). Whats ;; more, the menu bar exposes functionality that Doom doesn't endorse. ;; -;; I am intentionally avoid using `menu-bar-mode', `tool-bar-mode', and +;; I am intentionally not calling `menu-bar-mode', `tool-bar-mode', and ;; `scroll-bar-mode' because they do extra and unnecessary work that can be more -;; concisely, and efficiently, expressed with these six lines: +;; concisely and efficiently expressed with these six lines: (push '(menu-bar-lines . 0) default-frame-alist) (push '(tool-bar-lines . 0) default-frame-alist) (push '(vertical-scroll-bars) default-frame-alist) - -;; These are disabled directly through their frame parameters to avoid the extra -;; work their minor modes do, but their variables must be unset too, otherwise -;; users will have to cycle them twice to re-enable them. +;; And set these to nil so users don't have to toggle the modes twice to +;; reactivate them. (setq menu-bar-mode nil tool-bar-mode nil scroll-bar-mode nil) @@ -325,8 +323,7 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original ;; GUIs are inconsistent across systems and themes (and will rarely match our ;; active Emacs theme). They impose inconsistent shortcut key paradigms too. -;; It's best to avoid GUIs altogether and have Emacs handle the prompting, since -;; its promtps are governed by the same rules and keybinds as the rest of Emacs. +;; It's best to avoid them altogether and have Emacs handle the prompting. (setq use-dialog-box nil) (when (bound-and-true-p tooltip-mode) (tooltip-mode -1)) @@ -564,7 +561,7 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original ;; ;;; Theme & font -;; User themes should live in ~/.doom.d/themes, not ~/.emacs.d +;; User themes should live in $DOOMDIR/themes, not ~/.emacs.d (setq custom-theme-directory (concat doom-private-dir "themes/")) ;; Always prioritize the user's themes above the built-in/packaged ones.