[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/spell-fu 2c792330ac 18/86: Case insensitive sort lines as
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/spell-fu 2c792330ac 18/86: Case insensitive sort lines as a list (not in the buffer) |
Date: |
Thu, 7 Jul 2022 12:03:39 -0400 (EDT) |
branch: elpa/spell-fu
commit 2c792330ac9d2d5f07821e8dc7a379ef3f37855a
Author: Campbell Barton <ideasman42@gmail.com>
Commit: Campbell Barton <ideasman42@gmail.com>
Case insensitive sort lines as a list (not in the buffer)
---
spell-fu.el | 88 ++++++++++++++++++++++++++++++++++++++++---------------------
1 file changed, 58 insertions(+), 30 deletions(-)
diff --git a/spell-fu.el b/spell-fu.el
index 84e1c9c48f..8f1441336f 100644
--- a/spell-fu.el
+++ b/spell-fu.el
@@ -54,9 +54,7 @@
(eval-when-compile
;; For `ispell-personal-dictionary' and similar.
- (require 'ispell)
- ;; Quiet warning about `sort-fold-case'.
- (require 'sort))
+ (require 'ispell))
;; ---------------------------------------------------------------------------
@@ -143,6 +141,7 @@ Notes:
;; Helpers, not directly related to checking spelling.
;;
+
(defmacro spell-fu--with-message-prefix (prefix &rest body)
"Add text before the message output.
Argument PREFIX is the text to add at the start of the message.
@@ -186,6 +185,16 @@ Optional argument BODY runs with the depth override."
(goto-char ,point-start)
(setq ,point-start (line-beginning-position)))))
+(defun spell-fu--buffer-as-line-list (buffer lines)
+ "Add lines from BUFFER to LINES, returning the updated LINES."
+ (with-current-buffer buffer
+ (save-excursion
+ (goto-char (point-min))
+ (while (not (eobp))
+ (push (buffer-substring-no-properties (line-beginning-position)
(line-end-position)) lines)
+ (forward-line 1))))
+ lines)
+
(defun spell-fu--removed-changed-overlay (overlay after _beg _end &optional
_len)
"Hook for removing OVERLAY which is being edited.
Argument AFTER, ignore when true."
@@ -247,37 +256,56 @@ Argument WORDS-FILE the file to write the word list into."
(spell-fu--with-message-prefix "Spell-fu generating words: "
(message "%S" (file-name-nondirectory words-file))
- (with-temp-buffer
- ;; Optional: insert personal dictionary, stripping header and
inserting a newline.
- (when has-dict-personal
- (insert-file-contents personal-words-file)
- (goto-char (point-min))
- (when (looking-at "personal_ws\-")
- (delete-region (line-beginning-position) (1+
(line-end-position))))
- (goto-char (point-max))
- (unless (eq ?\n (char-after))
- (insert "\n")))
+ ;; Build a word list, sorted case insensitive.
+ (let ((word-list nil))
- (let
- ( ;; Use the pre-configured aspell binary, or call aspell directly.
- (aspell-bin
- (or
- (and
- (bound-and-true-p ispell-really-aspell)
- (bound-and-true-p ispell-program-name))
- (executable-find "aspell"))))
-
- (cond
- ((string-equal dict "default")
- (call-process aspell-bin nil t nil "dump" "master"))
- (t
- (call-process aspell-bin nil t nil "-d" dict "dump"
"master"))))
+ ;; Optional: insert personal dictionary, stripping header and
inserting a newline.
+ (with-temp-buffer
+ (when has-dict-personal
+ (insert-file-contents personal-words-file)
+ (goto-char (point-min))
+ (when (looking-at "personal_ws\-")
+ (delete-region (line-beginning-position) (1+
(line-end-position))))
+ (goto-char (point-max))
+ (unless (eq ?\n (char-after))
+ (insert "\n")))
+
+ (setq word-list (spell-fu--buffer-as-line-list (current-buffer)
word-list)))
+
+ ;; Insert dictionary from aspell.
+ (with-temp-buffer
+ (let
+ ( ;; Use the pre-configured aspell binary, or call aspell
directly.
+ (aspell-bin
+ (or
+ (and
+ (bound-and-true-p ispell-really-aspell)
+ (bound-and-true-p ispell-program-name))
+ (executable-find "aspell"))))
+
+ (cond
+ ((string-equal dict "default")
+ (call-process aspell-bin nil t nil "dump" "master"))
+ (t
+ (call-process aspell-bin nil t nil "-d" dict "dump"
"master"))))
+
+ (setq word-list (spell-fu--buffer-as-line-list (current-buffer)
word-list)))
;; Case insensitive sort is important if this is used for
`ispell-complete-word-dict'.
;; Which is a handy double-use for this file.
- (let ((sort-fold-case t))
- (sort-lines nil (point-min) (point-max)))
- (write-region nil nil words-file nil 0))))))
+ (let ((word-list-ncase nil))
+ (dolist (word word-list)
+ (push (cons (downcase word) word) word-list-ncase))
+
+ ;; Sort by the lowercase word.
+ (setq word-list-ncase
+ (sort word-list-ncase (lambda (a b) (string-lessp (car a) (car
b)))))
+
+ ;; Write to 'words-file'.
+ (with-temp-buffer
+ (dolist (line-cons word-list-ncase)
+ (insert (cdr line-cons) "\n"))
+ (write-region nil nil words-file nil 0))))))))
;; ---------------------------------------------------------------------------
- [nongnu] branch elpa/spell-fu created (now cbe5cd84c3), ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu eeda8ef28e 06/86: Cleanup: minor non-functional changes, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 676498f757 13/86: Support buffer local dictionaries, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 073932be78 16/86: Cleanup: replace '(nth 5 ...' with file-attribute-modification-time, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 2c792330ac 18/86: Case insensitive sort lines as a list (not in the buffer),
ELPA Syncer <=
- [nongnu] elpa/spell-fu 03114080c8 20/86: Add requirements at the top of the file, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu fe557e3dff 21/86: Be explicit about using macro that sets values in-place, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 33a28e0df5 41/86: fix: encode word to utf-8 generating the cache, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 7770c005c4 47/86: Cleanup minor name change for spell-fu function name, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 866044304f 50/86: Check if faces can be used on property change, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 8f780a874c 66/86: Reduce idle overlay fragmentation, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 4fc84a9028 69/86: Fix spell-fu-directory's documentation, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu 53bd2b24c6 81/86: Cleanup: add spell-fu--canonicalize-word utility function, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu a5a06e150a 02/86: Fix error comparing times of cache to word-list, ELPA Syncer, 2022/07/07
- [nongnu] elpa/spell-fu bd00417a0e 09/86: Improve status messages when generating word-list & cache, ELPA Syncer, 2022/07/07