Skip to content

Instantly share code, notes, and snippets.

@amygrinn
Last active September 28, 2021 18:34
Show Gist options
  • Save amygrinn/982a5d3d845cbaf7b1a5411bc6900022 to your computer and use it in GitHub Desktop.
Save amygrinn/982a5d3d845cbaf7b1a5411bc6900022 to your computer and use it in GitHub Desktop.
(require 'ispell)
(defun is-plural (noun)
"Determine if any word in NOUN has a base (root) word.
Uses either ispell, aspell, or hunspell based on user settings."
(condition-case err
(progn
(ispell-set-spellchecker-params)
(let* ((words (split-string noun))
(orig-args (ispell-get-ispell-args))
(args (append
(if (and ispell-current-dictionary
(not (member "-d" orig-args)))
(list "-d" ispell-current-dictionary))
orig-args
(if ispell-current-personal-dictionary
(list "-p" ispell-current-personal-dictionary))
(if ispell-encoding8-command
(if ispell-really-hunspell
(list ispell-encoding8-command
(upcase (symbol-name (ispell-get-coding-system))))
(list
(concat ispell-encoding8-command
(symbol-name (ispell-get-coding-system))))))
ispell-extra-args))
(mode (cond (ispell-really-aspell "munch")
((or ispell-really-hunspell
(not (not (string-match-p "ispell" ispell-program-name))))
"-m")
(t (error (concat ispell-program-name " is not supported.")))))
(results (mapcar
(lambda (word)
(shell-command-to-string
(concat "echo " word " | " ispell-program-name " " mode " " (string-join args " "))))
words)))
(cond
(ispell-really-aspell
(seq-some
(lambda (result)
(not (not (string-match-p "/S" result))))
results))
(ispell-really-hunspell
(seq-some
(lambda (result)
(not (not (string-match-p "fl:[[:alnum:]]*S[[:alnum:]]*" result))))
results))
((not (not (string-match-p "ispell" ispell-program-name)))
(seq-some
(lambda (result)
(not (not (string-match-p "(derives from root" result))))
results))
(t
(error (concat ispell-program-name " is not supported."))))))
(error (progn
(message (error-message-string err))
nil))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment