From 1e5c351253784ca3bd05c9e0db1e9dc53ab9a1e1 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Thu, 27 Jan 2022 19:26:33 -0600 Subject: Whose birthday is it? --- lisp/+ispell.el | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'lisp/+ispell.el') diff --git a/lisp/+ispell.el b/lisp/+ispell.el index e35b2f1..c3ee417 100644 --- a/lisp/+ispell.el +++ b/lisp/+ispell.el @@ -49,26 +49,31 @@ before the LISTS." (push string words)))))) words)) -(defun +ispell-move-buffer-words-to-dir-locals () - (interactive) +;;;###autoload +(defun +ispell-move-buffer-words-to-dir-locals (&optional arg) + "Move the current buffer-local words to .dir-locals.el. +This function prompts the user to save .dir-locals.el, unless +prefix ARG is non-nil; then it just saves them." + (interactive "P") (unless (buffer-file-name) (user-error "Buffer not attached to file")) (hack-dir-local-variables) - (let ((words (+ispell-buffer-local-words-list)) - (dir-local-words (+ispell-append-removing-duplicates - (alist-get 'ispell-buffer-session-localwords - dir-local-variables-alist) - (alist-get 'ispell-buffer-session-localwords - file-local-variables-alist)))) + (when-let ((new-words (+ispell-append-removing-duplicates + :test #'string= + ispell-buffer-session-localwords + (alist-get 'ispell-buffer-session-localwords + dir-local-variables-alist) + (alist-get 'ispell-buffer-session-localwords + file-local-variables-alist) + (+ispell-buffer-local-words-list)))) (save-excursion (add-dir-local-variable major-mode 'ispell-buffer-session-localwords (setq ispell-buffer-session-localwords - (+ispell-append-removing-duplicates - :test #'string= - dir-local-words ispell-buffer-session-localwords words))) - (when (y-or-n-p "Save .dir-locals.el?") + new-words)) + (when (or arg + (y-or-n-p "Save .dir-locals.el?")) (save-buffer)) (bury-buffer)) (or ispell-buffer-local-name @@ -78,5 +83,10 @@ before the LISTS." (while (search-forward ispell-words-keyword nil t) (delete-region (point-at-bol) (1+ (point-at-eol))))))) +;;;###autoload +(defun +ispell-move-buffer-words-to-dir-locals-hook () + "Convenience function for binding to a hook." + (+ispell-move-buffer-words-to-dir-locals t)) + (provide '+ispell) ;;; +ispell.el ends here -- cgit 1.4.1-21-gabe81