converted init code to use use-package

master
John Turner 1 year ago
parent e166c4beae
commit 4058ea89d9
No known key found for this signature in database

@ -1,47 +1,2 @@
(setq auth-source-save-behavior nil (setq native-comp-async-jobs-number (string-to-number (shell-command-to-string "nproc"))
auto-save-default nil native-compile-target-directory (file-name-concat (getenv "HOME") ".cache/emacs-native-comp"))
change-major-mode-with-file-name nil
custom-buffer-indent 4
custom-file (file-name-concat user-emacs-directory "custom.el")
custom-theme-directory (file-name-concat user-emacs-directory "themes/")
debugger 'edebug
initial-buffer-choice (lambda ()
(let ((initial-file (file-name-concat
user-emacs-directory
"initial-buffer")))
(if (file-exists-p initial-file)
(find-file initial-file)
(get-buffer-create "*scratch*"))))
enable-local-variables :safe
inferior-lisp-program "sbcl"
inhibit-splash-screen t
make-backup-files nil
scheme-program-name "guile"
tab-width 4
temporary-file-directory (file-name-concat (getenv "HOME") "tmp" ".emacs"))
(setq-default display-fill-column-indicator-column 120
indent-tabs-mode nil)
(let* ((init-modules-wildcard
(file-name-concat user-emacs-directory "init" "*"))
(lisp-modules-wildcard
(file-name-concat user-emacs-directory "lisp" "*"))
(init-modules-files
(file-expand-wildcards init-modules-wildcard t))
(lisp-modules-files
(file-expand-wildcards lisp-modules-wildcard t))
(files
(append init-modules-files lisp-modules-files))
(directories
(seq-filter 'file-directory-p files)))
(mapc (lambda (directory)
(add-to-list 'load-path directory))
directories))
(mkdir temporary-file-directory t)
(require 'init-garbage-collection)
(when (and (>= emacs-major-version 29) (native-comp-available-p))
(require 'init-native-comp))

@ -1,65 +1,80 @@
(defmacro require? (feature) (require 'use-package)
`(require ,feature nil t)) (require 'cl-lib)
(require 'seq)
(require 'server)
(require 'edebug)
(global-unset-key (kbd "<left>"))
(global-unset-key (kbd "<right>"))
(global-unset-key (kbd "<up>"))
(global-unset-key (kbd "<down>"))
(global-unset-key (kbd "<C-left>"))
(global-unset-key (kbd "<C-right>"))
(global-unset-key (kbd "<C-up>"))
(global-unset-key (kbd "<C-down>"))
(global-set-key (kbd "C-x k") 'kill-this-buffer)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(setq auth-source-save-behavior nil
auto-save-default nil
change-major-mode-with-file-name nil
custom-buffer-indent 4
custom-file (file-name-concat user-emacs-directory "custom.el")
custom-theme-directory (file-name-concat user-emacs-directory "themes/")
debugger 'edebug
display-buffer-base-action '(display-buffer-same-window display-buffer-reuse-window)
initial-buffer-choice (lambda ()
(let ((initial-file (file-name-concat
user-emacs-directory
"initial-buffer")))
(if (file-exists-p initial-file)
(find-file initial-file)
(get-buffer-create "*scratch*"))))
enable-local-variables :safe
inhibit-splash-screen t
make-backup-files nil
mouse-wheel-progressive-speed nil
tab-width 4
temporary-file-directory (file-name-concat (or (getenv "TMPDIR") "/tmp") ".emacs")
use-package-always-demand t
use-package-ensure-function 'ignore)
(setq-default display-fill-column-indicator-column 120
indent-tabs-mode nil)
(setq-default mode-line-format '("%*"
" "
(:eval (if buffer-file-name
(abbreviate-file-name buffer-file-name)
(buffer-name)))
" "
"(" mode-name ")"
" "
"(" (:eval (if server-process
(process-name server-process)
"_"))
")"))
(unless (when-let ((e (getenv "NO_SITE_GENTOO"))) (when (file-exists-p custom-file)
(string= e "1")) (load-file custom-file))
(require? 'site-gentoo))
(require? 'magit)
(require 'init-text-mode)
(require 'init-conf-mode)
(require 'init-prog-mode)
(require 'init-compile)
(require 'init-dired)
(require 'init-display-buffer)
(require 'init-ediff)
(require 'init-eldoc)
(require 'init-electric)
(require 'init-flymake)
(require 'init-ibuffer)
(require 'init-ielm)
(require 'init-keys)
(require 'init-man)
(require 'init-mode-line)
(require 'init-package)
(require 'init-project)
(require 'init-recentf)
(require 'init-savehist)
(require 'init-tramp)
(when (require? 'company)
(require 'init-company))
(when (require? 'flycheck)
(require 'init-flycheck))
(when (require? 'lsp-mode)
(require 'init-lsp-mode))
(when (require? 'eglot)
(require 'init-eglot))
(when (require? 'pixel-scroll)
(require 'init-pixel-scroll))
(when (and (require? 'treesit) (treesit-available-p))
(require 'init-treesit))
(require 'man-completion)
(require 'license-boilerplate)
(require 'toggle-local-vars) (load-file (locate-user-emacs-file "lisp/packages.el"))
(require 'reload-library) (cl-loop with packages-directory = (file-name-concat user-emacs-directory "packages")
for package in (directory-files packages-directory t)
unless (seq-contains-p '("." "..") (file-name-base package))
do (load-file package))
(when (file-exists-p custom-file) (mkdir temporary-file-directory t)
(load custom-file))
(cua-mode 1) (cua-mode 1)
(save-place-mode 1) (save-place-mode 1)
(show-paren-mode 1) (show-paren-mode 1)
(recentf-mode 1)
(savehist-mode 1)
(when (and (featurep 'pixel-scroll) (display-graphic-p))
(pixel-scroll-mode 1))
(menu-bar-mode 0) (menu-bar-mode 0)
(scroll-bar-mode 0) (scroll-bar-mode 0)
(tool-bar-mode 0) (tool-bar-mode 0)

@ -1,8 +0,0 @@
(require 'company)
(setq company-idle-delay 0
company-clang-executable "/usr/lib/llvm/11/bin/clang"
company-clang-insert-arguments nil
company-minimum-prefix-length 1)
(provide 'init-company)

@ -1,3 +0,0 @@
(add-hook 'compilation-mode-hook 'visual-line-mode)
(provide 'init-compile)

@ -1 +0,0 @@
(setq conf-mode-hook (copy-tree text-mode-hook))

@ -1,5 +0,0 @@
(require 'init-text-mode)
(load "init-conf-mode-hooks")
(provide 'init-conf-mode)

@ -1,4 +0,0 @@
(setq dired-listing-switches "-alh"
dired-kill-when-opening-new-dired-buffer t)
(provide 'init-dired)

@ -1,7 +0,0 @@
(defun init-display-buffer-frame-wide-p ()
(> (frame-pixel-width) (/ (x-display-pixel-width) 2)))
(defun init-display-buffer-best-side (buffer alist)
(let* ((side (funcall (alist-get 'which-side alist)))
(alist (append (cdr alist) (list (cons 'side side)))))
(display-buffer-in-side-window buffer alist)))

@ -1,5 +0,0 @@
(setq display-buffer-base-action '(display-buffer-same-window display-buffer-reuse-window))
(load "init-display-buffer-best-side")
(provide 'init-display-buffer)

@ -1,4 +0,0 @@
(setq ediff-split-window-function 'split-window-horizontally
ediff-window-setup-function 'ediff-setup-windows-plain)
(provide 'init-ediff)

@ -1,4 +0,0 @@
(setq eglot-autoshutdown t
eglot-events-buffer-size 0)
(provide 'init-eglot)

@ -1,4 +0,0 @@
(setq eldoc-idle-delay 0
eldoc-echo-area-use-multiline-p 5)
(provide 'init-eldoc)

@ -1,7 +0,0 @@
(require 'electric)
(require 'elec-pair)
(add-to-list 'electric-pair-pairs '("?(" . "?)"))
(add-to-list 'electric-pair-pairs '("?{" . "?}"))
(provide 'init-electric)

@ -1,7 +0,0 @@
(defun init-flycheck-rust-cargo-has-command-p (command)
(let* ((commands (process-lines "cargo" "--list"))
(trimmed (-map (lambda (row) (-slice row 4 (string-search " " 4))) commands)))
(seq-contains-p (-rest trimmed) command)))
(advice-add 'flycheck-rust-cargo-has-command-p
:override 'init-flycheck-rust-cargo-has-command-p)

@ -1,15 +0,0 @@
(require 'flycheck)
(load "init-flycheck-cargo-has-command-p-fix")
(add-hook 'flycheck-error-list-mode-hook (lambda () (visual-line-mode 1)))
(add-to-list 'display-buffer-alist '("\\*Flycheck errors.*"
(init-display-buffer-best-side)
(which-side . (lambda ()
(if (init-display-buffer-frame-wide-p)
'right
'bottom)))))
(provide 'init-flycheck)

@ -1,2 +0,0 @@
(add-hook 'flymake-diagnostics-buffer-mode-hook (lambda ()
(visual-line-mode 1)))

@ -1,12 +0,0 @@
(require 'flymake)
(load "init-flymake-hooks")
(add-to-list 'display-buffer-alist '("\\*Flymake diagnostics.*"
(init-display-buffer-best-side)
(which-side . (lambda ()
(if (init-display-buffer-frame-wide-p)
'right
'bottom)))))
(provide 'init-flymake)

@ -1,3 +0,0 @@
(setq gc-cons-threshold (* (expt 1024 2) 25))
(provide 'init-garbage-collection)

@ -1,10 +0,0 @@
(setq ibuffer-saved-filter-groups
'(("default"
("Misc" (and (name . "^\\*.*$")
(not (mode . Man-mode))))
("Dired" (mode . dired-mode))
("Man" (mode . Man-mode)))))
(add-hook 'ibuffer-mode-hook (lambda () (ibuffer-switch-to-saved-filter-groups "default")))
(provide 'init-ibuffer-filter-groups)

@ -1,16 +0,0 @@
(define-ibuffer-column size-human-readable
(:name "Size" :inline t)
(let ((size (buffer-size)))
(cond
((> size (expt 1000 4))
(error "buffer is over 1TB large!"))
((> size (expt 1000 3))
(format "%sG" (/ size (expt 1000 3))))
((> size (expt 1000 2))
(format "%sM" (/ size (expt 1000 2))))
((> size 1000)
(format "%sK" (/ size 1000)))
(t
(format "%sB" size)))))
(provide 'init-ibuffer-human-readable-size)

@ -1,11 +0,0 @@
(defvar init-ibuffer-never-show '("^\\*Messages\\*$"
"^\\*Completions\\*$"
"^\\*Async-native-compile-log\\*$"
"^\\*Native-compile-Log\\*$"
"^\\*Warnings\\*$"))
(mapc (lambda (p)
(add-to-list 'ibuffer-never-show-predicates p))
init-ibuffer-never-show)
(provide 'init-ibuffer-never-show)

@ -1,21 +0,0 @@
(require 'ibuffer)
(require 'ibuf-ext)
(require 'init-ibuffer-human-readable-size)
(require 'init-ibuffer-never-show)
(setq ibuffer-display-summary nil
ibuffer-expert t)
(setq ibuffer-formats
'((mark modified read-only locked " "
(name 32 32 :left :elide)
" "
(size-human-readable 5 5 :right)
" "
(mode 16 16 :left :elide)
" " filename-and-process)
(mark " "
(name 16 -1)
" " filename)))
(provide 'init-ibuffer)

@ -1,3 +0,0 @@
(add-hook 'ielm-mode-hook 'visual-line-mode)
(provide 'init-ielm)

@ -1,12 +0,0 @@
(global-unset-key (kbd "<left>"))
(global-unset-key (kbd "<right>"))
(global-unset-key (kbd "<up>"))
(global-unset-key (kbd "<down>"))
(global-unset-key (kbd "<C-left>"))
(global-unset-key (kbd "<C-right>"))
(global-unset-key (kbd "<C-up>"))
(global-unset-key (kbd "<C-down>"))
(global-set-key (kbd "C-x k") 'kill-this-buffer)
(global-set-key (kbd "C-x C-b") 'ibuffer)
(provide 'init-keys)

@ -1,40 +0,0 @@
(setq lsp-server-install-dir "/somewhere/that/doesnt/exist")
(defun init-lsp-mode-disable-install-server-error ()
(error "lsp-mode server install features have been disabled"))
(advice-add 'lsp-install-server
:around
'init-lsp-mode-disable-install-server-error)
(advice-add 'lsp-update-server
:around
'init-lsp-mode-disable-install-server-error)
(advice-add 'lsp-update-servers
:around
'init-lsp-mode-disable-install-server-error)
(advice-add 'lsp-download-install
:around
'init-lsp-mode-disable-install-server-error)
(advice-add 'lsp-download-path
:around
'init-lsp-mode-disable-install-server-error)
(advice-add 'lsp-async-start-process
:around
'init-lsp-mode-disable-install-server-error)
(advice-add 'lsp--download-status
:around
'init-lsp-mode-disable-install-server-error)
(advice-add 'lsp--install-server-internal
:around
'init-lsp-mode-disable-install-server-error)
(advice-add 'lsp--npm-dependency-install
:around
'init-lsp-mode-disable-install-server-error)

@ -1,19 +0,0 @@
(require 'lsp-mode)
(require 'flycheck)
(setq lsp-enable-dap-auto-configure nil
lsp-enable-folding nil
lsp-enable-indentation t
lsp-enable-on-type-formatting nil
lsp-completion-enable nil
lsp-enable-snippet nil
lsp-modeline-code-actions-enable nil
lsp-lens-enable nil
lsp-signature-auto-activate nil
lsp-eldoc-render-all t
lsp-rls-server-command nil
lsp-enable-suggest-server-download nil)
(load "init-lsp-mode-disable-install-server")
(provide 'init-lsp-mode)

@ -1,3 +0,0 @@
(setq Man-notify-method 'pushy)
(provide 'init-man)

@ -1,16 +0,0 @@
(setq-default mode-line-format '("%*"
" "
(:eval (if buffer-file-name
(abbreviate-file-name buffer-file-name)
(buffer-name)))
" "
"(" mode-name ")"
" "
"[" (:eval (abbreviate-file-name default-directory)) "]"
" "
"(" (:eval (if server-process
(process-name server-process)
"none"))
")"))
(provide 'init-mode-line)

@ -1,4 +0,0 @@
(setq native-comp-async-jobs-number (string-to-number (shell-command-to-string "nproc"))
native-compile-target-directory temporary-file-directory)
(provide 'init-native-comp)

@ -1,4 +0,0 @@
(setq package-archives nil
package-check-signature 'all)
(provide 'init-package)

@ -1,10 +0,0 @@
(require 'pixel-scroll)
(setq mouse-wheel-progressive-speed nil
pixel-dead-time 0
pixel-wait 0
pixel-resolution-fine-flag 10)
(pixel-scroll-mode 1)
(provide 'init-pixel-scroll)

@ -1 +0,0 @@
(setq prog-mode-hook (copy-tree text-mode-hook))

@ -1,5 +0,0 @@
(require 'init-text-mode)
(load "init-prog-mode-hooks")
(provide 'init-prog-mode)

@ -1,4 +0,0 @@
(add-to-list 'project-find-functions (lambda (directory)
(let ((rust-project (locate-dominating-file directory "Cargo.toml")))
(when rust-project
(cons 'transient rust-project)))))

@ -1,3 +0,0 @@
(load "init-project-find-rust-projects")
(provide 'init-project)

@ -1,6 +0,0 @@
(setq recentf-max-menu-items 25
recentf-max-saved-items 25)
(recentf-mode 1)
(provide 'init-recentf)

@ -1,15 +0,0 @@
(require 'savehist)
(defvar init-savehist-history-size 9999999999)
(setq savehist-file (expand-file-name "savehist" user-emacs-directory)
savehist-save-minibuffer-history t)
(add-to-list 'savehist-additional-variables `(command-history . ,init-savehist-history-size))
(unless (file-exists-p savehist-file)
(make-empty-file savehist-file))
(savehist-mode 1)
(provide 'init-savehist)

@ -1,9 +0,0 @@
(add-hook 'text-mode-hook (lambda ()
(display-line-numbers-mode 1)
(visual-line-mode 1)
(display-fill-column-indicator-mode 1)
(electric-pair-mode 1)
(electric-indent-mode 1)
(setq-local display-fill-column-indicator-column 120)
(when (require 'highlight-indentation nil t)
(highlight-indentation-mode 1))))

@ -1,3 +0,0 @@
(load "init-text-mode-hooks")
(provide 'init-text-mode)

@ -1,2 +0,0 @@
(add-to-list 'tramp-connection-properties (list (regexp-quote (format "/sudo:root@%s:" system-name))
"session-timeout" (* 60 20)))

@ -1,3 +0,0 @@
(defun sudo-edit ()
(interactive)
(find-file (format "/sudo:root@%s:%s" system-name (read-file-name "Edit as root: "))))

@ -1,10 +0,0 @@
(require 'tramp)
(setq password-cache nil
password-cache-expiry 0
tramp-persistency-file-name nil)
(load "init-tramp-connection-properties")
(load "init-tramp-sudo-hang-fix")
(provide 'init-tramp)

@ -1,97 +0,0 @@
;; -*- lexical-binding: t; -*-
;; This script is a quick workaround for setting up treesitter modes.
;; Hopefully this won't be needed for long but it works for now!
;;
;; This just runs through the list of modes below, checks if the
;; required treesitter parsers are installed, and if so,
;; sets up auto-mode-alist and interpreter-mode-alist
;; to open the respective source files with the treesitter
;; mode for that language.
;;
;; To use, you should just add the modes and other info to the list
;; below, and then "require" this file in your init.
;; The messages that get generated by this script may be burried
;; by other startup messages, so it may not appear to have done
;; anything!
;;
;; To test if it works, visit a file such as "x.py", then run
;; "M-x describe-mode". There should be some info about
;; the current major mode that looks like this:
;;
;; "The major mode is Python mode defined in python.el:
;; Major mode for editing Python files, using tree-sitter library."
(defvar -quiet? nil
"Suppress messages when setting up treesitter modes.")
(defvar -modes `((python-ts-mode
((:parsers . python)
(:file-ext . ,(rx ".py"))
(:interpreters . ("python" "python3"))))
(rust-ts-mode
((:parsers . rust)
(:file-ext . ,(rx ".rs"))))
(bash-ts-mode
((:parsers . bash)
(:file-ext . ,(rx ".sh"))
(:interpreters . ("bash" "sh" "openrc-run"))))
(c-ts-mode
((:parsers . c)
(:file-ext . ,(rx ".c"))))
(c++-ts-mode
((:parsers . cpp)
(:file-ext . ,(rx (or ".c++" ".cpp" ".cxx"
".h++" ".hpp" ".hxx")))))
(c-or-c++-ts-mode
((:parsers . (c c++))
(:file-ext . ,(rx ".h"))))
(toml-ts-mode
((:parsers . toml)
(:file-ext . ,(rx ".toml")))))
"Treesitter modes and some information required to set them up.
Parsers are the treesitter packages that need to be installed to
use the associated mode. python-ts-mode requires the python treesitter
parser package to be installed for example.
File extension is for example .py for python scripts. Some
modes like c++-ts-mode are associated with a few
extensions, and c-or-c++-mode is associated with .h
because the extension is ambiguous.
Interpreters are used to associate certain shebangs with the treesitter
mode. Files that start with '#!/usr/bin/env python' for example will
be associated with python-ts-mode if 'python' is included in the
interpreters list.")
(defun -ready-quiet? (parser)
(treesit-ready-p parser t))
(cl-defun -setup-mode? (&key ts-mode
required-parsers
file-extensions
interpreters)
(when (seq-every-p '-ready-quiet? (ensure-list required-parsers))
(add-to-list 'auto-mode-alist (cons file-extensions ts-mode))
(when interpreters
(seq-each (lambda (interpreter)
(add-to-list 'interpreter-mode-alist (cons interpreter ts-mode)))
(ensure-list interpreters)))
t))
(seq-each (lambda (mode)
(when (and (-setup-mode?
:ts-mode (car mode)
:required-parsers (alist-get :parsers (cadr mode))
:file-extensions (alist-get :file-ext (cadr mode))
:interpreters (alist-get :interpreters (cadr mode)))
(not -quiet?))
(message "Setup treesitter mode %s" (car mode))))
-modes)
(provide 'init-treesit-setup-available-languages)
;; Local Variables:
;; read-symbol-shorthands: (("-" . "init-treesit-setup-available-languages-"))
;; End:

@ -1,3 +0,0 @@
(require 'init-treesit-setup-available-languages)
(provide 'init-treesit)

@ -0,0 +1,27 @@
;;; packages.el --- -*- lexical-binding: t; -*-
;; Copyright (C) 2023
;; Author: John Turner
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
(use-package man-completion
:load-path (lambda () (locate-user-emacs-file "lisp/man-completion")))
(use-package reload-library
:load-path (lambda () (locate-user-emacs-file "lisp/reload-library")))
(use-package toggle-local-vars
:load-path (lambda () (locate-user-emacs-file "lisp/toggle-local/vars")))
Loading…
Cancel
Save