From 9e46efac61fc4246b810c8b19127248ed7b3080e Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 5 Jan 2022 17:12:32 -0600 Subject: [PATCH] Lots of changes, maybe breaking something I have to do a big debugging tonight. Keybinds aren't getting picked up, idk what's going on. --- early-init.el | 15 ++++++---- init.el | 78 +++++++++++++++++++++++++------------------------ lisp/+casing.el | 47 ++++++++++++++++------------- lisp/+emacs.el | 69 +++++++++++++++++++++---------------------- lisp/+lookup.el | 16 ++++++---- lisp/acdw.el | 8 ++++- 6 files changed, 127 insertions(+), 106 deletions(-) diff --git a/early-init.el b/early-init.el index 17b3844..805bd61 100644 --- a/early-init.el +++ b/early-init.el @@ -21,13 +21,16 @@ ;;; Code: -(define-advice load (:before (feature &rest _)) - "Message the user when loading a library." - (with-temp-message (format "Now loading: '%s'" feature))) +;;(setq debug-on-error t) +(message "Loading early-init.el...") + +;; (define-advice load (:before (feature &rest _)) +;; "Message the user when loading a library." +;; (with-temp-message (format "Now loading: '%s'" feature))) ;;; Speed up init -(setq gc-cons-threshold most-positive-fixnum) +;; (setq gc-cons-threshold most-positive-fixnum) (add-hook 'emacs-startup-hook (defun emacs-startup@restore-values () @@ -41,8 +44,6 @@ ;;; Set up extra load paths and functionality (push (locate-user-emacs-file "lisp") load-path) -(add-to-list 'load-path (locate-user-emacs-file "lisp/compat") :append) - (require 'acdw) (+define-dir .etc (locate-user-emacs-file ".etc") @@ -159,5 +160,7 @@ See `no-littering' for examples.") ;; is `straight-package-neutering-mode'. (defalias 'straight-ಠ_ಠ-mode nil) +(message "Loading early-init.el...Done.") + (provide 'early-init) ;;; early-init.el ends here diff --git a/init.el b/init.el index 51bcf31..526c867 100644 --- a/init.el +++ b/init.el @@ -15,17 +15,13 @@ ;; - Make good choices. ;;; Code: - -(dolist (feature `((early-init . ,(locate-user-emacs-file "early-init")) - acdw - private)) - (require (or (car-safe feature) feature) (cdr-safe feature) :noerror)) +(let ((early-features `((early-init . ,(locate-user-emacs-file "early-init")) + acdw private +key))) + (dolist (feature early-features) + (require (or (car-safe feature) feature) (cdr-safe feature) :noerror))) (setup (:require +casing) - (:+key "M-c" +casing-map) - ;; Unbind default casing bindings - (:global "M-u" nil "M-c" nil "M-l" nil - "C-x C-u" nil "C-x C-l" nil)) + (+casing-mode +1)) (setup (:require +emacs) ;; +emacs.el contains super-basic defaults that are basically necessary for @@ -37,11 +33,8 @@ (:global "C-x C-k" #'kill-current-buffer "C-x 4 n" #'clone-buffer "C-c v" #'visible-mode - "C-M-;" #'+lisp-comment-or-uncomment-sexp) - ;; Unbind stuff, too. - (dolist (key '("C-M-j" - "M-j")) - (global-set-key (kbd key) nil)) + "C-M-;" #'+lisp-comment-or-uncomment-sexp + "M-j" nil) ;; C-h deletes backward - see https://idiomdrottning.org/bad-emacs-defaults (global-set-key (kbd "C-h") 'delete-backward-char) (keyboard-translate ?\C-h ?\C-?) @@ -55,15 +48,28 @@ (:bind "C-c s" #'+init-sort-then-save) (:hook #'+init-add-setup-to-imenu)) -(setup (:require +key) - (+ensure-after-init #'+key-global-mode)) - (setup (:require +lookup) - (:+key "C-c l" +lookup-map)) + (+lookup-mode +1)) (setup (:require auth-source) (:option auth-sources (list (private/ "authinfo")))) +(setup (:require auto-insert) + (setf (alist-get '("lisp/.*\\.el\\'" . "+Emacs lisp") + auto-insert-alist nil nil #'equal) + `(nil ";;; " (file-name-nondirectory (buffer-file-name)) + (make-string (max 2 (- fill-column (current-column) 27)) 32) + "-*- lexical-binding: t; -*-" '(setq lexical-binding t) + ,(concat "\n\n;;; Commentary:" + "\n\n;; ") _ + ,(concat "\n\n;;; Code:" + "\n\n" + "\n\n(provide '") + (file-name-base (buffer-file-name)) + ,(concat ")" "\n;;; ") + (file-name-nondirectory (buffer-file-name)) " ends here\n")) + (auto-insert-mode +1)) + (setup (:require cus-edit) ;; I don't use Custom to actually /make/ any customizations, but it's handy to ;; (A) see what options are available and (B) persist some changes across @@ -98,28 +104,15 @@ (setup (:require reading) (:global "C-c C-r" #'reading-mode)) +(setup +key + (+ensure-after-init #'+key-global-mode)) + (setup abbrev (:option abbrev-file-name (sync/ "abbrev.el") save-abbrevs 'silent) (:hook-into text-mode circe-chat-mode)) -(setup auto-insert - (setf (alist-get '("lisp/.*\\.el\\'" . "+Emacs lisp") - auto-insert-alist nil nil #'equal) - `(nil ";;; " (file-name-nondirectory (buffer-file-name)) - (make-string (max 2 (- fill-column (current-column) 27)) 32) - "-*- lexical-binding: t; -*-" '(setq lexical-binding t) - ,(concat "\n\n;;; Commentary:" - "\n\n;; ") _ - ,(concat "\n\n;;; Code:" - "\n\n" - "\n\n(provide '") - (file-name-base (buffer-file-name)) - ,(concat ")" "\n;;; ") - (file-name-nondirectory (buffer-file-name)) " ends here\n")) - (auto-insert-mode +1)) - (setup autorevert (:option global-auto-revert-non-file-buffers t auto-revert-verbose nil) @@ -303,6 +296,9 @@ "M-n" nil "M-p" nil)) +(setup flyspell + (:hook-into org-mode)) + (setup hideshow (:also-load +hideshow) (:with-mode hs-minor-mode @@ -558,7 +554,7 @@ [remap isearch-query-replace-regexp] #'anzu-isearch-query-replace-regexp)) (setup (:straight avy) - (:also-load +avy) + (:require avy +avy) (:+key "M-j" #'avy-goto-char-timer) (:bind-into isearch "M-j" #'avy-isearch) @@ -780,7 +776,7 @@ ("M-s u" . consult-focus-lines) ;; Isearch integration ("M-s e" . consult-isearch-history))) - (define-key +key-mode-map (kbd (car binding)) (cdr binding))) + (global-set-key (kbd (car binding)) (cdr binding))) (with-eval-after-load 'isearch-mode (dolist (binding '(("M-e" . consult-isearch-history) ("M-s e" . consult-isearch-history) @@ -813,7 +809,8 @@ (setup (:straight crux) ;; yes it's silly I have an addon to this addon. (:also-load +crux) - (:option crux-shell-func #'crux-eshell) + (:option crux-shell-func #'crux-eshell + +crux-default-date-format "%F") (:global "C-o" #'crux-smart-open-line "C-x 4 t" #'crux-transpose-windows "M-w" #'+crux-kill-ring-save @@ -844,7 +841,7 @@ See also `crux-reopen-as-root-mode'." (autoload 'dictionary-search "dictionary" "Ask for a word and search it in all dictionaries" t) (:hook #'reading-mode) - (define-key +lookup-map "d" #'dictionary-search)) + (define-key +lookup-mode-map "d" #'dictionary-search)) (setup (:straight (discord :host github @@ -949,6 +946,11 @@ See also `crux-reopen-as-root-mode'." :repo "duckwork/filldent.el")) (:+key "M-q" #'filldent-dwim)) +(setup (:straight flyspell-correct) + (:option flyspell-correct--cr-key ";") + (:bind-into flyspell + "C-;" #'flyspell-correct-wrapper)) + (setup (:straight-when (forge :host github :repo "magit/forge") (eq system-system 'linux)) diff --git a/lisp/+casing.el b/lisp/+casing.el index fe97310..a21e710 100644 --- a/lisp/+casing.el +++ b/lisp/+casing.el @@ -3,17 +3,7 @@ ;;; Code: (require 'thingatpt) - -(defvar +casing-map (make-sparse-keymap) - "Keymap for word-casing.") - -(let ((map +casing-map)) - (define-key map "u" #'+upcase-dwim) - (define-key map (kbd "M-u") #'+upcase-dwim) - (define-key map "l" #'+downcase-dwim) - (define-key map (kbd "M-l") #'+downcase-dwim) - (define-key map "c" #'+capitalize-dwim) - (define-key map (kbd "M-c") #'+capitalize-dwim)) +(require '+key) ;;;###autoload (defun +upcase-dwim (arg) @@ -28,9 +18,10 @@ Otherwise, it calls `upcase-word' on the word at point (using (word-bound (save-excursion (skip-chars-forward "^[:word:]") (bounds-of-thing-at-point 'word)))) - (upcase-region (car word-bound) (cdr word-bound)) - (goto-char (cdr word-bound)) - (upcase-word following)))) + (when (and (car word-bound) (cdr word-bound)) + (upcase-region (car word-bound) (cdr word-bound)) + (goto-char (cdr word-bound)) + (upcase-word following))))) ;;;###autoload (defun +downcase-dwim (arg) @@ -45,9 +36,10 @@ Otherwise, it calls `downcase-word' on the word at point (using (word-bound (save-excursion (skip-chars-forward "^[:word:]") (bounds-of-thing-at-point 'word)))) - (downcase-region (car word-bound) (cdr word-bound)) - (goto-char (cdr word-bound)) - (downcase-word following)))) + (when (and (car word-bound) (cdr word-bound)) + (downcase-region (car word-bound) (cdr word-bound)) + (goto-char (cdr word-bound)) + (downcase-word following))))) ;;;###autoload (defun +capitalize-dwim (arg) @@ -62,11 +54,26 @@ Otherwise, it calls `capitalize-word' on the word at point (using (word-bound (save-excursion (skip-chars-forward "^[:word:]") (bounds-of-thing-at-point 'word)))) - (capitalize-region (car word-bound) (cdr word-bound)) - (goto-char (cdr word-bound)) - (capitalize-word following)))) + (when (and (car word-bound) (cdr word-bound)) + (capitalize-region (car word-bound) (cdr word-bound)) + (goto-char (cdr word-bound)) + (capitalize-word following))))) ;; Later on, I'll add repeat maps and stuff in here... +(define-minor-mode +casing-mode + "Enable easy case-twiddling commands." + :lighter " cC" + :keymap (let ((map (make-sparse-keymap))) + (define-key map "u" #'+upcase-dwim) + (define-key map (kbd "M-u") #'+upcase-dwim) + (define-key map "l" #'+downcase-dwim) + (define-key map (kbd "M-l") #'+downcase-dwim) + (define-key map "c" #'+capitalize-dwim) + (define-key map (kbd "M-c") #'+capitalize-dwim) + map) + (define-key +key-mode-map (kbd "M-c") (when +casing-mode + +casing-mode-map))) + (provide '+casing) ;;; +casing.el ends here diff --git a/lisp/+emacs.el b/lisp/+emacs.el index 2e3d257..7453913 100644 --- a/lisp/+emacs.el +++ b/lisp/+emacs.el @@ -80,8 +80,8 @@ Do this only if the buffer is not visiting a file." mark-ring-max 50 minibuffer-eldef-shorten-default t minibuffer-prompt-properties (list 'read-only t - 'cursor-intangible t - 'face 'minibuffer-prompt) + 'cursor-intangible t + 'face 'minibuffer-prompt) mode-require-final-newline 'visit-save mouse-drag-copy-region t mouse-wheel-progressive-speed nil @@ -90,8 +90,8 @@ Do this only if the buffer is not visiting a file." read-answer-short t read-buffer-completion-ignore-case t read-extended-command-predicate (when (fboundp - 'command-completion-default-include-p) - 'command-completion-default-include-p) + 'command-completion-default-include-p) + 'command-completion-default-include-p) recenter-positions '(top middle bottom) regexp-search-ring-max 100 regexp-search-ring-max 200 @@ -169,23 +169,23 @@ Do this only if the buffer is not visiting a file." ;;; Modes (dolist (enable-mode '(global-auto-revert-mode - blink-cursor-mode - electric-pair-mode - show-paren-mode - global-so-long-mode - minibuffer-depth-indicate-mode - file-name-shadow-mode - minibuffer-electric-default-mode - delete-selection-mode - column-number-mode)) + blink-cursor-mode + electric-pair-mode + show-paren-mode + global-so-long-mode + minibuffer-depth-indicate-mode + file-name-shadow-mode + minibuffer-electric-default-mode + delete-selection-mode + column-number-mode)) (when (fboundp enable-mode) (funcall enable-mode +1))) (dolist (disable-mode '(tooltip-mode tool-bar-mode - menu-bar-mode - scroll-bar-mode - horizontal-scroll-bar-mode)) + menu-bar-mode + scroll-bar-mode + horizontal-scroll-bar-mode)) (when (fboundp disable-mode) (funcall disable-mode -1))) @@ -243,19 +243,16 @@ kill without asking." ("C-s" . isearch-forward-regexp) ("C-r" . isearch-backward-regexp) ("C-M-s" . isearch-forward) - ("C-M-r" . isearch-backward) - ("M-u" . upcase-dwim) - ("M-l" . downcase-dwim) - ("M-c" . capitalize-dwim))) + ("C-M-r" . isearch-backward))) (define-key +key-mode-map (kbd (car binding)) (cdr binding))) ;;; Required libraries (when (require 'uniquify nil :noerror) (setq-default uniquify-buffer-name-style 'forward - uniquify-separator path-separator - uniquify-after-kill-buffer-p t - uniquify-ignore-buffers-re "^\\*")) + uniquify-separator path-separator + uniquify-after-kill-buffer-p t + uniquify-ignore-buffers-re "^\\*")) (when (require 'goto-addr) (if (fboundp 'global-goto-address-mode) @@ -264,36 +261,36 @@ kill without asking." (when (require 'recentf nil :noerror) (setq-default recentf-save-file (.etc "recentf.el") - recentf-max-menu-items 100 - recentf-max-saved-items nil - recentf-auto-cleanup 'mode) + recentf-max-menu-items 100 + recentf-max-saved-items nil + recentf-auto-cleanup 'mode) (add-to-list 'recentf-exclude .etc) (recentf-mode +1)) (when (require 'repeat nil :noerror) (setq-default repeat-exit-key "g" - repeat-exit-timeout 5) + repeat-exit-timeout 5) (when (fboundp 'repeat-mode) ;; `repeat-mode' is defined in repeat.el, which is an older library. (repeat-mode +1))) (when (require 'savehist nil :noerror) (setq-default history-length t - history-delete-duplicates t - history-autosave-interval 60 - savehist-file (.etc "savehist.el")) + history-delete-duplicates t + history-autosave-interval 60 + savehist-file (.etc "savehist.el")) (dolist (var '(extended-command-history - global-mark-ring - kill-ring - regexp-search-ring - search-ring - mark-ring)) + global-mark-ring + kill-ring + regexp-search-ring + search-ring + mark-ring)) (add-to-list 'savehist-additional-variables var)) (savehist-mode +1)) (when (require 'saveplace nil :noerror) (setq-default save-place-file (.etc "places.el") - save-place-forget-unreadable-files (eq system-type 'gnu/linux)) + save-place-forget-unreadable-files (eq system-type 'gnu/linux)) (save-place-mode +1)) ;; (when (require 'tramp) diff --git a/lisp/+lookup.el b/lisp/+lookup.el index dfa0180..f13f535 100644 --- a/lisp/+lookup.el +++ b/lisp/+lookup.el @@ -7,11 +7,17 @@ ;;; Code: -(defvar +lookup-map (let ((map (make-sparse-keymap))) - (define-key map "f" #'find-function) - (define-key map "l" #'find-library) - map) - "Keymap for looking up things.") +(require '+key) + +(define-minor-mode +lookup-mode + "A mode for easily looking things up." + :lighter " l^" + :keymap (let ((map (make-sparse-keymap))) + (define-key map "f" #'find-function) + (define-key map "l" #'find-library) + map) + (define-key +key-mode-map (kbd "C-c l") (when +lookup-mode + +lookup-mode-map))) (provide '+lookup) ;;; +lookup.el ends here diff --git a/lisp/acdw.el b/lisp/acdw.el index a6fddfe..fcab61b 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el @@ -19,6 +19,8 @@ ;;; Code: +(require 'diary-lib) + ;;; Define a directory and an expanding function (defmacro +define-dir (name directory &optional docstring inhibit-mkdir) @@ -94,7 +96,11 @@ itself." ;; sunset-command. (funcall sunset-command) (run-at-time sunrise nil sunrise-command)) - ((time-less-p nil sunset-time) (run-at-time sunset nil sunset-command)) + ((time-less-p nil sunset-time) + ;; If it isn't sunset yet, it's still light---so we need to run the + ;; sunrise-command. + (funcall sunrise-command) + (run-at-time sunset nil sunset-command)) (t (run-at-time "12:00am" nil sunset-command))) ;; Reset everything at midnight (unless reset