From 988341e2df4951286ee6ba18a51a9268f534d8cf Mon Sep 17 00:00:00 2001 From: Marc Coquand Date: Sun, 6 Oct 2024 20:43:57 +0300 Subject: . --- emacs | 343 +++++++++++++++++++++++++++++++++++++----------------------------- 1 file changed, 190 insertions(+), 153 deletions(-) diff --git a/emacs b/emacs index 28f3257..3bc2eb3 100644 --- a/emacs +++ b/emacs @@ -8,20 +8,27 @@ (pixel-scroll-precision-mode) (tab-bar-mode) (delete-selection-mode 1) + + (fset 'yes-or-no-p 'y-or-n-p) -(setq-default frame-title-format '("%b")) + (setq inhibit-startup-screen t line-spacing 0.2 display-time-format "%a, %d/%m/%Y %H:%M" undo-limit 10000000 undo-outer-limit 20000000 + completion-cycle-threshold 5 + + ;; X integration + x-select-enable-clipboard t + x-select-enable-primary t ring-bell-function 'ignore) (display-time-mode) (line-number-mode) (column-number-mode) -(setq completion-cycle-threshold 5) (setq-default fill-column 80) +(setq-default frame-title-format '("%b")) ;; Put Emacs auto-save and backup files to /tmp (defconst emacs-tmp-dir (expand-file-name (format "emacs%d" (user-uid)) temporary-file-directory)) @@ -38,6 +45,7 @@ ;; Packages (setq package-list '( magit + nix-mode go-mode devdocs rec-mode @@ -74,97 +82,105 @@ (package-install package))) ;; Avy -(require 'avy) -(global-set-key (kbd "C-o") 'avy-goto-char-timer) - - -(setf (alist-get ? avy-dispatch-alist) 'avy-action-mark-to-char) -(define-key isearch-mode-map (kbd "M-o") 'avy-isearch) - -(defun avy-action-kill-whole-line (pt) - (save-excursion - (goto-char pt) - (kill-whole-line)) - (select-window - (cdr - (ring-ref avy-ring 0))) - t) - -(setf (alist-get ?k avy-dispatch-alist) 'avy-action-kill-stay - (alist-get ?K avy-dispatch-alist) 'avy-action-kill-whole-line) - - -(defun avy-action-copy-whole-line (pt) - (save-excursion - (goto-char pt) - (cl-destructuring-bind (start . end) - (bounds-of-thing-at-point 'line) - (copy-region-as-kill start end))) - (select-window - (cdr - (ring-ref avy-ring 0))) - t) - -(defun avy-action-yank-whole-line (pt) - (avy-action-copy-whole-line pt) - (save-excursion (yank)) - t) - -(setf (alist-get ?y avy-dispatch-alist) 'avy-action-yank - (alist-get ?w avy-dispatch-alist) 'avy-action-copy - (alist-get ?W avy-dispatch-alist) 'avy-action-copy-whole-line - (alist-get ?Y avy-dispatch-alist) 'avy-action-yank-whole-line) -(defun avy-action-copy-whole-line (pt) - (save-excursion - (goto-char pt) - (cl-destructuring-bind (start . end) - (bounds-of-thing-at-point 'line) - (copy-region-as-kill start end))) - (select-window - (cdr - (ring-ref avy-ring 0))) - t) - -(defun avy-action-yank-whole-line (pt) - (avy-action-copy-whole-line pt) - (save-excursion (yank)) - t) - -(setf (alist-get ?y avy-dispatch-alist) 'avy-action-yank - (alist-get ?w avy-dispatch-alist) 'avy-action-copy - (alist-get ?W avy-dispatch-alist) 'avy-action-copy-whole-line - (alist-get ?Y avy-dispatch-alist) 'avy-action-yank-whole-line) - -(defun avy-action-teleport-whole-line (pt) - (avy-action-kill-whole-line pt) - (save-excursion (yank)) t) - -(setf (alist-get ?t avy-dispatch-alist) 'avy-action-teleport - (alist-get ?T avy-dispatch-alist) 'avy-action-teleport-whole-line) - -(defun avy-action-mark-to-char (pt) - (activate-mark) - (goto-char pt)) - -(setf (alist-get ? avy-dispatch-alist) 'avy-action-mark-to-char) + +(use-package avy + :ensure t + :config + (global-set-key (kbd "C-o") 'avy-goto-char-timer) + (setf (alist-get ? avy-dispatch-alist) 'avy-action-mark-to-char) + (define-key isearch-mode-map (kbd "M-o") 'avy-isearch) + (defun avy-action-kill-whole-line (pt) + (save-excursion + (goto-char pt) + (kill-whole-line)) + (select-window + (cdr + (ring-ref avy-ring 0))) + t) + (setf (alist-get ?k avy-dispatch-alist) 'avy-action-kill-stay + (alist-get ?K avy-dispatch-alist) 'avy-action-kill-whole-line) + (defun avy-action-copy-whole-line (pt) + (save-excursion + (goto-char pt) + (cl-destructuring-bind (start . end) + (bounds-of-thing-at-point 'line) + (copy-region-as-kill start end))) + (select-window + (cdr + (ring-ref avy-ring 0))) + t) + (defun avy-action-yank-whole-line (pt) + (avy-action-copy-whole-line pt) + (save-excursion (yank)) + t) + + (setf (alist-get ?y avy-dispatch-alist) 'avy-action-yank + (alist-get ?w avy-dispatch-alist) 'avy-action-copy + (alist-get ?W avy-dispatch-alist) 'avy-action-copy-whole-line + (alist-get ?Y avy-dispatch-alist) 'avy-action-yank-whole-line) + (defun avy-action-copy-whole-line (pt) + (save-excursion + (goto-char pt) + (cl-destructuring-bind (start . end) + (bounds-of-thing-at-point 'line) + (copy-region-as-kill start end))) + (select-window + (cdr + (ring-ref avy-ring 0))) + t) + + (defun avy-action-yank-whole-line (pt) + (avy-action-copy-whole-line pt) + (save-excursion (yank)) + t) + + (setf (alist-get ?y avy-dispatch-alist) 'avy-action-yank + (alist-get ?w avy-dispatch-alist) 'avy-action-copy + (alist-get ?W avy-dispatch-alist) 'avy-action-copy-whole-line + (alist-get ?Y avy-dispatch-alist) 'avy-action-yank-whole-line) + + (defun avy-action-teleport-whole-line (pt) + (avy-action-kill-whole-line pt) + (save-excursion (yank)) t) + + (setf (alist-get ?t avy-dispatch-alist) 'avy-action-teleport + (alist-get ?T avy-dispatch-alist) 'avy-action-teleport-whole-line) + + (defun avy-action-mark-to-char (pt) + (activate-mark) + (goto-char pt)) + + (setf (alist-get ? avy-dispatch-alist) 'avy-action-mark-to-char)) ;; Expand Region -(require 'expand-region) -(global-set-key (kbd "C-.") 'er/expand-region) -(global-set-key (kbd "C-,") 'er/contract-region) -(global-set-key (kbd "C-h D") 'devdocs-lookup) + +(use-package expand-region + :ensure t + :init + (global-set-key (kbd "C-.") 'er/expand-region) + (global-set-key (kbd "C-,") 'er/contract-region)) + +(use-package devdocs + :ensure t + :init + (global-set-key (kbd "C-h D") 'devdocs-lookup)) + ;; Html (add-to-list 'auto-mode-alist '("\\.njk\\'" . html-mode)) ;; Markdown -(add-hook 'markdown-mode-hook 'variable-pitch-mode) -(add-hook 'markdown-mode-hook 'visual-line-mode) -(add-hook 'markdown-mode-hook 'markdown-toggle-url-hiding) -(add-hook 'markdown-mode-hook 'markdown-toggle-markup-hiding) -(add-hook 'markdown-mode-hook 'visual-line-mode) -(require 'markdown-mode) -(set-face-attribute 'markdown-code-face nil :inherit 'fixed-pitch) +(use-package markdown-mode + :ensure t + :config + (set-face-attribute 'markdown-code-face nil :inherit 'fixed-pitch) + :hook + ((markdown-mode . variable-pitch-mode) + (markdown-mode . markdown-toggle-url-hiding) + (markdown-mode . markdown-toggle-markup-hiding) + (markdown-mode . visual-line-mode))) + + ;; Pairs (electric-pair-mode 1) @@ -179,16 +195,27 @@ ;; Eglot -(require 'eglot) -(define-key eglot-mode-map (kbd "C-c r") 'eglot-rename) -(define-key eglot-mode-map (kbd "C-c o") 'eglot-code-actions) -(define-key eglot-mode-map (kbd "C-c h") 'eldoc) +(use-package nix-mode + :ensure t + :hook + ((before-save . nix-format-buffer) + (nix-mode . nix-prettify-mode))) -(add-hook 'go-mode-hook 'eglot-ensure) +(use-package eglot + :config + ;; Ensure `nil` is in your PATH. + (add-to-list 'eglot-server-programs '(nix-mode . ("nil"))) + (define-key eglot-mode-map (kbd "C-c r") 'eglot-rename) + (define-key eglot-mode-map (kbd "C-c o") 'eglot-code-actions) + (define-key eglot-mode-map (kbd "C-c h") 'eldoc) + (set 'eldoc-print-after-edit t) + (global-eldoc-mode t) + (setq eldoc-echo-area-prefer-doc-buffer t) + + :hook + (nix-mode . eglot-ensure) + (go-mode . eglot-ensure)) -(set 'eldoc-print-after-edit t) -(global-eldoc-mode t) -(setq eldoc-echo-area-prefer-doc-buffer t) (setq make-backup-files nil) @@ -196,14 +223,12 @@ :ensure t :hook ((before-save . eglot-format-buffer))) + ;; HTML (add-hook 'html-mode-hook (lambda() (setq sgml-basic-offset 8) (setq indent-tabs-mode t))) -;; X integration -(setq x-select-enable-clipboard t) -(setq x-select-enable-primary t) (add-to-list 'load-path "~/.emacs.d/elisp") (add-to-list 'custom-theme-load-path "~/.emacs.d/themes") @@ -236,66 +261,78 @@ mastodon-instance-url "https://fosstodon.org") ;; Org +(use-package org + :ensure t + :init + (global-set-key (kbd "C-c l") #'org-store-link) + (global-set-key (kbd "C-c a") #'org-agenda) + (global-set-key (kbd "C-c c") #'org-capture) + (global-set-key (kbd "C-c s") #'project-find-regexp) + (setq org-agenda-files '("~/personal-db/notes") + org-refile-targets + '((nil :maxlevel . 2) + (org-agenda-files :maxlevel . 2)) + org-default-notes-file "~/personal-db/todo.org" + org-hide-emphasis-markers t + org-agenda-inhibit-startup t + ;; Add /New Heading at the end for use + org-refile-allow-creating-parent-nodes 'confirm + org-outline-path-complete-in-steps nil + org-refile-use-outline-path 'file + ;; Otherwise looks weird in variable-pitch-mode + org-tags-column 0 + org-log-done 'time) + + (add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)) + + (org-babel-do-load-languages + 'org-babel-load-languages + '((shell . t))) + + (setq org-capture-templates + '( + ("t" "Todo" + entry (file+headline "~/personal-db/todo.org" "Todo") + "* TODO %?\n%i\n%a\n%T\n " + :empty-lines 1) + ("l" "Log" entry (file+datetree "~/personal-db/notes/log.org") + "* %?\n%T\n" + :empty-lines 1) + ("n" "Inbox" + entry (file+headline "~/personal-db/notes/inbox.org" "Notes") + "** %?\n%T" + :empty-lines 1))) + + :config + (set-face-attribute 'org-block nil :inherit 'fixed-pitch) + (set-face-attribute 'org-code nil :inherit 'fixed-pitch) + (set-face-attribute 'org-table nil :inherit 'fixed-pitch) + + :hook + ((org-mode . auto-save-mode)) + (org-mode . org-indent-mode) + (org-mode . visual-line-mode) + (org-mode . variable-pitch-mode) + (org-agenda-mode . + (lambda () + (add-hook 'auto-save-hook 'org-save-all-org-buffers nil t) + (auto-save-mode)))) -(global-set-key (kbd "C-c l") #'org-store-link) -(global-set-key (kbd "C-c a") #'org-agenda) -(global-set-key (kbd "C-c c") #'org-capture) -(global-set-key (kbd "C-c s") #'project-find-regexp) - -(require 'org) -(add-hook 'org-agenda-mode-hook - (lambda () - (add-hook 'auto-save-hook 'org-save-all-org-buffers nil t) - (auto-save-mode))) -(setq org-agenda-files '("~/personal-db/notes")) -(setq org-refile-targets - '((nil :maxlevel . 2) - (org-agenda-files :maxlevel . 2))) -(setq org-default-notes-file "~/personal-db/todo.org") -(setq org-log-done 'time) -(add-to-list 'auto-mode-alist '("\\.org\\'" . org-mode)) -(add-hook 'org-mode-hook 'org-indent-mode) -(add-hook 'org-mode-hook 'visual-line-mode) -(add-hook 'org-mode-hook 'variable-pitch-mode) -(setq org-hide-emphasis-markers t) -(set-face-attribute 'org-block nil :inherit 'fixed-pitch) -(set-face-attribute 'org-code nil :inherit 'fixed-pitch) -(set-face-attribute 'org-table nil :inherit 'fixed-pitch) -(setq org-agenda-inhibit-startup t) - -(org-babel-do-load-languages -'org-babel-load-languages -'((shell . t))) - -;; Add /New Heading at the end for use -(setq org-refile-allow-creating-parent-nodes 'confirm) -(setq org-outline-path-complete-in-steps nil) -(setq org-refile-use-outline-path 'file) -;; Otherwise looks weird in variable-pitch-mode -(setq org-tags-column 0) - -(setq org-capture-templates - '( - ("t" "Todo" - entry (file+headline "~/personal-db/todo.org" "Todo") - "* TODO %?\n%i\n%a\n%T\n " - :empty-lines 1) - ("l" "Log" entry (file+datetree "~/personal-db/notes/log.org") - "* %?\n%T\n" - :empty-lines 1) - ("n" "Inbox" - entry (file+headline "~/personal-db/notes/inbox.org" "Notes") - "** %?\n%T" - :empty-lines 1))) ;; Magit -(require 'magit) -(require 'magit-extras) -(global-set-key (kbd "C-c g") 'magit) +(use-package magit + :ensure t + :init + (global-set-key (kbd "C-c g") 'magit)) + +(use-package magit-extras) ;; Yasnippet -(require 'yasnippet) -(yas-global-mode 1) +(use-package yasnippet + :ensure t + :init + (yas-global-mode 1)) + ;; Mu4e (defun marc/set-msmtp-account () @@ -483,7 +520,7 @@ '("~/personal-db/notes/carving-my-own-road.org" "/home/mccd/personal-db/notes/emacs-teaches.org" "/home/mccd/personal-db/notes/agency-and-tech.org" "/home/mccd/personal-db/notes/log.org" "/home/mccd/builds/sustainably/piva.org" "/home/mccd/builds/comma.directory/comma.org" "/home/mccd/personal-db/notes/frugal.org" "/home/mccd/personal-db/notes/inbox.org" "/home/mccd/personal-db/notes/emacs.org" "/home/mccd/personal-db/todo.org")) '(org-fold-core-style 'overlays) '(package-selected-packages - '(avy pdf-tools elfeed-protocol lem yasnippet-snippets elfeed yasnippet smartparens markdown-mode mastodon tldr almost-mono-themes rec-mode magit go-mode expand-region devdocs)) + '(nix-mode nix-ts-mode avy pdf-tools elfeed-protocol lem yasnippet-snippets elfeed yasnippet smartparens markdown-mode mastodon tldr almost-mono-themes rec-mode magit go-mode expand-region devdocs)) '(tab-bar-format '(tab-bar-separator tab-bar-format-align-right tab-bar-format-global)) '(yank-from-kill-ring-rotate t)) -- cgit v1.2.3