.emacs.d

the most bloated Emacs config on this planet
git clone https://git.trogloxene.org/.emacs.d.git
Log | Files | Refs

commit 271cad9631fff8eb474414e286d6f014d2d61b19
parent 046152d7742cfd863ec7dcc172f603913130b22d
Author: andsy10 <andsy1016@gmail.com>
Date:   Fri, 16 Oct 2026 05:19:23 +0800

Reorganize use-package declarations

Diffstat:
Mlisp/init-base.el | 55+++++++++++++++++++++++++++++++++----------------------
Mlisp/init-completion.el | 77++++++++++++++++++++++++++++++++---------------------------------------------
Mlisp/init-custom.el | 6++++++
Mlisp/init-dired.el | 2+-
Mlisp/init-edit.el | 32+++++++++++++++++++-------------
Mlisp/init-exwm.el | 34++++++++++++++++------------------
Mlisp/init-gptel.el | 8++++----
Mlisp/init-kbd.el | 53++++++++++++++++++++++++++++++++++++-----------------
Mlisp/init-org.el | 45++++++++++++++++++++++-----------------------
Mlisp/init-package.el | 75++++++++++++++++++++++++++++++---------------------------------------------
Mlisp/init-prog.el | 15++++++---------
Mlisp/init-ui.el | 112++++++++++++++++++++++++++++++++++++++-----------------------------------------
Mlisp/init-window.el | 8++++----
13 files changed, 263 insertions(+), 259 deletions(-)

