[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master ce7a2be 20/62: Changed case-sensitivity to case-handling
From: |
Ian Dunn |
Subject: |
[elpa] master ce7a2be 20/62: Changed case-sensitivity to case-handling |
Date: |
Sat, 9 Dec 2017 14:33:59 -0500 (EST) |
branch: master
commit ce7a2be39e23a061d83f69754f12d60c2f634ae4
Author: Ian Dunn <address@hidden>
Commit: Ian Dunn <address@hidden>
Changed case-sensitivity to case-handling
* paced.el (paced-dictionary): Added case-handling slot
(paced-make-dictionary): Updated constructor.
(paced--handle-word-case): New defun.
(paced-dictionary-process-word): New dictionary method.
(paced-add-word-to-dict): Use it.
* paced-tests.el (paced-handle-word-case): Test case handling function.
(paced-create-dictionary): Update constructor of dictionary.
---
paced-tests.el | 10 +++++++++-
paced.el | 54 +++++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 52 insertions(+), 12 deletions(-)
diff --git a/paced-tests.el b/paced-tests.el
index 70ff440..2aa53d5 100644
--- a/paced-tests.el
+++ b/paced-tests.el
@@ -38,6 +38,14 @@
(defconst paced-test-dict-save-file (paced-test-file
"paced-dictionary-case-sensitive"))
+(ert-deftest paced-handle-word-case ()
+ (let* ((word "EiEiO"))
+ (should (string-equal (paced--handle-word-case 'preserve word) "EiEiO"))
+ (should (string-equal (paced--handle-word-case 'downcase word) "eieio"))
+ (should (string-equal (paced--handle-word-case 'upcase word) "EIEIO"))
+ (should (string-equal (paced--handle-word-case 'downcase-first word)
"eiEiO"))
+ (should (string-equal (paced--handle-word-case 'upcase-first word)
"EiEiO"))))
+
(ert-deftest paced-create-dictionary ()
(let* ((paced--registered-dictionaries nil)
(target-file-exists (file-exists-p paced-test-dict-save-file))
@@ -45,7 +53,7 @@
(file-attribute-modification-time (file-attributes
paced-test-dict-save-file))))
(new-dict (paced-make-dictionary "test-dict-case"
paced-test-dict-save-file
- t)))
+ 'downcase)))
(should (= (length paced--registered-dictionaries) 1))
(should (paced-dictionary-p new-dict))
(oset new-dict updated t) ;; Mark it as updated so it saves
diff --git a/paced.el b/paced.el
index f5c6c49..51f885e 100644
--- a/paced.el
+++ b/paced.el
@@ -163,14 +163,24 @@ entry should be of the form (VAR VALUE).")
:documentation
"Header line for the save file.
This is used with the `object-write' method.")
- (case-sensitive :initarg :case-sensitive
- :initform nil
- :type boolean
- :custom boolean
- :label "Case Sensitive"
- :documentation "Non-nil if the dictionary should be case
sensitive when populating.
-
-When nil, \"This\" will be the same as \"this\" in `usage-hash'.")
+ (case-handling :initarg :case-handling
+ :initform downcase
+ :type (member downcase upcase preserve downcase-first
upcase-first)
+ :custom (choice (const :tag "Downcase All Words" downcase)
+ (const :tag "Upcase All Words" upcase)
+ (const :tag "Preserve Case" preserve)
+ (const :tag "Downcase Just the First Letter"
downcase-first)
+ (const :tag "Upcase Just the First Letter"
upcase-first))
+ :label "Case Sensitive"
+ :documentation "A symbol indicating how case should be
handled during population.
+
+It can be one of the following:
+
+* downcase Downcase every word
+* upcase Upcase every word
+* preserve Preserve case
+* downcase-first Downcase the first letter of each word, leave the rest the
same
+* upcase-first Upcase the first letter of each word, leave the rest the
same")
(updated :initarg :updated
:initform nil
:type boolean
@@ -216,7 +226,7 @@ instead.")
(defsubst paced--ensure-dictionary-directory ()
(make-directory paced-dictionary-directory t))
-(defun paced-make-dictionary (name filename case-sensitive)
+(defun paced-make-dictionary (name filename case-handling)
"Make a paced dictionary called NAME.
NAME is a symbol used to identify the new dictionary.
@@ -228,7 +238,7 @@ Return value is the new dictionary."
(let ((new-dict (paced-dictionary
:object-name name
:file filename
- :case-sensitive case-sensitive)))
+ :case-handling case-handling)))
(paced-register-dictionary name new-dict)
new-dict))
@@ -430,12 +440,34 @@ Things is based on `paced-thing-at-point-constituent'."
(interactive "p")
(forward-thing paced-thing-at-point-constituent number))
+(defun paced--handle-word-case (case-handling word)
+ "Process WORD based on CASE-HANDLING.
+
+This is a separate function only for testing; use
+`paced-dictionary-process-word' instead."
+ (pcase case-handling
+ (`preserve word)
+ (`downcase (downcase word))
+ (`upcase (upcase word))
+ (`downcase-first
+ ;; Downcase the first letter
+ (concat (downcase (substring word 0 1))
+ (substring word 1)))
+ ;; Upcase the first letter
+ (`upcase-first
+ (concat (upcase (substring word 0 1))
+ (substring word 1)))))
+
+(cl-defmethod paced-dictionary-process-word ((dict paced-dictionary) word)
+ "Return WORD, modified based on DICT's case handling."
+ (paced--handle-word-case (oref dict case-handling) word))
+
(defsubst paced-add-word-to-dict (dict word)
"Add WORD to paced dictionary DICT."
;; If I've got a word uppercase and lowercase in my usage table, I'm
;; going to have repeats when ignore case is enabled. To solve this,
;; downcase everything when not case sensitive.
- (let ((new-word (if (oref dict case-sensitive) word (downcase word))))
+ (let ((new-word (paced-dictionary-process-word dict word)))
;; Use the full name here to silence the byte-compiler
(cl-incf (map-elt (oref dict usage-hash) new-word 0))
(oset dict updated t)))
- [elpa] master de2260f 07/62: Documented the population commands, (continued)
- [elpa] master de2260f 07/62: Documented the population commands, Ian Dunn, 2017/12/09
- [elpa] master febb200 08/62: Added function to submit a bug report, Ian Dunn, 2017/12/09
- [elpa] master b925c0b 17/62: Updated links in documentation, Ian Dunn, 2017/12/09
- [elpa] master 38979b5 18/62: Fixed up contributing documentation, Ian Dunn, 2017/12/09
- [elpa] master 4162bd4 22/62: Changed name of registered checker, Ian Dunn, 2017/12/09
- [elpa] master 302d4b4 28/62: Added convenience method for adding population commands, Ian Dunn, 2017/12/09
- [elpa] master 4824306 21/62: Make the registered dictionary map a hash table, Ian Dunn, 2017/12/09
- [elpa] master e751e4f 24/62: Update case-handling slot name in Documentation, Ian Dunn, 2017/12/09
- [elpa] master dada473 19/62: Push of info page, Ian Dunn, 2017/12/09
- [elpa] master 6e7d6d7 29/62: Updated method names in paced-repopulate-dictionary-async, Ian Dunn, 2017/12/09
- [elpa] master ce7a2be 20/62: Changed case-sensitivity to case-handling,
Ian Dunn <=
- [elpa] master 35ba53b 26/62: Autoload paced-repopulate-named-dictionary-async, Ian Dunn, 2017/12/09
- [elpa] master 6e8acdf 09/62: Added documentation, Ian Dunn, 2017/12/09
- [elpa] master 0d17d8d 25/62: Warn before resetting dictionary during population, Ian Dunn, 2017/12/09
- [elpa] master 6aefb0b 05/62: Made dictionary names strings, Ian Dunn, 2017/12/09
- [elpa] master bda0995 36/62: Remove inaccurate comment about completion in case-handling slot, Ian Dunn, 2017/12/09
- [elpa] master 7c9a342 39/62: Fixed paced-global-dict-enable-alist value type, Ian Dunn, 2017/12/09
- [elpa] master 8f1860a 37/62: Documentation fixes, Ian Dunn, 2017/12/09
- [elpa] master b95b016 38/62: Pushed updated info pages, Ian Dunn, 2017/12/09
- [elpa] master 964eb48 42/62: Fixed bug in completion, Ian Dunn, 2017/12/09
- [elpa] master 23c4a65 48/62: Mention common variables in population commands settings, Ian Dunn, 2017/12/09