diff --git a/core/core-editor.el b/core/core-editor.el index e261c2ee3..7fbdc8eb6 100644 --- a/core/core-editor.el +++ b/core/core-editor.el @@ -1,55 +1,57 @@ ;;; core-editor.el -*- lexical-binding: t; -*- +(defvar doom-detect-indentation-excluded-modes '(fundamental-mode) + "A list of major modes in which indentation should be automatically +detected.") + (defvar-local doom-inhibit-indent-detection nil "A buffer-local flag that indicates whether `dtrt-indent' should try to detect indentation settings or not. This should be set by editorconfig if it successfully sets indent_style/indent_size.") -(defvar doom-detect-indentation-excluded-modes '(fundamental-mode) - "A list of major modes in which indentation should be automatically -detected.") -(setq-default - large-file-warning-threshold 15000000 - vc-follow-symlinks t - ;; Save clipboard contents into kill-ring before replacing them - save-interprogram-paste-before-kill t - ;; Bookmarks - bookmark-default-file (concat doom-etc-dir "bookmarks") - bookmark-save-flag t - ;; Formatting - delete-trailing-lines nil - fill-column 80 - sentence-end-double-space nil - word-wrap t - ;; Scrolling - hscroll-margin 2 - hscroll-step 1 - scroll-conservatively 1001 - scroll-margin 0 - scroll-preserve-screen-position t - mouse-wheel-scroll-amount '(5 ((shift) . 2)) - mouse-wheel-progressive-speed nil ; don't accelerate scrolling - ;; Whitespace (see `editorconfig') - indent-tabs-mode nil - require-final-newline t - tab-always-indent t - tab-width 4 - tabify-regexp "^\t* [ \t]+" ; for :retab - ;; Wrapping - truncate-lines t - truncate-partial-width-windows 50) +;; +;;; Formatting -;; Remove hscroll-margin in shells, otherwise it causes jumpiness -(setq-hook! '(eshell-mode-hook term-mode-hook) hscroll-margin 0) +;; Indentation +(setq-default tab-width 4 + tab-always-indent t + indent-tabs-mode nil + fill-column 80) -(def-advice! doom--optimize-literal-mode-for-large-files-a (buffer) - :filter-return #'find-file-noselect-1 - (with-current-buffer buffer - (when find-file-literally - (setq buffer-read-only t) - (buffer-disable-undo)) - buffer)) +;; Word wrapping +(setq-default word-wrap t + truncate-lines t + truncate-partial-width-windows nil) + +(setq sentence-end-double-space nil + delete-trailing-lines nil + require-final-newline t + tabify-regexp "^\t* [ \t]+") ; for :retab + + +;; +;;; Clipboard / kill-ring + + ;; Eliminate duplicates in the kill ring. That is, if you kill the + ;; same thing twice, you won't have to use M-y twice to get past it + ;; to older entries in the kill ring. +(setq kill-do-not-save-duplicates t) + +;; +(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)) + +;; Save clipboard contents into kill-ring before replacing them +(setq save-interprogram-paste-before-kill t) + +;; Fix the clipboard in terminal or daemon Emacs (non-GUI) +(add-hook 'tty-setup-hook + (defun doom-init-clipboard-in-tty-emacs-h () + (unless (getenv "SSH_CONNECTION") + (cond (IS-MAC + (if (require 'osx-clipboard nil t) (osx-clipboard-mode))) + ((executable-find "xclip") + (if (require 'xclip nil t) (xclip-mode))))))) ;; @@ -93,6 +95,10 @@ detected.") (doom-auto-revert-buffer-h)))))) +(after! bookmark + (setq bookmark-save-flag t)) + + (def-package! recentf ;; Keep track of recently opened files :defer-incrementally (easymenu tree-widget timer) @@ -134,6 +140,7 @@ detected.") (add-hook 'kill-emacs-hook #'recentf-cleanup) (quiet! (recentf-mode +1)))) + (def-package! savehist ;; persist variables across sessions :defer-incrementally (custom) @@ -167,6 +174,7 @@ detected.") (if buffer-file-name (ignore-errors (recenter)))) (save-place-mode +1)) + (def-package! server :when (display-graphic-p) :after-call (pre-command-hook after-find-file focus-out-hook) diff --git a/core/core-keybinds.el b/core/core-keybinds.el index 5e020685f..6daa8f245 100644 --- a/core/core-keybinds.el +++ b/core/core-keybinds.el @@ -73,10 +73,11 @@ If any hook returns non-nil, all hooks after it are ignored.") ;; ;;; General + leader/localleader keys -(require 'general) -;; Convenience aliases -(defalias 'define-key! #'general-def) -(defalias 'unmap! #'general-unbind) +(use-package general + :config + ;; Convenience aliases + (defalias 'define-key! #'general-def) + (defalias 'unmap! #'general-unbind)) ;; `map!' uses this instead of `define-leader-key!' because it consumes 20-30% ;; more startup time, so we reimplement it ourselves. @@ -216,7 +217,7 @@ localleader prefix." (?g . global)) "A list of cons cells that map a letter to a evil state symbol.") -(defun doom--keyword-to-states (keyword) +(defun doom--map-keyword-to-states (keyword) "Convert a KEYWORD into a list of evil state symbols. For example, :nvi will map to (list 'normal 'visual 'insert). See @@ -307,7 +308,9 @@ For example, :nvi will map to (list 'normal 'visual 'insert). See doom--map-forms))) (_ (condition-case _ - (doom--map-def (pop rest) (pop rest) (doom--keyword-to-states key) desc) + (doom--map-def (pop rest) (pop rest) + (doom--map-keyword-to-states key) + desc) (error (error "Not a valid `map!' property: %s" key))) (setq desc nil)))) diff --git a/core/core-lib.el b/core/core-lib.el index 63f9d2e9b..136194927 100644 --- a/core/core-lib.el +++ b/core/core-lib.el @@ -1,6 +1,6 @@ ;;; core-lib.el -*- lexical-binding: t; -*- -(let ((load-path doom-site-load-path)) +(let ((load-path doom--initial-load-path)) (require 'subr-x) (require 'cl-lib)) diff --git a/core/core-os.el b/core/core-os.el deleted file mode 100644 index 9ccbea8c1..000000000 --- a/core/core-os.el +++ /dev/null @@ -1,55 +0,0 @@ -;;; core-os.el -*- lexical-binding: t; -*- - -;; clipboard -(setq x-select-request-type '(UTF8_STRING COMPOUND_TEXT TEXT STRING)) - -;; fewer opts to process for systems that don't need them -(unless IS-MAC (setq command-line-ns-option-alist nil)) -(unless IS-LINUX (setq command-line-x-option-alist nil)) - -;; Fix the clipboard in terminal or daemon Emacs (non-GUI) -(defun doom-init-clipboard-in-tty-emacs-h () - (if IS-MAC - (if (require 'osx-clipboard nil t) (osx-clipboard-mode)) - (if (require 'xclip nil t) (xclip-mode)))) -(add-hook 'tty-setup-hook #'doom-init-clipboard-in-tty-emacs-h) - -;; Enable mouse in terminal Emacs -(add-hook 'tty-setup-hook #'xterm-mouse-mode) - -;; stop copying each visual state move to the clipboard: -;; https://bitbucket.org/lyro/evil/issue/336/osx-visual-state-copies-the-region-on -;; grokked from: http://stackoverflow.com/questions/15873346/elisp-rename-macro -(advice-add #'evil-visual-update-x-selection :override #'ignore) - -(cond (IS-MAC - (setq mac-command-modifier 'super - mac-option-modifier 'meta - ;; sane trackpad/mouse scroll settings - mac-redisplay-dont-reset-vscroll t - mac-mouse-wheel-smooth-scroll nil - ;; Curse Lion and its sudden but inevitable fullscreen mode! - ;; NOTE Meaningless to railwaycat's emacs-mac build - ns-use-native-fullscreen nil - ;; Visit files opened outside of Emacs in existing frame, rather - ;; than a new one - ns-pop-up-frames nil) - - ;; Syncs ns frame parameters with theme (and fixes mismatching text color - ;; in the frame title) - (when (and (or (daemonp) - (display-graphic-p)) - (require 'ns-auto-titlebar nil t)) - (add-hook 'doom-load-theme-hook #'ns-auto-titlebar-mode))) - - (IS-LINUX - (setq x-gtk-use-system-tooltips nil ; native tooltips are ugly! - x-underline-at-descent-line t)) ; draw underline lower - - (IS-WINDOWS - (setq w32-get-true-file-attributes nil) ; fix file io slowdowns - (when (display-graphic-p) - (setenv "GIT_ASKPASS" "git-gui--askpass")))) - -(provide 'core-os) -;;; core-os.el ends here diff --git a/core/core-ui.el b/core/core-ui.el index 92f52c0a7..bcbf6ea99 100644 --- a/core/core-ui.el +++ b/core/core-ui.el @@ -51,10 +51,6 @@ examples. It is recommended you don't set specify a font-size, as to inherit `doom-font's size.") -(defvar doom--prefer-theme-elc nil - "If non-nil, `load-theme' will prefer the compiled theme (unlike its default -behavior). Do not set this directly, this is let-bound in `doom-init-theme-h'.") - ;; ;;; Custom hooks @@ -152,86 +148,74 @@ read-only or not file-visiting." ;; -;;; General configuration +;;; General UX -(setq-default - ansi-color-for-comint-mode t - bidi-display-reordering nil ; disable bidirectional text for tiny performance boost - blink-matching-paren nil ; don't blink--too distracting - compilation-always-kill t ; kill compilation process before starting another - compilation-ask-about-save nil ; save all buffers on `compile' - compilation-scroll-output 'first-error - confirm-nonexistent-file-or-buffer t - confirm-kill-emacs #'doom-quit-p ; custom confirmation when killing Emacs - cursor-in-non-selected-windows nil ; hide cursors in other windows - custom-theme-directory (expand-file-name "themes/" doom-private-dir) - display-line-numbers-width 3 - echo-keystrokes 0.02 - enable-recursive-minibuffers nil - frame-inhibit-implied-resize t - frame-title-format '("%b – Doom Emacs") ; simple name in frame title - ;; remove continuation arrow on right fringe - fringe-indicator-alist - (delq (assq 'continuation fringe-indicator-alist) - fringe-indicator-alist) - highlight-nonselected-windows nil - image-animate-loop t - indicate-buffer-boundaries nil - indicate-empty-lines nil - max-mini-window-height 0.3 - mode-line-default-help-echo nil ; disable mode-line mouseovers - mouse-yank-at-point t ; middle-click paste at point, not at click - show-help-function nil ; hide :help-echo text - use-dialog-box nil ; always avoid GUI - uniquify-buffer-name-style 'forward - visible-cursor nil - x-stretch-cursor nil - ;; Favor vertical splits - split-width-threshold 160 - split-height-threshold nil - ;; `pos-tip' defaults - pos-tip-internal-border-width 6 - pos-tip-border-width 1 - ;; no beeping or blinking please - ring-bell-function #'ignore - visible-bell nil - ;; don't resize emacs in steps, it looks weird - window-resize-pixelwise t - frame-resize-pixelwise t) -;; y/n instead of yes/no -(fset #'yes-or-no-p #'y-or-n-p) -;; Truly silence startup message -(fset #'display-startup-echo-area-message #'ignore) -;; relegate tooltips to echo area only -(if (bound-and-true-p tooltip-mode) (tooltip-mode -1)) -;; enabled by default; no thanks, too distracting -(blink-cursor-mode -1) -;; Handle ansi codes in compilation buffer -(add-hook 'compilation-filter-hook #'doom|apply-ansi-color-to-compilation-buffer) -;; Make `next-buffer', `other-buffer', etc. ignore unreal buffers. -(add-to-list 'default-frame-alist '(buffer-predicate . doom-buffer-frame-predicate)) -;; Prevent the glimpse of un-styled Emacs by setting these early. -(add-to-list 'default-frame-alist '(tool-bar-lines . 0)) -(add-to-list 'default-frame-alist '(menu-bar-lines . 0)) -(add-to-list 'default-frame-alist '(vertical-scroll-bars)) -;; prompts the user for confirmation when deleting a non-empty frame -(global-set-key [remap delete-frame] #'doom/delete-frame) -;; don't resize minibuffer for large text -(setq resize-mini-windows nil) -;; Except when it's asking for input -(setq-hook! 'minibuffer-setup-hook resize-mini-windows 'grow-only) +;; Simpler confirmation prompt when killing Emacs +(setq confirm-kill-emacs #'doom-quit-p) + +(setq uniquify-buffer-name-style 'forward + ;; no beeping or blinking please + ring-bell-function #'ignore + visible-bell nil) ;; Use `show-trailing-whitespace' instead of `whitespace-mode' because it's ;; faster (implemented in C). But try to only enable it in editing buffers. (setq-default show-trailing-whitespace nil) -(add-hook! (prog-mode text-mode conf-mode) #'doom-enable-show-trailing-whitespace-h) +(add-hook! (prog-mode text-mode conf-mode) + (defun doom-enable-show-trailing-whitespace-h () + (setq show-trailing-whitespace t))) -;; The native border "consumes" a pixel of the fringe on righter-most splits, -;; `window-divider' does not. Available since Emacs 25.1. -(setq-default window-divider-default-places t - window-divider-default-bottom-width 1 - window-divider-default-right-width 1) -(add-hook 'doom-init-ui-hook #'window-divider-mode) +;; middle-click paste at point, not at click +(setq mouse-yank-at-point t) + +;; Enable mouse in terminal Emacs +(add-hook 'tty-setup-hook #'xterm-mouse-mode) + + +;; +;;; Scrolling + +(setq hscroll-margin 2 + hscroll-step 1 + scroll-conservatively 1001 + scroll-margin 0 + scroll-preserve-screen-position t + ;; mouse + mouse-wheel-scroll-amount '(5 ((shift) . 2)) + mouse-wheel-progressive-speed nil) ; don't accelerate scrolling + +;; Remove hscroll-margin in shells, otherwise it causes jumpiness +(setq-hook! '(eshell-mode-hook term-mode-hook) hscroll-margin 0) + +(when IS-MAC + ;; sane trackpad/mouse scroll settings + (setq mac-redisplay-dont-reset-vscroll t + mac-mouse-wheel-smooth-scroll nil)) + + +;; +;;; Cursor + +;; Don't blink the cursor, it's too distracting. +(blink-cursor-mode -1) + +;; Don't blink the paren matching the one at point, it's too distracting. +(setq blink-matching-paren nil) + +(setq visible-cursor nil) + +;; Don't stretch the cursor to fit wide characters, it is disorienting, +;; especially for tabs. +(setq x-stretch-cursor nil) + + +;; +;;; Buffers + +;; Make `next-buffer', `other-buffer', etc. ignore unreal buffers. +(push '(buffer-predicate . doom-buffer-frame-predicate) default-frame-alist) + +(setq confirm-nonexistent-file-or-buffer t) (def-advice! doom-switch-to-fallback-buffer-maybe-a (orig-fn) "Switch to `doom-fallback-buffer' if on last real buffer. @@ -267,9 +251,128 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original ((funcall orig-fn))))) +;; +;;; Fringes + +;; Reduce the clutter in the fringes; we'd like to reserve that space for more +;; useful information, like git-gutter and flycheck. +(setq indicate-buffer-boundaries nil + indicate-empty-lines nil) + +;; remove continuation arrow on right fringe +(delq! 'continuation fringe-indicator-alist 'assq) + + +;; +;;; Windows/frames + +;; A simple frame title +(setq frame-title-format '("%b – Doom Emacs") + icon-title-format frame-title-format) + +;; Don't resize emacs in steps, it looks weird. +(setq window-resize-pixelwise t + frame-resize-pixelwise t) + +(unless EMACS27+ ; We already do this in early-init.el + ;; Disable tool and scrollbars; Doom encourages keyboard-centric workflows, so + ;; these are just clutter (the scrollbar also impacts Emacs' performance). + (push '(menu-bar-lines . 0) default-frame-alist) + (push '(tool-bar-lines . 0) default-frame-alist) + (push '(vertical-scroll-bars) default-frame-alist)) + +;; Sets `ns-appearance' and `ns-transparent-titlebar' on GUI frames (and fixes +;; mismatching text color in the frame title) +(when IS-MAC + ;; Curse Lion and its sudden but inevitable fullscreen mode! + ;; NOTE Meaningless to railwaycat's emacs-mac build + (setq ns-use-native-fullscreen nil + ;; Visit files opened outside of Emacs in existing frame, rather than a + ;; new one + ns-pop-up-frames nil) + + (and (or (daemonp) + (display-graphic-p)) + (require 'ns-auto-titlebar nil t)) + + (add-hook 'after-make-frame-functions + (defun doom-init-menu-bar-in-gui-frames-h (frame) + "On MacOS, the menu bar isn't part of the frame. Disabling it makes MacOS +treat Emacs as a non-application window." + (when (display-graphic-p frame) + (set-frame-parameter frame 'menu-bar-lines 1))))) + +;; The native border "consumes" a pixel of the fringe on righter-most splits, +;; `window-divider' does not. Available since Emacs 25.1. +(setq window-divider-default-places t + window-divider-default-bottom-width 1 + window-divider-default-right-width 1) +(add-hook 'doom-init-ui-hook #'window-divider-mode) + +;; Prompt the user for confirmation when deleting a non-empty frame +(global-set-key [remap delete-frame] #'doom/delete-frame) + +;; always avoid GUI +(setq use-dialog-box nil) +;; Don't display floating tooltips; display their contents in the echo-area. +(if (bound-and-true-p tooltip-mode) (tooltip-mode -1)) +;; native linux tooltips are ugly +(when IS-LINUX + (setq x-gtk-use-system-tooltips nil)) + + ;; Favor vertical splits over horizontal ones +(setq split-width-threshold 160 + split-height-threshold nil) + + +;; +;;; Minibuffer + +;; Allow for minibuffer-ception. Sometimes we need another minibuffer command +;; _while_ we're in the minibuffer. +(setq enable-recursive-minibuffers t) + +;; Show current key-sequence in minibuffer, like vim does. Any feedback after +;; typing is better UX than no feedback at all. +(setq echo-keystrokes 0.02) + +;; Expand the minibuffer to fit multi-line text displayed in the echo-area. This +;; doesn't look too great with direnv, however... +(setq resize-mini-windows 'grow-only + ;; But don't let the minibuffer grow beyond this size + max-mini-window-height 0.15) + +;; Disable help mouse-overs for mode-line segments (i.e. :help-echo text). +;; They're generally unhelpful and only add confusing visual clutter. +(setq mode-line-default-help-echo nil + show-help-function nil) + +;; y/n is easier to type than yes/no +(fset #'yes-or-no-p #'y-or-n-p) + +;; Try really hard to keep the cursor from getting stuck in the read-only prompt +;; portion of the minibuffer. +(setq minibuffer-prompt-properties '(read-only t intangible t cursor-intangible t face minibuffer-prompt)) +(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode) + + ;; ;;; Built-in packages +;;;###package ansi-color +(setq ansi-color-for-comint-mode t) + + +(def-package! compile + :defer t + :config + (setq compilation-always-kill t ; kill compilation process before starting another + compilation-ask-about-save nil ; save all buffers on `compile' + compilation-scroll-output 'first-error) + ;; Handle ansi codes in compilation buffer + (add-hook 'compilation-filter-hook #'doom-apply-ansi-color-to-compilation-buffer-h)) + + (def-package! ediff :defer t :init @@ -293,8 +396,8 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original ;; Highlights the current line :hook ((prog-mode text-mode conf-mode) . hl-line-mode) :config - ;; PERF Not having to render the hl-line overlay in multiple buffers offers a - ;; tiny performance boost. I also don't need to see it in other buffers. + ;; Not having to render the hl-line overlay in multiple buffers offers a tiny + ;; performance boost. I also don't need to see it in other buffers. (setq hl-line-sticky-flag nil global-hl-line-sticky-flag nil) @@ -340,11 +443,6 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original (newline-mark ?\n [?¬ ?\n]) (space-mark ?\ [?·] [?.]))) -;; Disable these because whitespace should be customized programmatically -;; (through `whitespace-style'), and not through these commands. -(put 'whitespace-toggle-options 'disabled t) -(put 'global-whitespace-toggle-options 'disabled t) - ;; ;;; Third party packages @@ -356,8 +454,8 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original (def-advice! doom--disable-all-the-icons-in-tty-a (orig-fn &rest args) "all-the-icons doesn't work in the terminal, so we \"disable\" them." :around '(all-the-icons-octicon all-the-icons-material - all-the-icons-faicon all-the-icons-fileicon - all-the-icons-wicon all-the-icons-alltheicon) + all-the-icons-faicon all-the-icons-fileicon + all-the-icons-wicon all-the-icons-alltheicon) (if (display-graphic-p) (apply orig-fn args) ""))) @@ -371,15 +469,24 @@ windows, switch to `doom-fallback-buffer'. Otherwise, delegate to original :hook ((prog-mode conf-mode) . highlight-numbers-mode) :config (setq highlight-numbers-generic-regexp "\\_<[[:digit:]]+\\(?:\\.[0-9]*\\)?\\_>")) +;;;###package image +(setq image-animate-loop t) + ;;;###package rainbow-delimiters ;; Helps us distinguish stacked delimiter pairs, especially in parentheses-drunk ;; languages like Lisp. (setq rainbow-delimiters-max-face-count 3) +;;;###package pos-tip +(setq pos-tip-internal-border-width 6 + pos-tip-border-width 1) + ;; ;;; Line numbers +(setq-default display-line-numbers-width 3) + ;; line numbers in most modes (add-hook! '(prog-mode-hook text-mode-hook conf-mode-hook) #'display-line-numbers-mode) @@ -431,7 +538,7 @@ character that looks like a space that `whitespace-mode' won't affect.") (setq nlinum-format-function #'doom-nlinum-format-fn) (add-hook 'nlinum-mode-hook - (defun doom--init-nlinum-width-h () + (defun doom-init-nlinum-width-h () "Calculate line number column width beforehand (optimization)." (setq nlinum--width (length (save-excursion (goto-char (point-max)) @@ -464,6 +571,13 @@ character that looks like a space that `whitespace-mode' won't affect.") ;; ;;; Theme & font +;; Underline looks a bit better when drawn lower +(setq x-underline-at-descent-line t) + +(defvar doom--prefer-theme-elc nil + "If non-nil, `load-theme' will prefer the compiled theme (unlike its default +behavior). Do not set this directly, this is let-bound in `doom-init-theme-h'.") + (defun doom-init-fonts-h () "Loads fonts. @@ -575,10 +689,6 @@ it to fix all that visual noise." (funcall orig-fn))) (add-function :around whitespace-enable-predicate #'doom-disable-whitespace-mode-in-childframes-a)) -;; Don't allow cursor to enter the prompt -(setq minibuffer-prompt-properties '(read-only t intangible t cursor-intangible t face minibuffer-prompt)) -(add-hook 'minibuffer-setup-hook #'cursor-intangible-mode) - ;; Don't display messages in the minibuffer when using the minibuffer (defmacro doom-silence-motion-key (command key) (let ((key-command (intern (format "doom/silent-%s" command)))) diff --git a/core/core.el b/core/core.el index 4a80620d8..b5238d23b 100644 --- a/core/core.el +++ b/core/core.el @@ -114,106 +114,160 @@ users).") ;; ;;; Emacs core configuration +;; Reduce debug output, well, unless we've asked for it. +(setq debug-on-error doom-debug-mode + jka-compr-verbose doom-debug-mode) + ;; UTF-8 as the default coding system (when (fboundp 'set-charset-priority) - (set-charset-priority 'unicode)) ; pretty -(prefer-coding-system 'utf-8) ; pretty -(setq locale-coding-system 'utf-8) ; please + (set-charset-priority 'unicode)) ; pretty +(prefer-coding-system 'utf-8) ; pretty +(setq locale-coding-system 'utf-8) ; please +;; Except for the clipboard on Windows, where its contents could be in an +;; encoding that's wider than utf-8, so we let Emacs/the OS decide what encoding +;; to use. (unless IS-WINDOWS - (setq selection-coding-system 'utf-8)) ; with sugar on top + (setq selection-coding-system 'utf-8)) ; with sugar on top -(setq-default - ad-redefinition-action 'accept ; silence redefined function warnings - apropos-do-all t ; make `apropos' more useful - auto-mode-case-fold nil - autoload-compute-prefixes nil - debug-on-error doom-debug-mode - jka-compr-verbose doom-debug-mode ; silence compression messages - ffap-machine-p-known 'reject ; don't ping things that look like domain names - find-file-visit-truename t ; resolve symlinks when opening files - idle-update-delay 1 ; update ui slightly less often - ;; be quiet at startup; don't load or display anything unnecessary - inhibit-startup-message t - inhibit-startup-echo-area-message user-login-name - inhibit-default-init t - initial-major-mode 'fundamental-mode - initial-scratch-message nil - ;; History & backup settings (save nothing, that's what git is for) - auto-save-default nil - create-lockfiles nil - history-length 500 - make-backup-files nil ; don't create backup~ files - ;; byte compilation - byte-compile-verbose doom-debug-mode - byte-compile-warnings '(not free-vars unresolved noruntime lexical make-local) - ;; security - gnutls-verify-error (not (getenv "INSECURE")) ; you shouldn't use this - tls-checktrust gnutls-verify-error - tls-program (list "gnutls-cli --x509cafile %t -p %p %h" - ;; compatibility fallbacks - "gnutls-cli -p %p %h" - "openssl s_client -connect %h:%p -no_ssl2 -no_ssl3 -ign_eof") - ;; Don't store authinfo in plain text! - auth-sources (list (expand-file-name "authinfo.gpg" doom-etc-dir) - "~/.authinfo.gpg") - ;; Don't litter `doom-emacs-dir' - abbrev-file-name (concat doom-local-dir "abbrev.el") - async-byte-compile-log-file (concat doom-etc-dir "async-bytecomp.log") - auto-save-list-file-name (concat doom-cache-dir "autosave") - backup-directory-alist (list (cons "." (concat doom-cache-dir "backup/"))) - custom-file (concat doom-private-dir "init.el") - desktop-dirname (concat doom-etc-dir "desktop") - desktop-base-file-name "autosave" - desktop-base-lock-name "autosave-lock" - pcache-directory (concat doom-cache-dir "pcache/") - request-storage-directory (concat doom-cache-dir "request") - server-auth-dir (concat doom-cache-dir "server/") - shared-game-score-directory (concat doom-etc-dir "shared-game-score/") - tramp-auto-save-directory (concat doom-cache-dir "tramp-auto-save/") - tramp-backup-directory-alist backup-directory-alist - tramp-persistency-file-name (concat doom-cache-dir "tramp-persistency.el") - url-cache-directory (concat doom-cache-dir "url/") - url-configuration-directory (concat doom-etc-dir "url/") - gamegrid-user-score-file-directory (concat doom-etc-dir "games/")) +;; Disable warnings from legacy advice system. They aren't useful, and we can't +;; often do anything about them besides changing packages upstream +(setq ad-redefinition-action 'accept) -(defun doom*symbol-file (orig-fn symbol &optional type) - "If a `doom-file' symbol property exists on SYMBOL, use that instead of the -original value of `symbol-file'." - (or (if (symbolp symbol) (get symbol 'doom-file)) - (funcall orig-fn symbol type))) -(advice-add #'symbol-file :around #'doom*symbol-file) +;; Make apropos omnipotent. It's more useful this way. +(setq apropos-do-all t) + +;; Don't make a second case-insensitive pass over `auto-mode-alist'. If it has +;; to, it's our (the user's) failure. One case for all! +(setq auto-mode-case-fold nil) + +;; Enable all disabled commands. +(setq disabled-command-function nil) + +;; Display the bare minimum at startup. We don't need all that noise. The +;; dashboard/empty scratch buffer is good enough. +(setq inhibit-startup-message t + inhibit-startup-echo-area-message user-login-name + inhibit-default-init t + initial-major-mode 'fundamental-mode + initial-scratch-message nil) +(fset #'display-startup-echo-area-message #'ignore) + +;; Emacs "updates" its ui more often than it needs to, so we slow it down +;; slightly, from 0.5s: +(setq idle-update-delay 1) + +;; Don't autosave files or create lock/history/backup files. The +;; editor doesn't need to hold our hands so much. We'll rely on git +;; and our own good fortune instead. Fingers crossed! +(setq auto-save-default nil + create-lockfiles nil + make-backup-files nil + ;; But have a place to store them in case we do use them... + auto-save-list-file-name (concat doom-cache-dir "autosave") + backup-directory-alist `(("." . ,(concat doom-cache-dir "backup/")))) + +;; Emacs is a huge security vulnerability, what with all the dependencies it +;; pulls in from all corners of the globe. Let's at least try to be more +;; discerning. +(setq gnutls-verify-error (not (getenv "INSECURE")) + tls-checktrust gnutls-verify-error + tls-program '("gnutls-cli --x509cafile %t -p %p %h" + ;; compatibility fallbacks + "gnutls-cli -p %p %h" + "openssl s_client -connect %h:%p -no_ssl2 -no_ssl3 -ign_eof")) + +;; Emacs stores authinfo in HOME and in plaintext. Let's not do that, mkay? This +;; file usually stores usernames, passwords, and other such treasures for the +;; aspiring malicious third party. +(setq auth-sources (list (expand-file-name "authinfo.gpg" doom-etc-dir) + "~/.authinfo.gpg")) -;; -;;; Minor mode version of `auto-mode-alist' +;; Resolve symlinks when opening files, so that any operations are conducted +;; from the file's true directory (like `find-file'). +(setq find-file-visit-truename t) -(defvar doom-auto-minor-mode-alist '() - "Alist mapping filename patterns to corresponding minor mode functions, like -`auto-mode-alist'. All elements of this alist are checked, meaning you can -enable multiple minor modes for the same regexp.") +;; Disable the warning "X and Y are the same file". It's fine to ignore this +;; warning as it will redirect you to the existing buffer anyway. +(setq find-file-suppress-same-file-warnings t) -(defun doom-enable-minor-mode-maybe-h () - "Check file name against `doom-auto-minor-mode-alist'." - (when (and buffer-file-name doom-auto-minor-mode-alist) - (let ((name buffer-file-name) - (remote-id (file-remote-p buffer-file-name)) - (alist doom-auto-minor-mode-alist)) - ;; Remove backup-suffixes from file name. - (setq name (file-name-sans-versions name)) - ;; Remove remote file name identification. - (when (and (stringp remote-id) - (string-match (regexp-quote remote-id) name)) - (setq name (substring name (match-end 0)))) - (while (and alist (caar alist) (cdar alist)) - (if (string-match-p (caar alist) name) - (funcall (cdar alist) 1)) - (setq alist (cdr alist)))))) -(add-hook 'find-file-hook #'doom-enable-minor-mode-maybe-h) +;; Create missing directories when we open a file that doesn't exist under a +;; directory tree that may not exist. +(add-hook 'find-file-not-found-functions + (defun doom-create-missing-directories-h () + "Automatically create missing directories when creating new files." + (let ((parent-directory (file-name-directory buffer-file-name))) + (when (and (not (file-exists-p parent-directory)) + (y-or-n-p (format "Directory `%s' does not exist! Create it?" parent-directory))) + (make-directory parent-directory t))))) + +;; Emacs on Windows frequently confuses HOME (C:\Users\) and APPDATA, +;; causing `abbreviate-home-dir' to produce incorrect paths. +(when IS-WINDOWS + (setq abbreviated-home-dir "\\`'")) + +;; Don't litter `doom-emacs-dir' +(setq abbrev-file-name (concat doom-local-dir "abbrev.el") + async-byte-compile-log-file (concat doom-etc-dir "async-bytecomp.log") + bookmark-default-file (concat doom-etc-dir "bookmarks") + custom-file (concat doom-private-dir "init.el") + custom-theme-directory (concat doom-private-dir "themes/") + desktop-dirname (concat doom-etc-dir "desktop") + desktop-base-file-name "autosave" + desktop-base-lock-name "autosave-lock" + pcache-directory (concat doom-cache-dir "pcache/") + request-storage-directory (concat doom-cache-dir "request") + server-auth-dir (concat doom-cache-dir "server/") + shared-game-score-directory (concat doom-etc-dir "shared-game-score/") + tramp-auto-save-directory (concat doom-cache-dir "tramp-auto-save/") + tramp-backup-directory-alist backup-directory-alist + tramp-persistency-file-name (concat doom-cache-dir "tramp-persistency.el") + url-cache-directory (concat doom-cache-dir "url/") + url-configuration-directory (concat doom-etc-dir "url/") + gamegrid-user-score-file-directory (concat doom-etc-dir "games/")) ;; ;;; Optimizations +;; Disable bidirectional text rendering for a modest performance boost. Of +;; course, this renders Emacs unable to detect/display right-to-left languages +;; (sorry!), but for us left-to-right language speakers/writers, it's a boon. +(setq-default bidi-display-reordering 'left-to-right) + +;; Reduce rendering/line scan work for Emacs by not rendering cursors or regions +;; in non-focused windows. +(setq-default cursor-in-non-selected-windows nil) +(setq highlight-nonselected-windows nil) + +;; More performant rapid scrolling over unfontified regions. May cause brief +;; spells of inaccurate fontification immediately after scrolling. +(setq fast-but-imprecise-scrolling t) + +;; Resizing the Emacs frame can be a terribly expensive part of changing the +;; font. By inhibiting this, we easily halve startup times with fonts that are +;; larger than the system default. +(setq frame-inhibit-implied-resize t) + +;; Don't ping things that look like domain names. +(setq ffap-machine-p-known 'reject) + +;; Performance on Windows is considerably worse than elsewhere. We'll need +;; everything we can get. +(when IS-WINDOWS + ;; Reduce the workload when doing file IO + (setq w32-get-true-file-attributes nil) + + ;; Font compacting can be terribly expensive, especially for rendering icon + ;; fonts on Windows. Whether it has a noteable affect on Linux and Mac hasn't + ;; been determined. + (setq inhibit-compacting-font-caches t)) + +;; Remove command line options that aren't relevant to our current OS; that +;; means less to process at startup. +(unless IS-MAC (setq command-line-ns-option-alist nil)) +(unless IS-LINUX (setq command-line-x-option-alist nil)) + ;; This is consulted on every `require', `load' and various path/io functions. ;; You get a minor speed up by nooping this. (setq file-name-handler-alist nil) @@ -293,14 +347,6 @@ enable multiple minor modes for the same regexp.") (doom-run-local-var-hooks-h))) 'append) -(add-hook 'find-file-not-found-functions - (defun doom-create-missing-directories-h () - "Automatically create missing directories when creating new files." - (let ((parent-directory (file-name-directory buffer-file-name))) - (when (and (not (file-exists-p parent-directory)) - (y-or-n-p (format "Directory `%s' does not exist! Create it?" parent-directory))) - (make-directory parent-directory t))))) - ;; ;;; Incremental lazy-loading diff --git a/core/packages.el b/core/packages.el index 4e1f28a17..b859d15aa 100644 --- a/core/packages.el +++ b/core/packages.el @@ -4,12 +4,6 @@ ;; core.el (package! dotenv-mode) -;; core-os.el -(if (not IS-MAC) - (package! xclip) - (package! osx-clipboard) - (package! ns-auto-titlebar)) - ;; core-ui.el (package! all-the-icons) (package! hide-mode-line) @@ -26,10 +20,13 @@ (package! command-log-mode) (package! dtrt-indent) (package! helpful) +(package! ns-auto-titlebar :ignore (not IS-MAC)) (package! pcre2el) (package! smartparens) +(package! osx-clipboard :ignore (not IS-MAC)) (package! undo-tree) (package! ws-butler) +(package! xclip :ignore IS-LINUX) ;; core-projects.el (package! projectile) diff --git a/modules/editor/evil/config.el b/modules/editor/evil/config.el index 44bd54264..35a3a3f20 100644 --- a/modules/editor/evil/config.el +++ b/modules/editor/evil/config.el @@ -49,6 +49,12 @@ directives. By default, this only recognizes C directives.") (put 'evil-define-key* 'lisp-indent-function 'defun) + ;; stop copying each visual state move to the clipboard: + ;; https://bitbucket.org/lyro/evil/issue/336/osx-visual-state-copies-the-region-on + ;; grokked from: + ;; http://stackoverflow.com/questions/15873346/elisp-rename-macro + (advice-add #'evil-visual-update-x-selection :override #'ignore) + ;; Start help-with-tutorial in emacs state (advice-add #'help-with-tutorial :after (lambda (&rest _) (evil-emacs-state +1))) diff --git a/modules/emacs/vc/config.el b/modules/emacs/vc/config.el index 36fa5ea3b..c5213c16d 100644 --- a/modules/emacs/vc/config.el +++ b/modules/emacs/vc/config.el @@ -1,6 +1,11 @@ ;;; emacs/vc/config.el -*- lexical-binding: t; -*- -(setq vc-make-backup-files nil) +(when IS-WINDOWS + (setenv "GIT_ASKPASS" "git-gui--askpass")) + + +(setq vc-make-backup-files nil + vc-follow-symlinks t) (after! git-timemachine