1

Perform some code cleanup

This commit is contained in:
Jessie Hildebrandt 2022-12-19 22:37:06 -05:00
parent 5fbc709f3f
commit af034bf172

172
init.el
View File

@ -198,17 +198,6 @@
(byte-compile-file user/init-file) (byte-compile-file user/init-file)
(byte-compile-file user/early-init-file)) (byte-compile-file user/early-init-file))
(defun user/refresh-packages ()
"Refresh packages that have been configured for use in the user init file.
This is accomplished by deleting `package-user-dir' and recompiling the user
init file, which initializes the package manager during compile time."
(interactive)
(when (yes-or-no-p "Redownload and refresh packages? ")
(message "Refreshing packages...")
(delete-directory package-user-dir :recursive)
(user/byte-compile-init-files)))
(defun user/download-latest-init-file () (defun user/download-latest-init-file ()
"Download the latest user init file from jessieh.net/emacs. "Download the latest user init file from jessieh.net/emacs.
@ -223,6 +212,17 @@ If `user/init-file' points to a symlink, nothing will be downloaded."
(url-copy-file "https://jessieh.net/emacs" user/init-file :ok-if-already-exists) (url-copy-file "https://jessieh.net/emacs" user/init-file :ok-if-already-exists)
(user/byte-compile-init-files)))) (user/byte-compile-init-files))))
(defun user/refresh-packages ()
"Refresh packages that have been configured for use in the user init file.
This is accomplished by deleting `package-user-dir' and recompiling the user
init file, which initializes the package manager during compile time."
(interactive)
(when (yes-or-no-p "Redownload and refresh packages? ")
(message "Refreshing packages...")
(delete-directory package-user-dir :recursive)
(user/byte-compile-init-files)))
(defun user/select-minibuffer-window () (defun user/select-minibuffer-window ()
"Select the minibuffer window if it is active." "Select the minibuffer window if it is active."
(interactive) (interactive)
@ -277,7 +277,7 @@ DOCSTRING is an optional form that is discarded upon expansion."
`(use-package ,name :ensure nil ,@args)) `(use-package ,name :ensure nil ,@args))
;; ---------------------------------- ;; ;; ---------------------------------- ;;
;; General editor setup ;; emacs
;; ---------------------------------- ;; ;; ---------------------------------- ;;
(defun user/ensure-region-active (func &rest args) (defun user/ensure-region-active (func &rest args)
@ -286,7 +286,7 @@ DOCSTRING is an optional form that is discarded upon expansion."
(apply func args))) (apply func args)))
(editor-feature emacs (editor-feature emacs
"General editor-wide configuration" "Provides an extensible, customizable, self-documenting real-time display editor"
:config :config
@ -313,7 +313,6 @@ DOCSTRING is an optional form that is discarded upon expansion."
(max-mini-window-height 10 "Limit minibuffer height to 10 lines") (max-mini-window-height 10 "Limit minibuffer height to 10 lines")
(enable-recursive-minibuffers t "Allow minibuffer commands to be called in the minibuffer") (enable-recursive-minibuffers t "Allow minibuffer commands to be called in the minibuffer")
(load-prefer-newer t "Load from source files if they are newer than bytecode files") (load-prefer-newer t "Load from source files if they are newer than bytecode files")
(server-client-instructions nil "Suppress help messages from the server for new frames")
;; Startup ;; Startup
(initial-scratch-message "" "Leave scratch buffer empty on startup") (initial-scratch-message "" "Leave scratch buffer empty on startup")
@ -383,69 +382,6 @@ DOCSTRING is an optional form that is discarded upon expansion."
("C-c C-j" . windmove-left) ("C-c C-j" . windmove-left)
("C-c C-l" . windmove-right)) ("C-c C-l" . windmove-right))
;; ---------------------------------- ;;
;; File save/backup behavior
;; ---------------------------------- ;;
(defconst user/custom-file (locate-user-emacs-file "custom.el") "Location of user customizations file.")
(defconst user/backup-directory (locate-user-emacs-file "backup/") "Location of user backup directory.")
(defconst user/auto-save-directory (locate-user-emacs-file "auto-save/") "Location of user auto save directory.")
(defconst user/lock-file-directory (locate-user-emacs-file "lock-file/") "Location of user lock file directory.")
(make-directory user/backup-directory :parents)
(make-directory user/auto-save-directory :parents)
(make-directory user/lock-file-directory :parents)
(editor-feature files
"File/save backup behavior configuration"
:custom
;; Config file
(custom-file user/custom-file "Store customization info in a separate file")
;; Directories
(backup-directory-alist `((".*" . ,user/backup-directory)))
(auto-save-file-name-transforms `((".*" ,user/auto-save-directory t)))
(lock-file-name-transforms `((".*" ,user/lock-file-directory t)))
;; Backup behavior
(backup-by-copying t "Use copying unconditionally when creating backups")
(version-control t "Use version numbers on backup files")
(delete-old-versions t "Clean up old backup files")
(kept-new-versions 5 "Keep 5 recent backup files")
(kept-old-versions 3 "Keep 3 old backup files")
:hook
(before-save-hook . delete-trailing-whitespace))
;; ---------------------------------- ;;
;; Graphical frame settings
;; ---------------------------------- ;;
(defvar user/initial-frame-created nil "Whether or not the first frame has been initialized by the server.")
(defvar user/after-daemon-make-initial-frame-functions nil "Run when the first frame is produced by the server in daemon mode.")
(defun user/set-up-frame (frame)
"Set up newly-created frame FRAME."
(when (display-graphic-p frame)
(with-selected-frame frame
(let ((winid (frame-parameter frame 'outer-window-id)))
(call-process-shell-command
(concat "xprop -f _GTK_THEME_VARIANT 8u -set _GTK_THEME_VARIANT dark -id " winid)
nil 0))
(when (and (daemonp)
(not user/initial-frame-created))
(run-hooks 'user/after-daemon-make-initial-frame-functions)
(setq user/initial-frame-created t)))))
(editor-feature frame
"Graphical frame configuration"
:config
(mapc #'user/set-up-frame (frame-list))
:hook
(after-make-frame-functions . user/set-up-frame))
;; ---------------------------------- ;; ;; ---------------------------------- ;;
;; autorevert ;; autorevert
;; ---------------------------------- ;; ;; ---------------------------------- ;;
@ -554,6 +490,67 @@ DOCSTRING is an optional form that is discarded upon expansion."
("C-c j" . tab-line-switch-to-prev-tab) ("C-c j" . tab-line-switch-to-prev-tab)
("C-c l" . tab-line-switch-to-next-tab))) ("C-c l" . tab-line-switch-to-next-tab)))
;; ---------------------------------- ;;
;; files
;; ---------------------------------- ;;
(defconst user/custom-file (locate-user-emacs-file "custom.el") "Location of user customizations file.")
(defconst user/backup-directory (locate-user-emacs-file "backup/") "Location of user backup directory.")
(defconst user/auto-save-directory (locate-user-emacs-file "auto-save/") "Location of user auto save directory.")
(defconst user/lock-file-directory (locate-user-emacs-file "lock-file/") "Location of user lock file directory.")
(make-directory user/backup-directory :parents)
(make-directory user/auto-save-directory :parents)
(make-directory user/lock-file-directory :parents)
(editor-feature files
"Defines most of Emacs' file-handling functionality"
:custom
;; Config file
(custom-file user/custom-file "Store customization info in a separate file")
;; Directories
(backup-directory-alist `((".*" . ,user/backup-directory)))
(auto-save-file-name-transforms `((".*" ,user/auto-save-directory t)))
(lock-file-name-transforms `((".*" ,user/lock-file-directory t)))
;; Backup behavior
(backup-by-copying t "Use copying unconditionally when creating backups")
(version-control t "Use version numbers on backup files")
(delete-old-versions t "Clean up old backup files")
(kept-new-versions 5 "Keep 5 recent backup files")
(kept-old-versions 3 "Keep 3 old backup files")
:hook
(before-save-hook . delete-trailing-whitespace))
;; ---------------------------------- ;;
;; frame
;; ---------------------------------- ;;
(defvar user/initial-frame-created nil "Whether or not the first frame has been initialized by the server.")
(defvar user/after-daemon-make-initial-frame-functions nil "Run when the first frame is produced by the server in daemon mode.")
(defun user/set-up-frame (frame)
"Set up newly-created frame FRAME."
(when (display-graphic-p frame)
(let ((winid (frame-parameter frame 'outer-window-id)))
(start-process "" nil "xprop" "-f" "_GTK_THEME_VARIANT" "8u" "-set" "_GTK_THEME_VARIANT" "dark" "-id" winid))
(when (and (daemonp)
(not user/initial-frame-created))
(with-selected-frame frame
(run-hooks 'user/after-daemon-make-initial-frame-functions)
(setq user/initial-frame-created t)))))
(editor-feature frame
"Graphical frame configuration"
:config
(mapc #'user/set-up-frame (frame-list))
:hook
(after-make-frame-functions . user/set-up-frame))
;; ---------------------------------- ;; ;; ---------------------------------- ;;
;; hl-line ;; hl-line
;; ---------------------------------- ;; ;; ---------------------------------- ;;
@ -597,6 +594,22 @@ DOCSTRING is an optional form that is discarded upon expansion."
:config :config
(savehist-mode)) (savehist-mode))
;; ---------------------------------- ;;
;; server
;; ---------------------------------- ;;
(editor-feature server
"Allows Emacs to operate as a server for other Emacs processes"
:config
;; When running in a server/client configuration, we don't want the
;; foreground/background in `default-frame-alist' to override the colors
;; set by the theme every time we open a new client frame
(when (daemonp)
(assoc-delete-all 'foreground default-frame-alist)
(assoc-delete-all 'background default-frame-alist))
:custom
(server-client-instructions nil "Suppress help messages from the server for new frames"))
;; ---------------------------------- ;; ;; ---------------------------------- ;;
;; so-long ;; so-long
;; ---------------------------------- ;; ;; ---------------------------------- ;;
@ -947,9 +960,7 @@ DOCSTRING is an optional form that is discarded upon expansion."
;; ---------------------------------- ;; ;; ---------------------------------- ;;
(external-package fussy (external-package fussy
"Provides a flexible `completion-style' that scores and sorts candidates" "Provides a flexible completion style that scores and sorts candidates"
:demand
t
:custom :custom
(completion-ignore-case t "Ignore case in completion candidates") (completion-ignore-case t "Ignore case in completion candidates")
(completion-category-defaults nil "Disable category-specific completion styles") (completion-category-defaults nil "Disable category-specific completion styles")
@ -1279,7 +1290,6 @@ DOCSTRING is an optional form that is discarded upon expansion."
:hook :hook
(server-after-make-frame-hook . solaire-global-mode) (server-after-make-frame-hook . solaire-global-mode)
(emacs-startup-hook . solaire-global-mode)) (emacs-startup-hook . solaire-global-mode))
;; (user/after-daemon-make-initial-frame-functions . solaire-global-mode))
;; ---------------------------------- ;; ;; ---------------------------------- ;;
;; undo-tree ;; undo-tree