diff --git a/lisp/init-base.el b/lisp/init-base.el @@ -28,17 +28,19 @@ ;; benchmark (my-use-package benchmark-init - :hook - (after-init . benchmark-init/deactivate)) + :init + (add-hook 'after-init-hook #'benchmark-init/deactivate 100)) ;; server-mode -(my-use-package server +(my-use-package server my-enable-server :straight nil :demand t :hook - (emacs-startup . (lambda () - (unless (server-running-p) - (server-mode 1))))) + (emacs-startup . my-enable-server) + :init + (defun my-enable-server () + (unless (server-running-p) + (server-mode 1)))) ;; recently opened files (my-use-package recentf @@ -81,14 +83,14 @@ ;; async (my-use-package async (not *is-android*) :hook - (after-init . dired-async-mode)) + (dired-mode . dired-async-mode)) ;; autorevert buffer (my-use-package autorevert :straight nil :delight :hook - (after-init . global-auto-revert-mode)) + (find-file . global-auto-revert-mode)) ;; display keybindings (my-use-package which-key @@ -107,6 +109,10 @@ ;; ibuffer (my-use-package ibuffer :straight nil + :hook + (ibuffer . my-ibuffer-setup) + :init + (defun my-ibuffer-setup () (ibuffer-switch-to-saved-filter-groups "Main")) :config (setq ibuffer-saved-filter-groups '(("Main" @@ -225,10 +231,6 @@ (name . "\\*Ediff Registry\\*"))) ("Process" (predicate get-buffer-process (current-buffer)))))) - (defun my-ibuffer-setup () - (ibuffer-switch-to-saved-filter-groups "Main")) - (add-hook 'ibuffer-hook #'my-ibuffer-setup) - (setq ibuffer-formats '((mark modified read-only locked " " (name 55 55 :left :elide) @@ -257,12 +259,13 @@ :init (setq scroll-preserve-screen-position t scroll-conservatively 101) + + (defun my-pixel-scroll-precision-hack (fun event) + (cl-letf (((symbol-function 'device-class) + (lambda (&rest _) 'mouse))) + (funcall fun event))) :config - (advice-add 'pixel-scroll-precision :around - (lambda (orig event) - (cl-letf (((symbol-function 'device-class) - (lambda (&rest _) 'mouse))) - (funcall orig event))))) + (advice-add 'pixel-scroll-precision :around #'my-pixel-scroll-precision-hack)) ;; eww (my-use-package eww @@ -288,8 +291,7 @@ :straight nil :init (setq speedbar-window-default-width 30) - :commands my-speedbar - :config + (defun my-speedbar () "Run `speedbar-get-focus' if current buffer is not speedbar, otherwise run `speedbar'" (interactive) @@ -312,6 +314,7 @@ (speedbar-contract-line) (speedbar-expand-line))) + :config (if (boundp 'speedbar-prefer-window) (setq speedbar-prefer-window t)) (setq speedbar-use-images nil) @@ -324,7 +327,8 @@ :straight nil :hook (isearch-mode-end . my-goto-match-beginning) - :config + (lazy-count-update . force-mode-line-update) + :init (defun my-goto-match-beginning () (when (and isearch-forward (not isearch-mode-end-hook-quit)) (goto-char isearch-other-end))) @@ -369,9 +373,16 @@ (default-value 'mode-line-format)) (setq-default mode-line-format (cons my-isearch-count--mode-line-construct - (default-value 'mode-line-format)))) + (default-value 'mode-line-format))))) - (add-hook 'lazy-count-update-hook #'force-mode-line-update)) +;; diff +(my-use-package diff-mode + :straight nil + :init + (defun my-diff-kill-ring-save-hack (fun &rest args) + (let ((major-mode 'diff-mode)) + (apply fun args))) + (advice-add #'diff-kill-ring-save :around #'my-diff-kill-ring-save-hack)) (provide 'init-base) ;;; init-base.el ends here diff --git a/lisp/init-completion.el b/lisp/init-completion.el @@ -24,13 +24,11 @@ ;; marginalia in minibuffer (my-use-package marginalia :hook - (after-init . marginalia-mode)) + (vertico-mode . marginalia-mode)) ;; search and navigation (my-use-package consult - :commands my-consult-org-agenda my-consult-git-grep-project consult-directory-externally - :commands consult-directory-externally my-open-current-directory my-consult-fd-home - :config + :init (defun my-consult-org-agenda (arg) "Jump to an active Org agenda heading. With prefix ARG, search for all agenda headings." @@ -76,6 +74,19 @@ With prefix ARG, search for all agenda headings." (default-directory "~/")) (consult-fd))) + (with-eval-after-load 'consult-register + ;; the default setting can't handle deleted buffers + (cl-defmethod consult-register--describe ((val (head buffer))) + "Describe buffer register VAL." + (let* ((buf (cdr val)) + (dead (and (bufferp buf) (not (buffer-live-p buf)))) + (name (cond ((bufferp buf) (or (buffer-name buf) "#<killed buffer>")) + ((stringp buf) buf) + (t "#<invalid>")))) + (list (propertize name 'face (if dead 'error 'consult-buffer)) + 'consult--type ?f 'multi-category `(buffer . ,buf))))) + + :config ;; set locate arguments (cond (*is-windows* @@ -104,18 +115,6 @@ With prefix ARG, search for all agenda headings." register-preview-function #'consult-register-format) (advice-add #'register-preview :override #'consult-register-window) - (with-eval-after-load 'consult-register - ;; the default setting can't handle deleted buffers - (cl-defmethod consult-register--describe ((val (head buffer))) - "Describe buffer register VAL." - (let* ((buf (cdr val)) - (dead (and (bufferp buf) (not (buffer-live-p buf)))) - (name (cond ((bufferp buf) (or (buffer-name buf) "#<killed buffer>")) - ((stringp buf) buf) - (t "#<invalid>")))) - (list (propertize name 'face (if dead 'error 'consult-buffer)) - 'consult--type ?f 'multi-category `(buffer . ,buf))))) - ;; delete unused buffer sources (delete 'consult-source-bookmark consult-buffer-sources) @@ -145,15 +144,7 @@ With prefix ARG, search for all agenda headings." ;; right-click (my-use-package embark - :commands embark-prefix-help-command :init - (setq prefix-help-command 'embark-prefix-help-command) - :config - (add-to-list 'display-buffer-alist - '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*" - nil - (window-parameters (mode-line-format . none)))) - (with-no-warnings (with-eval-after-load 'which-key (defun embark-which-key-indicator () @@ -179,33 +170,35 @@ targets." nil nil t (lambda (binding) (not (string-suffix-p "-argument" (cdr binding)))))))) - (setq embark-indicators - '(embark-which-key-indicator - embark-highlight-indicator)) - (defun embark-hide-which-key-indicator (fn &rest args) "Hide the which-key indicator immediately when using the completing-read prompter." (which-key--hide-popup-ignore-command) (let ((embark-indicators (remq #'embark-which-key-indicator embark-indicators))) - (apply fn args))) + (apply fn args))))) + (advice-add #'embark-completing-read-prompter :around #'embark-hide-which-key-indicator) - (advice-add #'embark-completing-read-prompter - :around #'embark-hide-which-key-indicator)))) + (setq prefix-help-command #'embark-prefix-help-command + embark-indicators '(embark-which-key-indicator embark-highlight-indicator)) + (add-to-list 'display-buffer-alist + '("\\`\\*Embark Collect \\(Live\\|Completions\\)\\*" + nil + (window-parameters (mode-line-format . none))))) ;; embark-consult (my-use-package embark-consult) ;; corfu (my-use-package corfu - :bind - (:map corfu-map - ("M-d" . corfu-popupinfo-documentation) - ("RET" . nil)) :hook - (after-init . global-corfu-mode) - (after-init . corfu-popupinfo-mode) - (after-init . corfu-history-mode) + (prog-mode . global-corfu-mode) + (prog-mode . corfu-popupinfo-mode) + (prog-mode . corfu-history-mode) + (eshell-mode . my-disable-corfu-auto) + (org-mode . my-disable-corfu-auto) + :init + (defun my-disable-corfu-auto () + (setq-local corfu-auto nil)) :config (setq corfu-auto t corfu-auto-prefix 2 @@ -219,16 +212,10 @@ targets." help-mode gud-mode vterm-mode) - t)) - (add-hook 'eshell-mode-hook #'my-disable-corfu-auto) - (add-hook 'org-mode-hook #'my-disable-corfu-auto) - (defun my-disable-corfu-auto () - (setq-local corfu-auto nil))) + t))) ;; cape (my-use-package cape - :commands cape-file cape-elisp-block cape-keyword - :autoload cape-wrap-nonexclusive cape-wrap-buster cape-wrap-silent :init (add-to-list 'completion-at-point-functions #'cape-dabbrev) (add-to-list 'completion-at-point-functions #'cape-file) diff --git a/lisp/init-custom.el b/lisp/init-custom.el @@ -17,6 +17,12 @@ :type 'boolean :group 'trogloxene) + +(defcustom my-enable-server nil + "Enable `server-mode' or not." + :type 'boolean + :group 'trogloxene) + (defcustom my-enable-dashboard nil "Enable `dashboard' or not." :type 'boolean diff --git a/lisp/init-dired.el b/lisp/init-dired.el @@ -29,7 +29,6 @@ (my-use-package dirvish :init (dirvish-override-dired-mode) - :config (defun my-dirvish-layout-toggle () "Toggle layout using the first recipe in `dirvish-layout-recipes' instead of the hardcoded fallback recipe." @@ -39,6 +38,7 @@ the hardcoded fallback recipe." (setf (dv-ff-layout dv) (car dirvish-layout-recipes))) (dirvish-layout-toggle))) + :config (if *is-android* (setq dirvish-default-layout nil dirvish-layout-recipes '((0 0 0.6)) diff --git a/lisp/init-edit.el b/lisp/init-edit.el @@ -79,7 +79,8 @@ ;; pinyinlib (my-use-package pinyinlib - :config + :autoload pinyinlib-build-regexp-string + :init (with-eval-after-load 'orderless (defun my/orderless-pinyin (component) (orderless-regexp @@ -89,8 +90,10 @@ ;; Chinese support for avy (my-use-package ace-pinyin :delight - :hook - (after-init . ace-pinyin-global-mode)) + :after avy + :demand t + :config + (ace-pinyin-global-mode)) ;; avy-zap (my-use-package avy-zap) @@ -102,24 +105,27 @@ ;; modal editing (my-use-package god-mode + :hook + (after-init-hook . which-key-enable-god-mode-support) + (post-command-hook . my-sync-line-numbers-with-god-mode) :init (if *is-android* (add-hook 'after-init-hook 'god-mode-all)) - (add-hook 'after-init-hook #'which-key-enable-god-mode-support) - :config - (setq god-mode-enable-function-key-translation nil - god-exempt-major-modes - (cl-union '(diff-mode exwm-mode) god-exempt-major-modes :test 'equal) - god-mode-lighter-string "THANK-GOD-MODE") - - (custom-set-faces '(god-mode-lighter ((t (:inherit error :weight bold))))) (defun my-sync-line-numbers-with-god-mode () - (let ((desired (if (and god-local-mode display-line-numbers-mode) + (let ((desired (if (and (bound-and-true-p god-local-mode) + display-line-numbers-mode) 'relative display-line-numbers-type))) (unless (or (eq display-line-numbers desired) (not display-line-numbers-mode)) (setq display-line-numbers desired)))) - (add-hook 'post-command-hook #'my-sync-line-numbers-with-god-mode)) + + :config + (setq god-mode-enable-function-key-translation nil + god-exempt-major-modes + (cl-union '(diff-mode exwm-mode) god-exempt-major-modes :test 'equal) + god-mode-lighter-string "THANK-GOD-MODE") + + (custom-set-faces '(god-mode-lighter ((t (:inherit error :weight bold)))))) (provide 'init-edit) ;;; init-edit.el ends here diff --git a/lisp/init-exwm.el b/lisp/init-exwm.el @@ -41,15 +41,9 @@ :hook (exwm-init . restart-fcitx5) (exwm-init . my-desktop-init) - :config + :init (setq pop-up-windows nil) (setq exwm-workspace-number 1) - (exwm-input-set-key (kbd "s-&") - (lambda (command) - (interactive (list (read-shell-command "$ "))) - (let ((display-buffer-alist - '((".*" . (display-buffer-no-window . nil))))) - (async-shell-command command)))) (defun my--exwm-switch-to-workspace (delta) (let ((target @@ -71,9 +65,21 @@ (if (= 1 (length exwm-workspace--list)) (message "No previous workspace"))) + (defun my-exwm-update-class () + (exwm-workspace-rename-buffer exwm-class-name)) + (add-hook 'exwm-update-class-hook #'my-exwm-update-class) + (global-set-key (kbd "s-]") #'my-exwm-next-workspace) (global-set-key (kbd "s-[") #'my-exwm-previous-workspace) + :config + (exwm-input-set-key (kbd "s-&") + (lambda (command) + (interactive (list (read-shell-command "$ "))) + (let ((display-buffer-alist + '((".*" . (display-buffer-no-window . nil))))) + (async-shell-command command)))) + (add-to-list 'global-mode-string '(:eval (propertize (format " WS:%d " exwm-workspace-current-index) 'face 'mode-line-emphasis)) @@ -135,11 +141,7 @@ (,(kbd "C-y") . [?\C-v]) (,(kbd "C-w") . [?\C-x]) (,(kbd "C-/") . [?\C-z]) - (,(kbd "C-?") . ,(kbd "C-S-z")))) - - (defun my-exwm-update-class () - (exwm-workspace-rename-buffer exwm-class-name)) - (add-hook 'exwm-update-class-hook #'my-exwm-update-class)) + (,(kbd "C-?") . ,(kbd "C-S-z"))))) (my-use-package desktop-environment my-enable-exwm :after exwm @@ -163,18 +165,14 @@ :straight (xdg-launcher :type git :host github - :repo "emacs-exwm/xdg-launcher") - :bind - (("s-SPC" . xdg-launcher-run-app))) + :repo "emacs-exwm/xdg-launcher")) (my-use-package launcher (and *is-mac* my-enable-unessentials) :straight (launcher :type git :host github - :repo "xiaoxinghu/launcher.el") - :bind - ("s-SPC" . launcher)) + :repo "xiaoxinghu/launcher.el")) (provide 'init-exwm) ;;; init-exwm.el ends here diff --git a/lisp/init-gptel.el b/lisp/init-gptel.el @@ -45,6 +45,7 @@ (setq gptel-model 'k3-256k gptel-backend (gptel-get-backend "gptel-Kimi-Code")) + :init (defun my-gptel--sanitize-filename (name) "Clean NAME into a safe kebab-case filename string." (let ((clean (downcase name))) @@ -109,8 +110,7 @@ explanations, no quotes, no punctuation, no file extension." (message "ERROR: File was not created: %s" file))))) (error (message "gptel save-session error: %S" err))))))) (unless (plist-get (gptel-fsm-info fsm) :callback) - (message "WARNING: gptel-request did not register callback!"))))) - (keymap-set gptel-mode-map "C-c C-s" #'my-gptel-save-session)) + (message "WARNING: gptel-request did not register callback!")))))) (my-use-package gptel-agent my-enable-unessentials :after gptel @@ -144,8 +144,7 @@ explanations, no quotes, no punctuation, no file extension." ;; pi-coding-agent (my-use-package pilish my-enable-unessentials - :commands my-pilish - :config + :init (defun my-pilish () "Run `pilish' in project root." (interactive) @@ -153,6 +152,7 @@ explanations, no quotes, no punctuation, no file extension." (default-directory (project-root proj))) (pilish))) + :config (add-hook 'pilish-session-browser-mode-hook (lambda () (setq pilish--session-browser-sort "recent" diff --git a/lisp/init-kbd.el b/lisp/init-kbd.el @@ -67,6 +67,7 @@ "M-g i" #'consult-imenu "M-g I" #'consult-imenu-multi "M-g M-i" #'consult-imenu + "C-x r b" #'consult-bookmark ;; window "C-M-<left>" #'shrink-window-horizontally @@ -79,16 +80,26 @@ "M-o" #'other-window "M-O" #'other-window-backward + ;; org + "C-c a" #'org-agenda + "C-c l" #'org-store-link + ;; other - [remap eval-expression] #'pp-eval-expression "C-h h" #'hyperbole - "C-x r b" #'consult-bookmark + "M-RET" #'my-hkey-either-lazy "C-;" #'embark-act "M-s M-b" #'eww-list-bookmarks "<f1>" #'eldoc-mouse-pop-doc-at-cursor "<f8>" #'emms-pause "<f7>" #'emms-previous - "<f9>" #'emms-next) + "<f9>" #'emms-next + [remap eval-expression] #'pp-eval-expression + [remap ispell-word] #'jinx-correct + [remap describe-function] #'helpful-callable + [remap describe-command] #'helpful-command + [remap describe-variable] #'helpful-variable + [remap describe-key] #'helpful-key + [remap describe-symbol] #'helpful-symbol) ;;; other keymaps @@ -102,10 +113,16 @@ "M-n" #'minibuffer-next-completion "M-p" #'minibuffer-previous-completion) +;; corfu +(general-def corfu-map + "M-d" #'corfu-popupinfo-documentation + "RET" nil) + ;; diff (general-def diff-mode-map "M-o" #'other-window - "M-m" #'my-back-to-indentation) + "M-m" #'my-back-to-indentation + "C-w" #'diff-kill-ring-save) ;; dired (general-def (dired-mode-map dirvish-mode-map) @@ -184,6 +201,10 @@ "p" #'previous-line "n" #'next-line) +;; flycheck +(general-def flycheck-command-map + "a" #'flycheck-annotate-mode) + ;; ghostel (general-def (ghostel-mode-map ghostel-semi-char-mode-map @@ -223,7 +244,8 @@ ;; help (general-def (help-mode-map helpful-mode-map) "p" #'previous-line - "n" #'next-line) + "n" #'next-line + "R" #'remove-hook-at-point) ;; hs-hide-mode (general-def hs-minor-mode-map @@ -505,19 +527,16 @@ ;;; other -;; org -(general-def - "C-c a" #'org-agenda - "C-c l" #'org-store-link) - -;; scratch buffer (if *is-mac* - (general-def "C-c <f12>" #'my-persp-scratch-buffer) - (general-def "C-c <delete>" #'my-persp-scratch-buffer)) - -;; fullscreen -(if *is-emacs-mac-port* - (general-def "<f12>" #'mac-toggle-frame-fullscreen)) + (general-def + "C-c <f12>" #'my-persp-scratch-buffer + "s-SPC" #'launcher) + (general-def + "C-c <delete>" #'my-persp-scratch-buffer + "s-SPC" #'xdg-launcher-run-app)) + +(when *is-emacs-mac-port* + (general-def "<f12>" #'mac-toggle-frame-fullscreen)) (provide 'init-kbd) ;;; init-kbd.el ends here diff --git a/lisp/init-org.el b/lisp/init-org.el @@ -9,6 +9,7 @@ (org-mode . org-indent-mode) (org-mode . visual-line-mode) (org-mode . electric-pair-local-mode) + (org-cycle-tab-first . my-org-tab-complete) :init (setq org-directory @@ -18,7 +19,6 @@ (*is-linux* "~/org/my-org-note") (*is-android* "~/storage/shared/my-org-note"))) - :config (defun my-org-tab-complete () (let ((completion-at-point-functions (cond ((or (save-excursion @@ -33,8 +33,8 @@ '(cape-elisp-block t)) (t nil)))) (completion-at-point))) - (add-hook 'org-cycle-tab-first-hook #'my-org-tab-complete) + :config (defvar org-hide-space-keywords '(("\\cc\\( \\)[*/_=~+]\\cc.*?[*/_=~+]" (0 (prog1 () (add-text-properties (match-beginning 1) (match-end 1) '(invisible t))))) @@ -83,19 +83,19 @@ ;; consult-denote (my-use-package consult-denote - :hook - (after-init . consult-denote-mode) - :init + :after denote + :demand t + :config + (consult-denote-mode) (setq consult-denote-buffer-sources nil)) ;; denote (my-use-package denote :hook - (after-init . denote-rename-buffer-mode) + (find-file . denote-rename-buffer-mode) (dired-mode . denote-dired-mode) - :commands my-denote-find-file my-denote-find-backlink-with-location my-org-dblock-update-all :autoload denote-retrieve-filename-identifier - :config + :init (defun my-denote-find-file (&optional arg) "Find file use denote-open-or-create." (interactive "P") @@ -144,7 +144,6 @@ (apply fun file file-type args))) (advice-add #'denote-link :around #'my-denote-link-image-fix) - :init (setq denote-directory org-directory denote-org-store-link-to-heading 'context denote-date-prompt-use-org-read-date t @@ -160,8 +159,7 @@ ;; extra tools for org (my-use-package denote-org - :commands my-denote-org-find-backlink-for-heading-with-location - :config + :init (defun my-denote-org-find-backlink-for-heading-with-location () "Like `denote-org-backlinks-for-heading' but with consult preview." (interactive) @@ -178,7 +176,7 @@ (setq denote-agenda-include-regexp "==agenda\\|==project") (with-eval-after-load 'org-agenda (denote-agenda-insinuate)) - :config + (defun my-denote-agenda-file-p (file) "Non-nil if FILE is a denote-agenda managed file." (and (string-prefix-p (denote-directory) (expand-file-name file)) @@ -195,10 +193,10 @@ ;; denote-journal (my-use-package denote-journal + :autoload denote-journal--date-in-interval-p :hook (calendar-mode . denote-journal-calendar-mode) - :commands my-denote-journal-open-entry my-denote-journal-find-file - :config + :init (defun my-denote-journal-path-to-existing-entry () "Return the path of current denote journal if it exists, otherwise return nil." (let* ((internal-date @@ -228,18 +226,18 @@ (denote-journal-new-or-existing-entry) (find-file entry)))) - (advice-add 'calendar-redraw :after #'denote-journal-calendar-mark-dates) - - :init (setq denote-journal-directory (concat denote-directory "/journal")) - (add-to-list 'recentf-exclude denote-journal-directory) (setq denote-journal-keyword nil) (setq denote-journal-signature "journal") - (setq denote-journal-keyword "daily")) + (setq denote-journal-keyword "daily") + (advice-add 'calendar-redraw :after #'denote-journal-calendar-mark-dates) + + :config + (add-to-list 'recentf-exclude denote-journal-directory)) ;; explore, maintain and visualise denote files (my-use-package denote-explore - :commands my-denote-explore-isolate-files-dired + :autoload denote-explore--idenitfy-isolated ;yes, it's a typo from upstream :config (setq denote-explore-isolated-ignore-keywords '("daily")) (require 'ansi-color) @@ -250,6 +248,7 @@ (face-foreground 'ansi-color-red) (face-foreground 'ansi-color-magenta))) + :init (defun my-denote-explore-isolate-files-dired () "Identify Denote files without (back)links." (interactive) @@ -271,11 +270,12 @@ (org-download :fork (:type git :host nil :repo "https://git.trogloxene.org/org-download.git")) :after org :demand t - :config + :init (defun my-org-download-image-dir-function () (expand-file-name "images/" (project-root (or (project-current nil) '(vc Git "./"))))) + (setq-default org-download-image-dir #'my-org-download-image-dir-function org-download-heading-lvl nil) (setq org-download-timestamp "%Y%m%dT%H%M%S--" @@ -374,8 +374,7 @@ ;; presentation (my-use-package org-tree-slide my-enable-unessentials - :commands my-org-tree-slide-start my-org-tree-slide-stop - :config + :init (defun my-org-tree-slide-start () "Start `org-tree-slide'." (interactive) diff --git a/lisp/init-package.el b/lisp/init-package.el @@ -11,8 +11,6 @@ (my-use-package jinx (not *is-windows*) :delight (jinx-mode " Jinx" jinx) - :bind - ([remap ispell-word] . jinx-correct) :config (setq jinx-languages "en_US") (add-to-list 'jinx-exclude-regexps '(t "\\cc")) @@ -36,14 +34,14 @@ :hook (eshell-load . ghostel-eshell-visual-command-mode) (ghostel-mode . (lambda () (cns-mode -1))) - :config + :init (defun my-ghostel-send-C-k-and-kill () "Send `C-k' to ghostel. Like normal Emacs `C-k'. Kill to end of line and put content in kill-ring." (interactive) (kill-ring-save (point) (line-end-position)) (ghostel-send-key "k" "ctrl")) - + :config (setq eshell-destroy-buffer-when-process-dies t ghostel-ssh-install-terminfo t) (defalias 'eshell/v 'eshell/ghostel)) @@ -58,7 +56,7 @@ Like normal Emacs `C-k'. Kill to end of line and put content in kill-ring." ;; shell (my-use-package shell :straight nil - :config + :init (defun my-setenv-local (var val buffer) (with-current-buffer buffer (unless (local-variable-p 'process-environment) @@ -93,7 +91,7 @@ Like normal Emacs `C-k'. Kill to end of line and put content in kill-ring." (my-use-package perspective :hook (after-init . persp-mode) - :config + :init (defun my-persp-scratch-buffer (arg) "Switch to the current perspective's scratch buffer. With a prefix ARG create a new *scratch* buffer." @@ -166,31 +164,30 @@ With a prefix ARG create a new *scratch* buffer." (dolist (buf buffers) (persp-set-buffer buf)))) + :config (setopt persp-mode-prefix-key (kbd "C-c p")) (general-def perspective-map "d" #'persp-kill) - (setq persp-switch-to-buffer-behavior 'switch persp-sort 'oldest) (with-eval-after-load 'consult (consult-customize consult-source-buffer :hidden t :default nil) - (add-to-list 'consult-buffer-sources persp-consult-source)) - (setq switch-to-prev-buffer-skip - (lambda (win buff bury-or-kill) - (or (not (persp-is-current-buffer buff)) - (cl-some (lambda (re) (string-match-p re (buffer-name buff))) - consult-buffer-filter)))) + (add-to-list 'consult-buffer-sources persp-consult-source) + (setq switch-to-prev-buffer-skip + (lambda (win buff bury-or-kill) + (or (not (persp-is-current-buffer buff)) + (cl-some (lambda (re) (string-match-p re (buffer-name buff))) + consult-buffer-filter))))) (setq persp-initial-frame-name "main")) ;; magit (my-use-package magit - :commands my-magit-toggle-parent-section - :config + :init (defun my-magit-toggle-parent-section () "Toggle parent magit section." (interactive) (magit-section-up) (magit-section-toggle (magit-section-at))) - + :config (setq magit-bind-magit-project-status nil) (unless *is-windows* (setq magit-diff-refine-hunk 'all))) @@ -215,7 +212,7 @@ With a prefix ARG create a new *scratch* buffer." (my-use-package vc :straight nil :commands vc-create-repo - :config + :init (defun my-vc-annotate-diff-current-revision () "Show the diff of the revision displayed in this vc-annotate buffer against its previous revision." @@ -246,7 +243,7 @@ against its previous revision." :straight (consult-vc :type git :repo "https://git.trogloxene.org/consult-vc.git") - :init + :config (setq consult-vc-annotate-revision-narrow-key-forward ?\] consult-vc-annotate-revision-narrow-key-backward ?\[)) @@ -273,8 +270,6 @@ against its previous revision." ;; emms (my-use-package emms my-enable-unessentials - :commands - (emms-playlist-mode-switch-buffer) :config (add-to-list 'recentf-exclude "~/.emacs.d/emms/history") (emms-all) @@ -289,15 +284,7 @@ against its previous revision." (my-use-package helpful my-enable-unessentials :straight (helpful :fork (:type git :host nil :repo "https://git.trogloxene.org/helpful.git")) - :bind - (([remap describe-function] . helpful-callable) - ([remap describe-command] . helpful-command) - ([remap describe-variable] . helpful-variable) - ([remap describe-key] . helpful-key) - ([remap describe-symbol] . helpful-symbol) - :map helpful-mode-map - ("R" . remove-hook-at-point)) - :config + :init (defun remove-hook-at-point () "Remove the hook at the point in the *Help* buffer." (interactive) @@ -340,6 +327,14 @@ against its previous revision." ;; process manager (my-use-package proced :straight nil + :init + (defun proced-sort-rss (&optional arg) + "Sort Proced buffer by time the command rss. +Prefix ARG controls sort order, see `proced-sort-interactive'." + (interactive (list (or current-prefix-arg 'no-arg)) proced-mode) + (proced-sort-interactive 'rss arg)) + (general-def proced-mode-map "s r" #'proced-sort-rss) + :config (setopt proced-auto-update-flag (if *is-windows* nil t) proced-goal-attribute nil @@ -353,14 +348,7 @@ against its previous revision." '(custom user pid ppid rss start (args comm)) '(custom user pid ppid sess tree pcpu pmem rss start time state (args comm)))) (setq proced-low-memory-usage-threshold 0.025 - proced-medium-memory-usage-threshold 0.125) - - (defun proced-sort-rss (&optional arg) - "Sort Proced buffer by time the command rss. -Prefix ARG controls sort order, see `proced-sort-interactive'." - (interactive (list (or current-prefix-arg 'no-arg)) proced-mode) - (proced-sort-interactive 'rss arg)) - (general-def proced-mode-map "s r" #'proced-sort-rss)) + proced-medium-memory-usage-threshold 0.125)) ;; syncthing (my-use-package syncthing my-enable-unessentials @@ -374,7 +362,7 @@ Prefix ARG controls sort order, see `proced-sort-interactive'." ;; pass (my-use-package pass my-enable-unessentials - :config + :init (defvar my-pass-meta-fields '("url" "username" "email") "List of pass metadata fields for completion.") @@ -434,7 +422,7 @@ Prefix ARG controls sort order, see `proced-sort-interactive'." ;; elfeed (my-use-package elfeed my-enable-unessentials - :config + :init (defun my-elfeed-search-preview-other-window () "Preview currently selected elfeed entry in another window." (interactive) @@ -443,7 +431,7 @@ Prefix ARG controls sort order, see `proced-sort-interactive'." display-buffer-pop-up-window)))) (current-prefix-arg '(4))) (call-interactively #'elfeed-search-show-entry))) - + :config (setq elfeed-curl-timeout 600) (setq-default elfeed-search-filter "")) @@ -452,8 +440,6 @@ Prefix ARG controls sort order, see `proced-sort-interactive'." ;; translator (my-use-package gt my-enable-unessentials - :bind - (([remap gt-buffer-render--keyboard-quit] . keyboard-quit)) :config (setq gt-default-translator (gt-translator @@ -463,8 +449,7 @@ Prefix ARG controls sort order, see `proced-sort-interactive'." ;; thesaurus (my-use-package synosaurus my-enable-unessentials - :autoload my-synosaurus-lookup - :config + :init (defun my-synosaurus-lookup (arg) "Lookup word in thesaurus. With a prefix ARG replace the word under the cursor by a synonym." @@ -472,7 +457,7 @@ With a prefix ARG replace the word under the cursor by a synonym." (if arg (call-interactively #'synosaurus-choose-and-replace) (call-interactively #'synosaurus-lookup))) - + :config (setq synosaurus-prefix nil synosaurus-choose-method 'default)) diff --git a/lisp/init-prog.el b/lisp/init-prog.el @@ -39,7 +39,7 @@ ;; consult-eglot (my-use-package consult-eglot - :config + :init (defun my-consult-eglot-hack (fun) (let ((consult-async-split-styles-alist '((none :function consult--split-none) @@ -54,17 +54,14 @@ :hook (prog-mode . flycheck-mode) :config - (global-flycheck-eglot-mode) - :bind - (:map flycheck-command-map - ("a" . flycheck-annotate-mode))) + (global-flycheck-eglot-mode)) + +(my-use-package consult-flycheck) (my-use-package flycheck-guile :hook (scheme-mode . (lambda () (require 'flycheck-guile)))) -(my-use-package consult-flycheck) - ;; scheme (my-use-package geiser :config @@ -81,7 +78,7 @@ (my-use-package markdown-mode :hook (markdown-mode . visual-line-mode) - :config + :init (defun markdown-cycle-parent-subtree() "Cycle parent markdown subtree." (interactive) @@ -91,7 +88,7 @@ (markdown-cycle)) (markdown-back-to-heading) (markdown-cycle))) - + :config (setq markdown-command "multimarkdown" markdown-fontify-code-blocks-natively t)) diff --git a/lisp/init-ui.el b/lisp/init-ui.el @@ -29,10 +29,9 @@ (my-use-package color-picker my-enable-unessentials :straight (color-picker :type git :host github :repo "zHaOdANiuu/color-picker.el") - :commands color-picker my-pick-color :config (setq color-picker-scale 2.0) - + :init (defun my-pick-color (arg) "Pick and insert color." (interactive "P") @@ -47,69 +46,66 @@ (my-use-package colorful-mode my-enable-unessentials :hook (prog-mode . colorful-mode) - :commands my-colorful-color-picker :config (setq colorful-use-prefix t colorful-only-strings 'only-prog) (add-to-list 'global-colorful-modes 'helpful-mode) - (when (display-graphic-p) - (require 'svg) - - (defvar color-picker-initial-color) - - (defun my-colorful--svg-img (color) - (let* ((sz (frame-char-width)) - (svg (svg-create sz sz))) - (svg-node svg 'rect - :x 1 :y 1 :width (- sz 2) :height (- sz 2) - :fill color :stroke "#ffffff" :stroke-width "0.5") - (svg-image svg :ascent 'center))) - - (defun my-colorful--ov-hex (ov) - "Return normalized hex color string of colorful overlay OV." - (when-let* ((c (overlay-get ov 'colorful--color))) - (pcase-let ((`(,r ,g ,b) (color-name-to-rgb c))) - (color-rgb-to-hex r g b 2)))) - - (defun my-colorful-color-picker (event) - "Pick color use color-picker." - (interactive "e") - (let* ((pos (event-start event)) - (xy (posn-x-y pos)) - (ov (colorful--find-overlay (posn-point pos)))) - (when ov - (let ((color-picker-initial-color - (or (my-colorful--ov-hex ov) color-picker-initial-color))) - (color-picker - :style 'simple :display 'frame - :x (car xy) :y (cdr xy) - :ok (lambda (picked) - (with-current-buffer (overlay-buffer ov) - (delete-region (overlay-start ov) (overlay-end ov)) - (insert picked)))))))) - - (defvar-keymap my-colorful--color-picker-map - "<mouse-1>" - #'my-colorful-color-picker) - - (defun colorful--colorize-match (color beg end kind face map) - "Overlay match with a face from BEG to END. + (require 'svg) + (defvar color-picker-initial-color) + + (defun my-colorful--svg-img (color) + (let* ((sz (frame-char-width)) + (svg (svg-create sz sz))) + (svg-node svg 'rect + :x 1 :y 1 :width (- sz 2) :height (- sz 2) + :fill color :stroke "#ffffff" :stroke-width "0.5") + (svg-image svg :ascent 'center))) + + (defun my-colorful--ov-hex (ov) + "Return normalized hex color string of colorful overlay OV." + (when-let* ((c (overlay-get ov 'colorful--color))) + (pcase-let ((`(,r ,g ,b) (color-name-to-rgb c))) + (color-rgb-to-hex r g b 2)))) + + (defun my-colorful-color-picker (event) + "Pick color use color-picker." + (interactive "e") + (let* ((pos (event-start event)) + (xy (posn-x-y pos)) + (ov (colorful--find-overlay (posn-point pos)))) + (when ov + (let ((color-picker-initial-color + (or (my-colorful--ov-hex ov) color-picker-initial-color))) + (color-picker + :style 'simple :display 'frame + :x (car xy) :y (cdr xy) + :ok (lambda (picked) + (with-current-buffer (overlay-buffer ov) + (delete-region (overlay-start ov) (overlay-end ov)) + (insert picked)))))))) + + (defvar-keymap my-colorful--color-picker-map + "<mouse-1>" + #'my-colorful-color-picker) + + (defun colorful--colorize-match (color beg end kind face map) + "Overlay match with a face from BEG to END. The background uses COLOR color value. The foreground is obtained from `readable-foreground-color'." - (let ((ov (make-overlay beg end))) - (overlay-put ov 'colorful--overlay t) - (overlay-put ov 'colorful--color-kind kind) - (overlay-put ov 'colorful--color color) - (overlay-put ov 'evaporate t) - (overlay-put ov - 'before-string - (propertize - " " - 'display (my-colorful--svg-img color) - 'keymap my-colorful--color-picker-map - 'pointer 'hand)) - (overlay-put ov 'face nil))))) + (let ((ov (make-overlay beg end))) + (overlay-put ov 'colorful--overlay t) + (overlay-put ov 'colorful--color-kind kind) + (overlay-put ov 'colorful--color color) + (overlay-put ov 'evaporate t) + (overlay-put ov + 'before-string + (propertize + " " + 'display (my-colorful--svg-img color) + 'keymap my-colorful--color-picker-map + 'pointer 'hand)) + (overlay-put ov 'face nil)))) ;; line numbers (my-use-package display-line-numbers diff --git a/lisp/init-window.el b/lisp/init-window.el @@ -100,9 +100,6 @@ (if *is-android* (general-def "C-M-w" #'my-popper-toggle-type-delete-other-window)) - :config - (popper-echo-mode 1) - (with-no-warnings (defun my-popper-fit-window-height (win) "Determine the height of popup window WIN by fitting it to the buffer's content." @@ -141,7 +138,10 @@ 'shell-mode 'term-mode)))) (delete-window window))))) - (advice-add #'keyboard-quit :before #'popper-close-window-hack))) + (advice-add #'keyboard-quit :before #'popper-close-window-hack)) + + :config + (popper-echo-mode 1)) ;; windmove (my-use-package windmove