From e7305993579abf4c86045aa6654260a57131f9e5 Mon Sep 17 00:00:00 2001 From: Madeleine Sydney Date: Mon, 17 Feb 2025 21:36:30 -0700 Subject: [PATCH] feat(emacs): Spell-checking - Uses Aspell and Jinx. --- README.org | 24 ++++--- users/crumb/programs/emacs.nix | 66 ++++++++++++------- .../programs/emacs/lib/syd-handle-lookup.el | 4 +- users/crumb/programs/emacs/lib/syd-prose.el | 27 +++++++- users/crumb/programs/emacs/modules/syd-org.el | 4 +- 5 files changed, 89 insertions(+), 36 deletions(-) diff --git a/README.org b/README.org index c740868..b8157c6 100755 --- a/README.org +++ b/README.org @@ -41,7 +41,7 @@ Where =configuration.nix= is the main entry point imported by the top-level flak *** =users/= -Similarly to the =hosts= directory, each subdirectory =users/«USER»= is assumed to have some structure, and that =«USER»= is the precise username desired. +Similarly to the =hosts= directory, each sub-directory =users/«USER»= is assumed to have some structure, and that =«USER»= is the precise username desired. #+begin_example users @@ -153,11 +153,11 @@ As with the rest of the config, these are largely adapted from Doom's ([cite:@li * Hosts -** nixos-testbed +** =nixos-testbed= -Configuration for the VM I'm currently using as a testbed, before moving to my real desktop. +Configuration for the VM I'm currently using as a test-bed, before moving to my real desktop. -** deertopia +** =deertopia= My home server. @@ -302,9 +302,9 @@ CLOSED: [2025-01-16 Thu 18:19] *** TODO Prose minor mode -**** TODO Grammar-checking +**** HOLD Grammar-checking -**** TODO Spell-checking +**** DONE Spell-checking *** DONE Lookup handlers CLOSED: [2025-02-01 Sat 16:56] @@ -407,7 +407,7 @@ CLOSED: [2024-11-14 Thu 04:46] **** grammar -**** spellcheck and dictionaries +**** DONE spellcheck and dictionaries **** org-mode @@ -533,7 +533,7 @@ CLOSED: [2024-12-29 Sun 01:41] ** DONE git config CLOSED: [2024-12-30 Mon 17:01] -** TODO niri +** TODO Niri Or Qtile @@ -639,9 +639,9 @@ List persistent files per user, and show their mount strategy. Following is a subset of the many places I've learnt from. Most important of all are Doom Emacs and Faye's Wishsys. -Doom Emacs was my gateway drug to Emacs, as well as continually supportive parent as I've begun to move out — of course, that's a flowerism obfuscating the more direct statement "I've stolen a great deal of their code" }:). +Doom Emacs was my gateway drug to Emacs, as well as a continually supportive parent as I've begun to move out — of course, that's a flowerism obfuscating the more direct statement "I've stolen a great deal of their code" }:). -The beloved Faye's Wishsys is an incredibly impressive 3-kloc NixOS config with several hosts, users, and a beautiful level of modularity. Her system has a number of quirks that initially raise eyebrows, but the questioning turns to awe once you understand she really knows what she's doing }:). Faye and her config are entirely responsible for inspiring and motivating my effort expent here, as well as being a wonderful reference as I re-learnt Nix from the ground up. In the most nerdy moment of my life, I've genuinely /swooned/ over this damn config. +The beloved Faye's Wishsys is an incredibly impressive 3-kloc NixOS config with several hosts, users, and a beautiful level of modularity. Her system has a number of quirks that initially raise eyebrows, but the questioning turns to awe once you understand she really knows what she's doing }:). Faye and her config are entirely responsible for inspiring and motivating my effort expended here, as well as being a wonderful reference as I re-learnt Nix from the ground up. In the most nerdy moment of my life, I've genuinely /swooned/ over this damn config. - My darling dearest Faye's =wishsys= }:D - [[https://github.com/rasendubi/dotfiles][rasendubi/dotfiles]] @@ -663,3 +663,7 @@ The beloved Faye's Wishsys is an incredibly impressive 3-kloc NixOS config with - [[https://github.com/noctuid/evil-guide][noctuid/evil-guide]] - [[https://github.com/drym-org/symex.el][symex.el]] - [[https://github.com/Fuco1/smartparens][Smartparens]] + +# Local Variables: +# jinx-local-words: "Wishsys" +# End: diff --git a/users/crumb/programs/emacs.nix b/users/crumb/programs/emacs.nix index 4386897..d92301a 100755 --- a/users/crumb/programs/emacs.nix +++ b/users/crumb/programs/emacs.nix @@ -33,35 +33,57 @@ let fontPackages = [ pkgs.julia-mono pkgs.nerd-fonts.victor-mono - # pkgs.overpass pkgs.ibm-plex ]; - emacsWrapper = pkgs.symlinkJoin { - name = "emacs-wrapper"; - paths = [ emacsPackage ]; - nativeBuildInputs = [ pkgs.makeWrapper ]; - buildInputs = [ - pkgs.git # Dependency of Straight.el. - ]; - postBuild = '' - # The binary called `emacs` is actually a symlink to `emacs-«version»`, so - # we needn't wrap it. - for i in $out/bin/emacs-*; do - wrapProgram "$i" \ - --add-flags "--init-directory \"${emacsConfigDir}\"" \ - --set EMACS_STRAIGHT_BASE_DIR "${straightBaseDir}" \ - --set EMACS_CACHE_DIR "${emacsCacheDir}" \ - --set EMACS_DATA_DIR "${emacsDataDir}" \ - --prefix PATH : "${pkgs.git}/bin" - done - ''; - }; + my-aspell = pkgs.aspellWithDicts + (dicts: with dicts; [ + en en-computers en-science + ]); + + emacsWrapper = + pkgs.symlinkJoin { + name = "emacs-wrapper"; + paths = [ emacsPackage ]; + nativeBuildInputs = [ pkgs.makeWrapper ]; + buildInputs = [ + pkgs.git # Dependency of Straight.el. + my-aspell + ]; + postBuild = '' + # The binary called `emacs` is actually a symlink to `emacs-«version»`, so + # we needn't wrap it. + for i in $out/bin/emacs-*; do + wrapProgram "$i" \ + --add-flags "--init-directory \"${emacsConfigDir}\"" \ + --set EMACS_STRAIGHT_BASE_DIR "${straightBaseDir}" \ + --set EMACS_CACHE_DIR "${emacsCacheDir}" \ + --set EMACS_DATA_DIR "${emacsDataDir}" \ + --prefix PATH : "${pkgs.git}/bin" \ + --prefix PATH : "${my-aspell}/bin" \ + --set ASPELL_CONF "dict-dir ${my-aspell}/lib/aspell" + done + + # HACK: Prevent collision between `emacsWrapper` and the later + # `emacsWithPackages` call. + # find $out/bin -not -regex '.*/\.?emacs[^/]*' -exec rm {} \; + ''; + meta = emacsPackage.meta; + version = emacsPackage.version; + }; emacsclient-or-emacs = pkgs.writeShellScriptBin "emacsclient-or-emacs" '' emacsclient --alternate-editor=${emacsWrapper}/bin/emacs "$@" ''; in { + programs.emacs = { + enable = true; + package = emacsWrapper; + extraPackages = epkgs: [ + epkgs.jinx + ]; + }; + sydnix.impermanence.cache.directories = # Impermanence expects the path to be relative to ~. map (lib.removePrefix config.home.homeDirectory) [ @@ -89,7 +111,7 @@ in { }; home.packages = [ - emacsWrapper + # emacsWrapper emacsclient-or-emacs ] ++ fontPackages; diff --git a/users/crumb/programs/emacs/lib/syd-handle-lookup.el b/users/crumb/programs/emacs/lib/syd-handle-lookup.el index d3ecb14..9b99e3a 100644 --- a/users/crumb/programs/emacs/lib/syd-handle-lookup.el +++ b/users/crumb/programs/emacs/lib/syd-handle-lookup.el @@ -10,7 +10,9 @@ `(("Kagi" . "https://kagi.com/search?q=%s") ("DuckDuckGo" . "https://duckduckgo.com/?q=%s") ("Nixpkgs" . "https://search.nixos.org/packages?query=%s") - ("Hackage" . "https://hackage.haskell.org/packages/search?terms=%s")) + ("Hackage" . "https://hackage.haskell.org/packages/search?terms=%s") + ("The Free Dictionary" . "https://www.thefreedictionary.com/%s") + ("The Free Thesaurus" . "https://www.freethesaurus.com/%s")) "A list of pairs (NAME . BACKEND) describing the various backends `syd-lookup-online-documentation' may delegate to. diff --git a/users/crumb/programs/emacs/lib/syd-prose.el b/users/crumb/programs/emacs/lib/syd-prose.el index 967d627..7c246d6 100644 --- a/users/crumb/programs/emacs/lib/syd-prose.el +++ b/users/crumb/programs/emacs/lib/syd-prose.el @@ -1,5 +1,7 @@ ;;; syd-prose.el -*- lexical-binding: t; -*- +;; Soft-wrap text to not the window edge, but a constant width. Also allows for +;; centering buffer text. (use-package visual-fill-column :defer t) @@ -11,12 +13,35 @@ "Sets the buffer-local value for `visual-fill-column-center-text'." (setq-local visual-fill-column-center-text t)) +;; Jinx is a fast just-in-time spell-checker for Emacs. Jinx highlights +;; misspelled words in the text of the visible portion of the buffer. For +;; efficiency, Jinx highlights misspellings lazily, recognizes window boundaries +;; and text folding, if any. For example, when unfolding or scrolling, only the +;; newly visible part of the text is checked if it has not been checked +;; before. Each misspelling can be corrected from a list of dictionary words +;; presented as a completion menu. +(use-package jinx + ;; Managed by Nix. + :straight nil + :commands (jinx-mode jinx-correct jinx-correct-word) + :init (defun syd-jinx--jinx-or-ispell () + (interactive) + (if (bound-and-true-p jinx-mode) + (call-interactively #'jinx-correct-word) + (call-interactively #'ispell-word))) + :general (:states '(normal visual) + "z =" #'syd-jinx--jinx-or-ispell) + :config + ;; Default is "en_US"; fuck that! + (jinx-languages "en" t)) + (defvar syd-prose-mode-hook (list #'syd-prose-set-visual-fill-column-center #'visual-fill-column-mode #'visual-line-mode #'variable-pitch-mode - #'syd-prose-disable-display-line-numbers-mode-h) + #'syd-prose-disable-display-line-numbers-mode-h + #'jinx-mode) "Hooks run for `syd-prose-mode'.") ;;;###autoload diff --git a/users/crumb/programs/emacs/modules/syd-org.el b/users/crumb/programs/emacs/modules/syd-org.el index c9b7816..0959d43 100755 --- a/users/crumb/programs/emacs/modules/syd-org.el +++ b/users/crumb/programs/emacs/modules/syd-org.el @@ -77,12 +77,12 @@ See https://lists.gnu.org/archive/html/emacs-orgmode/2019-07/msg00081.html." (let* ((hl `(:weight bold)) (fg (lambda (c) `(:foreground ,(syd-kanagawa-get c)))) (bg (lambda (c) `(:background ,(syd-kanagawa-get c)))) - (block-delim `(:foreground nil + (block-delim `(:foreground unspecified :inherit font-lock-comment-face :extend t ,@(funcall bg 'sumi-ink-0) :height 0.75)) - (keyword '(:background nil :foreground nil + (keyword '(:background unspecified :foreground unspecified :inherit (fixed-pitch font-lock-comment-face) :height 0.9))) (setq org-src-block-faces