+;;;###autoload
+(defun ispell-completion-at-point ()
+ "Word completion function for use in `completion-at-point-functions'."
+ (pcase (bounds-of-thing-at-point 'word)
+ (`(,beg . ,end)
+ (when (and (< beg (point)) (<= (point) end))
+ (let* ((word (buffer-substring-no-properties beg end))
+ (len (length word))
+ (inhibit-message t)
+ (all (cons word (ispell-lookup-words word)))
+ (cur all))
+ (while cur
+ (unless (string-prefix-p word (car cur))
+ (setcar cur (concat word (substring (car cur) len))))
+ (while (when-let ((next (cadr cur)))
+ (not (string-prefix-p word next t)))
+ (setcdr cur (cddr cur)))
+ (setq cur (cdr cur)))
+ (list beg end (cdr all)
+ :annotation-function (lambda (_) " Dictionary word")