home

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 3f89e71053c80f8119bb191d182b7bd5603060bb
parent d05ed095401d62fb9c568a01ac5e12422dbfe8d2
Author: Vincent Demeester <vincent@sbr.pm>
Date:   Wed,  6 Jan 2021 18:02:53 +0100

tools/emacs: experimenting with lightweight…

… emacs configuration.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>

Diffstat:
Atools/emacs/foo.el | 174+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtools/emacs/init.el | 6+++---
Mtools/emacs/lisp/init-func.el | 3+--
Atools/emacs/small-init.el | 130+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Musers/vincent/dev/emacs.nix | 7+++----
5 files changed, 311 insertions(+), 9 deletions(-)

diff --git a/tools/emacs/foo.el b/tools/emacs/foo.el @@ -0,0 +1,174 @@ + +(require 'package) + +(setq package-archives + '(("melpa" . "http://melpa.org/packages/") + ("org" . "https://orgmode.org/elpa/") + ("gnu" . "https://elpa.gnu.org/packages/"))) + +(setq package-archive-priorities + '(("melpa" . 3) + ("org" . 2) + ("gnu" . 1))) + +(require 'tls) + +;; From https://github.com/hlissner/doom-emacs/blob/5dacbb7cb1c6ac246a9ccd15e6c4290def67757c/core/core-packages.el#L102 +(setq gnutls-verify-error (not (getenv "INSECURE")) ; you shouldn't use this + tls-checktrust gnutls-verify-error + tls-program (list "gnutls-cli --x509cafile %t -p %p %h" + ;; compatibility fallbacks + "gnutls-cli -p %p %h" + "openssl s_client -connect %h:%p -no_ssl2 -no_ssl3 -ign_eof")) + +;; Initialise the packages, avoiding a re-initialisation. +(unless (bound-and-true-p package--initialized) + (setq package-enable-at-startup nil) + (package-initialize)) + +(setq load-prefer-newer t) ; Always load newer compiled files +(setq ad-redefinition-action 'accept) ; Silence advice redefinition warnings + +;; Init `delight' +(unless (package-installed-p 'delight) + (package-refresh-contents) + (package-install 'delight)) + +;; Configure `use-package' prior to loading it. +(eval-and-compile + (setq use-package-always-ensure nil) + (setq use-package-always-defer nil) + (setq use-package-always-demand nil) + (setq use-package-expand-minimally nil) + (setq use-package-enable-imenu-support t)) + +(unless (package-installed-p 'use-package) + (package-refresh-contents) + (package-install 'use-package)) + +(eval-when-compile + (require 'use-package)) + +(use-package orderless + :unless noninteractive + :config + (setq orderless-regexp-separator " +") + (setq orderless-matching-styles + '(orderless-flex + orderless-strict-leading-initialism + orderless-regexp + orderless-prefixes + orderless-literal)) + + (defun prot/orderless-literal-dispatcher (pattern _index _total) + (when (string-suffix-p "=" pattern) + `(orderless-literal . ,(substring pattern 0 -1)))) + + (defun prot/orderless-initialism-dispatcher (pattern _index _total) + (when (string-suffix-p "," pattern) + `(orderless-strict-leading-initialism . ,(substring pattern 0 -1)))) + + (setq orderless-style-dispatchers '(prot/orderless-literal-dispatcher + prot/orderless-initialism-dispatcher)) + :bind (:map minibuffer-local-completion-map + ("SPC" . nil))) ; space should never complete +(use-package marginalia + :config + (marginalia-mode 1) + (setq marginalia-annotators '(marginalia-annotators-heavy + marginalia-annotators-light)) + ;;:bind (:map minibuffer-local-completion-map + ;; ("C-i" . marginalia-cycle-annotators)) + ) + +(use-package minibuffer + :config + (setq completion-styles '(orderless partial-completion)) + (setq completion-category-defaults nil) + (setq completion-cycle-threshold 3) + (setq completion-flex-nospace nil) + (setq completion-pcm-complete-word-inserts-delimiters t) + (setq completion-pcm-word-delimiters "-_./:| ") + (setq completion-show-help nil) + (setq completion-ignore-case t) + (setq-default case-fold-search nil) ; For general regexp + + ;; The following two are updated in Emacs 28. They concern the + ;; *Completions* buffer. + (setq completions-format 'one-column) + (setq completions-detailed t) + + (setq read-buffer-completion-ignore-case t) + (setq read-file-name-completion-ignore-case t) + + (setq enable-recursive-minibuffers t) + (setq read-answer-short t) + (setq resize-mini-windows t) + (setq minibuffer-eldef-shorten-default t) + + (file-name-shadow-mode 1) + (minibuffer-depth-indicate-mode 1) + (minibuffer-electric-default-mode 1) + + ;; Defines, among others, aliases for common minibuffer commands to + ;; Super-KEY. Normally these should go in individual package + ;; declarations, but their grouping here makes things easier to + ;; understand. Besides, they are related to the minibuffer. + :bind (("s-b" . switch-to-buffer) + ("s-B" . switch-to-buffer-other-window) + ("s-f" . find-file) + ("s-F" . find-file-other-window) + ("s-d" . dired) + ("s-D" . dired-other-window) + :map completion-list-mode-map + ("n" . next-line) + ("p" . previous-line) + ("f" . next-completion) + ("b" . previous-completion))) +(use-package consult + :config + (setq consult-line-numbers-widen t) + (setq consult-preview-buffer nil) + (setq consult-preview-grep t) + (setq consult-preview-mark t) + (setq consult-preview-line t) + (setq consult-preview-outline nil) + (setq completion-in-region-function #'consult-completion-in-region) + (setq consult-async-input-debounce 0.5) + (setq consult-async-input-throttle 0.8) + (consult-preview-mode 1) + :bind (("M-X" . consult-mode-command) + ("M-s i" . consult-imenu) + ("M-s s" . consult-outline) ; M-s o is `occur' + ("M-s M-s" . consult-outline) + ("M-s m" . consult-mark) + ("M-s l" . consult-line) + :map minibuffer-local-completion-map + ("<tab>" . minibuffer-force-complete))) + +(use-package embark + :ensure t + :after minibuffer + :config + (setq embark-occur-initial-view-alist '((t . zebra))) + (setq embark-occur-minibuffer-completion t) + (setq embark-live-occur-update-delay 0.5) + (setq embark-live-occur-initial-delay 0.8) + (setq embark-annotator-alist '((t . embark-annotation-function-metadatum))) + :hook (minibuffer-setup-hook . embark-live-occur-after-input) + :bind (("C-," . embark-act) + :map minibuffer-local-completion-map + ("C-," . embark-act) + ("C-." . embark-act-noexit) + ("M-q" . embark-occur-toggle-view) ; parallel of `fill-paragraph' + ("M-o" . embark-export) ; falls back to `embark-occur' + ("C-o" . embark-export) + ("M-v" . embark-switch-to-live-occur) + :map embark-occur-mode-map + ("," . embark-act) + ("M-o" . embark-export) + ("C-o" . embark-export) + ("M-t" . toggle-truncate-lines) + ("M-q" . embark-occur-toggle-view) + ;; ("M-v" . prot-minibuffer-focus-mini) ; from `prot-minibuffer.el' + ("M-q" . embark-occur-toggle-view))) diff --git a/tools/emacs/init.el b/tools/emacs/init.el @@ -102,13 +102,13 @@ load-path)) (defun vde/el-load-dir (dir) - "Load el files from the given folder" + "Load el files from the given folder `DIR'." (let ((files (directory-files dir nil "\.el$"))) (while files (load-file (concat dir (pop files)))))) (defun vde/short-hostname () - "Return hostname in short (aka wakasu.local -> wakasu)" + "Return hostname in short (aka wakasu.local -> wakasu)." (string-match "[0-9A-Za-z-]+" system-name) (substring system-name (match-beginning 0) (match-end 0))) @@ -127,7 +127,7 @@ "Are you a ROOT user?") (defconst *nix* (executable-find "nix") - "Do we have nix? (aka are we running in NixOS or a system using nixpkgs)") + "Do we have nix? (aka are we running in NixOS or a system using nixpkgs).") (defconst *rg* (executable-find "rg") "Do we have ripgrep?") diff --git a/tools/emacs/lisp/init-func.el b/tools/emacs/lisp/init-func.el @@ -1,6 +1,6 @@ ;;; init-func.el --- -*- lexical-binding: t -*- ;; -;; OrgIncludeAuto + ;; https://endlessparentheses.com/updating-org-mode-include-statements-on-the-fly.html (defun save-and-update-includes () "Update the line numbers of #+INCLUDE:s in current buffer. @@ -45,7 +45,6 @@ BEGIN and END are regexps which define the line range to use." (search-forward-regexp end) (setq r (1+ (line-number-at-pos (match-end 0))))) (format "%s-%s" (+ l 1) (- r 1)))))) ;; Exclude wrapper -;; -OrgIncludeAuto (provide 'init-func) ;;; init-func.el ends here diff --git a/tools/emacs/small-init.el b/tools/emacs/small-init.el @@ -0,0 +1,130 @@ +(defconst emacs-start-time (current-time)) + +(let ((minver 26)) + (unless (>= emacs-major-version minver) + (error "Your Emacs is too old -- this configuration requires v%s or higher" minver))) + +;; load early-init.el before Emacs 27.0 +(unless (>= emacs-major-version 27) + (message "Early init: Emacs Version < 27.0") + (load (expand-file-name "early-init.el" user-emacs-directory))) + +(setq inhibit-default-init t) ; Disable the site default settings + +(setq inhibit-startup-message t + inhibit-startup-screen t) + +(setq confirm-kill-emacs #'y-or-n-p) +(setq initial-major-mode 'fundamental-mode + initial-scratch-message nil) + +(prefer-coding-system 'utf-8) +(set-default-coding-systems 'utf-8) +(set-language-environment 'utf-8) +(set-selection-coding-system 'utf-8) +(set-terminal-coding-system 'utf-8) + +(require 'package) + +(setq package-archives + '(("melpa" . "http://melpa.org/packages/") + ("org" . "https://orgmode.org/elpa/") + ("gnu" . "https://elpa.gnu.org/packages/"))) + +(setq package-archive-priorities + '(("melpa" . 3) + ("org" . 2) + ("gnu" . 1))) + +(require 'tls) + +;; From https://github.com/hlissner/doom-emacs/blob/5dacbb7cb1c6ac246a9ccd15e6c4290def67757c/core/core-packages.el#L102 +(setq gnutls-verify-error (not (getenv "INSECURE")) ; you shouldn't use this + tls-checktrust gnutls-verify-error + tls-program (list "gnutls-cli --x509cafile %t -p %p %h" + ;; compatibility fallbacks + "gnutls-cli -p %p %h" + "openssl s_client -connect %h:%p -no_ssl2 -no_ssl3 -ign_eof")) + +;; Initialise the packages, avoiding a re-initialisation. +(unless (bound-and-true-p package--initialized) + (setq package-enable-at-startup nil) + (package-initialize)) + +(setq load-prefer-newer t) ; Always load newer compiled files +(setq ad-redefinition-action 'accept) ; Silence advice redefinition warnings + +;; Init `delight' +(unless (package-installed-p 'delight) + (package-refresh-contents) + (package-install 'delight)) + +;; Configure `use-package' prior to loading it. +(eval-and-compile + (setq use-package-always-ensure nil) + (setq use-package-always-defer nil) + (setq use-package-always-demand nil) + (setq use-package-expand-minimally nil) + (setq use-package-enable-imenu-support t)) + +(unless (package-installed-p 'use-package) + (package-refresh-contents) + (package-install 'use-package)) + +(eval-when-compile + (require 'use-package)) + +(defconst vde/custom-file (locate-user-emacs-file "custom.el") + "File used to store settings from Customization UI.") + +(use-package cus-edit + :config + (setq + custom-file vde/custom-file + custom-buffer-done-kill nil ; Kill when existing + custom-buffer-verbose-help nil ; Remove redundant help text + custom-unlispify-tag-names nil ; Show me the real variable name + custom-unlispify-menu-entries nil) + (unless (file-exists-p custom-file) + (write-region "" nil custom-file)) + + (load vde/custom-file 'no-error 'no-message)) + +;; Remove built-in org-mode +(require 'cl-seq) +(setq load-path + (cl-remove-if + (lambda (x) + (string-match-p "org$" x)) + load-path)) + +(defun vde/el-load-dir (dir) + "Load el files from the given folder `DIR'." + (let ((files (directory-files dir nil "\.el$"))) + (while files + (load-file (concat dir (pop files)))))) + +(defun vde/short-hostname () + "Return hostname in short (aka wakasu.local -> wakasu)." + (string-match "[0-9A-Za-z-]+" system-name) + (substring system-name (match-beginning 0) (match-end 0))) + +(add-to-list 'load-path (concat user-emacs-directory "lisp/")) +(add-to-list 'load-path (concat user-emacs-directory "lisp/vorg")) +(require 'init-func) +;; (vde/el-load-dir (concat user-emacs-directory "/config/")) +;; +;; (if (file-exists-p (downcase (concat user-emacs-directory "/hosts/" (vde/short-hostname) ".el"))) +;; (load-file (downcase (concat user-emacs-directory "/hosts/" (vde/short-hostname) ".el")))) + +(let ((elapsed (float-time (time-subtract (current-time) + emacs-start-time)))) + (message "Loading %s...done (%.3fs)" load-file-name elapsed)) + +(add-hook 'after-init-hook + `(lambda () + (let ((elapsed + (float-time + (time-subtract (current-time) emacs-start-time)))) + (message "Loading %s...done (%.3fs) [after-init]" + ,load-file-name elapsed))) t) diff --git a/users/vincent/dev/emacs.nix b/users/vincent/dev/emacs.nix @@ -7,10 +7,6 @@ let #!${pkgs.stdenv.shell} emacsclient -n -F '((name . "capture") (width . 150) (height . 90))' -e '(org-capture)' ''; - e = pkgs.writeScriptBin "e" '' - #!${pkgs.stdenv.shell} - emacs --dump-file=~/.config/emacs/emacs.pdmp $@ - ''; et = pkgs.writeScriptBin "et" '' #!${pkgs.stdenv.shell} emacsclient --tty $@ @@ -31,6 +27,7 @@ let company company-emoji company-go + consult dash delight diredfl @@ -42,6 +39,7 @@ let dumb-jump easy-kill edit-indirect + embark envrc esh-autosuggest eshell-prompt-extras @@ -73,6 +71,7 @@ let magit magit-annex magit-popup + marginalia markdown-mode minions modus-operandi-theme