331 lines
10 KiB
EmacsLisp
331 lines
10 KiB
EmacsLisp
(setq gc-cons-threshold 100000000)
|
||
(add-to-list 'load-path "~/.emacs.d/lisp/")
|
||
|
||
(require 'package)
|
||
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
|
||
(package-initialize)
|
||
|
||
(menu-bar-mode -1)
|
||
(tool-bar-mode -1)
|
||
(scroll-bar-mode -1)
|
||
(savehist-mode -1)
|
||
(global-hl-line-mode)
|
||
(column-number-mode)
|
||
(recentf-mode)
|
||
(save-place-mode)
|
||
|
||
;; basic key binds
|
||
(global-set-key (kbd "C-`") 'other-window)
|
||
(global-set-key (kbd "C-x w d") 'delete-all-space)
|
||
(global-set-key (kbd "C-x w f") 'forward-whitespace)
|
||
(global-set-key (kbd "C-c c") 'compile)
|
||
(global-set-key (kbd "C-c r") 'recompile)
|
||
(global-set-key (kbd "C-c k") 'kill-current-buffer)
|
||
(global-set-key (kbd "C-c e v") 'eval-buffer)
|
||
|
||
;; utilities
|
||
(defun edit-init-file ()
|
||
"Switch to a buffer visiting your init file."
|
||
(interactive)
|
||
(find-file user-init-file))
|
||
(defun reindent-buffer ()
|
||
"Reindent the current buffer."
|
||
(interactive)
|
||
(indent-region (point-min) (point-max)))
|
||
(defun set-face-attributes (list-of-lists)
|
||
"For each sublist of LIST-OF-LISTS, apply the attributes specified in
|
||
the cdr to the face specified by the car.
|
||
|
||
That is, the call:
|
||
|
||
(set-face-attributes '((font-lock-comment-face :slant italic)))
|
||
|
||
will set the `:slant' attribute of `font-lock-comment-face' to the
|
||
value `italic'."
|
||
(mapc #'(lambda (l)
|
||
(apply #'set-face-attribute
|
||
(append (list (car l) t) (cdr l))))
|
||
list-of-lists))
|
||
(defun touch (file-name)
|
||
"Create FILE-NAME or update its modified date."
|
||
(find-file custom-file)
|
||
(save-buffer)
|
||
(kill-current-buffer))
|
||
|
||
;; other key binds
|
||
(global-set-key (kbd "C-c e r") 'reindent-buffer)
|
||
(global-set-key (kbd "C-c e i") 'edit-init-file)
|
||
(global-set-key (kbd "C-h w") 'dictionary-search)
|
||
|
||
;; variables
|
||
(setq compilation-scroll-output t
|
||
dictionary-server "dict.org"
|
||
dired-listing-switches "-alh --group-directories-first"
|
||
fill-column 74
|
||
frame-resize-pixelwise t
|
||
window-resize-pixelwise t
|
||
show-paren-context-when-offscreen 'overlay
|
||
treesit-font-lock-level 4
|
||
wdired-allow-to-change-permissions t)
|
||
|
||
;; modes
|
||
(package-install 'git-modes)
|
||
(package-install 'json-mode)
|
||
(package-install 'lua-mode)
|
||
(package-install 'markdown-mode)
|
||
(package-install 'nix-mode)
|
||
(package-install 'yaml-mode)
|
||
|
||
;; hooks
|
||
(defun indent-common-hook ()
|
||
;; set indent width to 4 spaces
|
||
(setq-local tab-width 4
|
||
c-basic-offset 4
|
||
c-syntactic-indentation nil
|
||
c-ts-mode-indent-offset 4
|
||
lua-indent-level 4))
|
||
(defun indent-tab-hook ()
|
||
(indent-common-hook)
|
||
(setq-local indent-tabs-mode t))
|
||
(defun indent-spc-hook (&optional w)
|
||
(or w (setq w 4))
|
||
(indent-common-hook)
|
||
(setq-local indent-tabs-mode nil
|
||
tab-width w))
|
||
|
||
(add-hook 'prog-mode-hook 'display-line-numbers-mode)
|
||
|
||
(add-hook 'prog-mode-hook 'indent-tab-hook)
|
||
(add-hook 'sgml-mode-hook 'indent-spc-hook)
|
||
(add-hook 'd-mode-hook 'indent-tab-hook)
|
||
(add-hook 'nix-mode-hook #'(lambda () (indent-spc-hook 2)))
|
||
|
||
(defun lisp-hook ()
|
||
(indent-spc-hook 2))
|
||
(add-hook 'lisp-mode-hook 'lisp-hook)
|
||
(add-hook 'lisp-data-mode-hook 'lisp-hook)
|
||
|
||
(add-hook 'mail-mode-hook 'auto-fill-mode)
|
||
(add-hook 'markdown-mode-hook 'auto-fill-mode)
|
||
(add-hook 'nroff-mode-hook 'auto-fill-mode)
|
||
(add-hook 'org-mode-hook 'auto-fill-mode)
|
||
|
||
;; file extensions
|
||
(add-to-list 'auto-mode-alist '("\\.scd\\'" . markdown-mode))
|
||
(add-to-list 'auto-mode-alist '("\\.nix\\'" . nix-mode))
|
||
(add-to-list 'auto-mode-alist '("\\.3lua\\'" . nroff-mode))
|
||
|
||
;; treesitter modes
|
||
(setq major-mode-remap-alist
|
||
'((c-mode . c-ts-mode)
|
||
(c++-mode . c++-ts-mode)
|
||
(sh-mode . bash-ts-mode)))
|
||
|
||
(package-install 'd-mode)
|
||
;; fix to make d-mode highlight primitive types properly
|
||
(font-lock-add-keywords 'd-mode
|
||
'(("\\<\\(bool\\|byte\\|ubyte\\|char\\|delegate\\|double\\|float\\|function\\|int\\|long\\|short\\|uint\\|ulong\\|ushort\\|cent\\|ucent\\|real\\|ireal\\|idouble\\|ifloat\\|creal\\|cfloat\\|cdouble\\|wchar\\|dchar\\|void\\|string\\|wstring\\|dstring\\|__vector\\|Runtime\\|Thread\\)\\>" . 'font-lock-type-face)))
|
||
|
||
;; undo-tree
|
||
(package-install 'undo-tree)
|
||
(global-undo-tree-mode)
|
||
|
||
;; isearch match count
|
||
(package-install 'anzu)
|
||
(global-anzu-mode)
|
||
|
||
;; highlight colours
|
||
(package-install 'rainbow-mode)
|
||
(add-hook 'prog-mode-hook 'rainbow-mode)
|
||
|
||
;; rainbow parens in lisp-mode
|
||
(package-install 'rainbow-delimiters)
|
||
(add-hook 'lisp-mode-hook 'rainbow-delimiters-mode)
|
||
(add-hook 'lisp-data-mode-hook 'rainbow-delimiters-mode)
|
||
|
||
;; modernize org-mode
|
||
(package-install 'org-modern)
|
||
(add-hook 'org-mode-hook 'org-modern-mode)
|
||
;; create a TOC on saving an org document
|
||
(package-install 'toc-org)
|
||
(add-hook 'org-mode-hook 'toc-org-mode)
|
||
;; enable spell checking in org mode
|
||
(add-hook 'org-mode-hook #'(lambda () (flyspell-mode)))
|
||
|
||
;; slime
|
||
(package-install 'slime)
|
||
(setq inferior-lisp-program "sbcl")
|
||
(add-hook 'slime-repl-mode-hook
|
||
#'(lambda ()
|
||
(keymap-local-set "C-c l" 'slime-hyperspec-lookup)))
|
||
|
||
;; minibuffer completion
|
||
(package-install 'marginalia)
|
||
(package-install 'vertico)
|
||
(marginalia-mode)
|
||
(vertico-mode)
|
||
|
||
;; company completion
|
||
(package-install 'company)
|
||
(require 'company)
|
||
(add-hook 'after-init-hook 'global-company-mode)
|
||
(setq company-begin-commands '(self-insert-command)
|
||
company-idle-delay .1
|
||
company-minimum-prefix-length 2
|
||
company-show-numbers t
|
||
company-tooltip-align-annotations 't
|
||
read-buffer-completion-ignore-case t
|
||
read-file-name-completion-ignore-case t
|
||
completion-ignore-case t)
|
||
|
||
;; eglot
|
||
(require 'eglot)
|
||
(add-hook 'c-ts-mode-hook 'eglot-ensure)
|
||
(add-hook 'c++-ts-mode-hook 'eglot-ensure)
|
||
(add-to-list 'eglot-server-programs `(d-mode . ("serve-d")))
|
||
|
||
;; diff information in the gutter
|
||
(package-install 'diff-hl)
|
||
(global-diff-hl-mode)
|
||
(add-hook 'magit-pre-refresh-hook 'diff-hl-magit-pre-refresh)
|
||
(add-hook 'magit-post-refresh-hook 'diff-hl-magit-post-refresh)
|
||
|
||
;; editorconfig
|
||
(package-install 'editorconfig)
|
||
(editorconfig-mode)
|
||
|
||
;; which-key
|
||
(package-install 'which-key)
|
||
(which-key-mode)
|
||
(setq which-key-side-window-location 'bottom
|
||
which-key-sort-order 'which-key-key-order-alpha
|
||
which-key-sort-uppercase-first nil
|
||
which-key-add-column-padding 1
|
||
which-key-max-display-columns nil
|
||
which-key-min-display-lines 6
|
||
which-key-side-window-slot -10
|
||
which-key-side-window-max-height 0.25
|
||
which-key-idle-delay 0.8
|
||
which-key-max-description-length 25
|
||
which-key-allow-imprecise-window-fit t
|
||
which-key-separator " ")
|
||
|
||
;; image-dired
|
||
(package-install 'image-dired)
|
||
(global-set-key (kbd "C-c i") 'image-dired)
|
||
(add-hook 'image-dired-thumbnail-mode-hook
|
||
#'(lambda ()
|
||
(keymap-local-set "M-RET" 'image-dired-display-this)))
|
||
|
||
;; magit
|
||
(package-install 'magit)
|
||
(global-set-key (kbd "C-c b") 'magit-blame)
|
||
|
||
;; breadcrumbs
|
||
(package-install 'breadcrumb)
|
||
(require 'breadcrumb)
|
||
(setq breadcrumb-project-crumb-separator " / "
|
||
breadcrumb-imenu-crumb-separator " ] ")
|
||
(add-hook 'prog-mode-hook
|
||
#'(lambda ()
|
||
(setq header-line-format
|
||
'(" "
|
||
(:eval (breadcrumb-project-crumbs))
|
||
" : "
|
||
(:eval (breadcrumb-imenu-crumbs))))))
|
||
|
||
;; dashboard
|
||
(package-install 'dashboard)
|
||
(require 'dashboard)
|
||
(setq dashboard-banner-logo-title (concat "Welcome to GNU Emacs, one "
|
||
"component of the GNU/Linux "
|
||
"operating system.")
|
||
dashboard-startup-banner "~/pix/jemacs-book.png"
|
||
dashboard-center-content t
|
||
dashboard-vertically-center-content t
|
||
dashboard-items '((bookmarks . 4)
|
||
(recents . 4))
|
||
dashboard-footer-messages
|
||
(list
|
||
"At its core is an interpreter for Emacs Lisp."
|
||
"Merely an interface to your code."
|
||
"“We don't use the term ‘corelibs,’ and I am not sure what that would mean.”"
|
||
"50 years and Dired is still the best file manager on the planet")
|
||
initial-buffer-choice (lambda ()
|
||
(get-buffer-create dashboard-buffer-name)))
|
||
(add-hook 'after-init-hook 'dashboard-insert-startupify-lists)
|
||
(add-hook 'after-init-hook 'dashboard-initialize)
|
||
(dashboard-setup-startup-hook)
|
||
|
||
;; faces
|
||
(require 'cus-edit) ; custom faces
|
||
(let
|
||
((fixedpt "Roboto Mono")
|
||
( varpt "Roboto")
|
||
( accent "#89b4fa"))
|
||
(add-to-list 'default-frame-alist (cons 'font fixedpt))
|
||
(set-face-attributes
|
||
`((default :height 140)
|
||
(fixed-pitch :family ,fixedpt)
|
||
(variable-pitch :family ,varpt)
|
||
(font-lock-comment-face :slant italic)
|
||
(font-lock-keyword-face :slant italic)
|
||
(link :foreground ,accent :underline t)
|
||
(mode-line-inactive :weight light)
|
||
(help-key-binding
|
||
:family ,fixedpt
|
||
:background "#181825"
|
||
:foreground ,accent
|
||
:box (:line-width (-1 . -1) :color "#11111b" :style nil))
|
||
(widget-field
|
||
:extend t
|
||
:background "#181825"
|
||
:box (:line-width (1 . 1) :color "#11111b"))
|
||
(custom-button
|
||
:background "#181825"
|
||
:foreground "white"
|
||
:box (:line-width (1 . 1) :color "#11111b" :style nil))
|
||
(custom-button-mouse :background "#11111b" :foreground "white")
|
||
(custom-button-pressed :inherit custom-button-mouse
|
||
:box (:line-width (1 . 1) :color "#11111b"))
|
||
(info-xref :inherit link
|
||
:background "#181825"
|
||
:foreground ,accent)
|
||
(anzu-mode-line :foreground ,accent)
|
||
(breadcrumb-imenu-leaf-face :foreground ,accent)
|
||
(dashboard-heading :foreground ,accent :height 1.1 :weight bold))))
|
||
|
||
;; custom
|
||
(setq custom-file "~/.emacs.d/custom.el")
|
||
(touch custom-file)
|
||
(load custom-file)
|
||
|
||
;; catppuccin theme
|
||
(package-install 'catppuccin-theme)
|
||
(setq catppuccin-flavor 'mocha)
|
||
(load-theme 'catppuccin :no-confirm)
|
||
|
||
;; nyan-mode
|
||
(package-install 'nyan-mode)
|
||
(nyan-mode)
|
||
|
||
;; mu4e
|
||
(let ((mu4e-file "~/.emacs.d/mu4e.el"))
|
||
(when (file-exists-p mu4e-file)
|
||
(load mu4e-file)))
|
||
|
||
;; other packages
|
||
(require 'esv)
|
||
(require 'phobos)
|
||
(setq phobos-browser "firefox")
|
||
|
||
(add-to-list 'load-path "~/git/d-ts-mode/")
|
||
(require 'd-ts-mode)
|
||
|
||
;; enable disabled commands
|
||
(put 'dired-find-alternate-file 'disabled nil)
|
||
(put 'downcase-region 'disabled nil)
|
||
(put 'upcase-region 'disabled nil)
|
||
(put 'narrow-to-region 'disabled nil)
|
||
|
||
;;; init.el ends here
|