;;; 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)

(defun syd-prose-disable-display-line-numbers-mode-h ()
  "Disable `display-line-numbers-mode'."
  (display-line-numbers-mode -1))

(defun syd-prose-set-visual-fill-column-center ()
  "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: libenchant dependency.
  :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
        #'jinx-mode)
  "Hooks run for `syd-prose-mode'.")

;;;###autoload
(define-minor-mode syd-prose-mode
  "A minor mode for writing prose."
  :lighter nil)

(provide 'syd-prose)
