diff --git a/elisp-refs.el b/elisp-refs.el index f438b64..63f4f4c 100644 --- a/elisp-refs.el +++ b/elisp-refs.el @@ -469,20 +469,20 @@ propertize them." 'path path) (buffer-string))) +(defun elisp-refs--pluralize (number thing) + "Human-friendly description of NUMBER occurrences of THING." + (format "%s %s%s" + (elisp-refs--format-int number) + thing + (if (equal number 1) "" "s"))) + (defun elisp-refs--format-count (symbol ref-count file-count) - (let ((ref-count-str - (if (equal ref-count 1) - "1 reference" - (format "%s references" (elisp-refs--format-int ref-count)))) - (file-count-str - (cond - ((zerop file-count) - "") - ((equal file-count 1) - " in 1 file") - (t - (format " in %s files" (elisp-refs--format-int file-count)))))) - (format "Found %s to %s%s." ref-count-str symbol file-count-str))) + (format "Found %s to %s%s." + (elisp-refs--pluralize ref-count "reference") + symbol + (if (zerop file-count) + "" + (format " in %s" (elisp-refs--pluralize file-count "file"))))) ;; TODO: if we have multiple matches on one line, we repeatedly show ;; that line. That's slighly confusing. diff --git a/test/unit-test.el b/test/unit-test.el index e58a083..2e0b64f 100644 --- a/test/unit-test.el +++ b/test/unit-test.el @@ -34,6 +34,12 @@ whilst visiting that file." (should (equal (elisp-refs--format-int -1234) "-1,234")) (should (equal (elisp-refs--format-int 1234567) "1,234,567"))) +(ert-deftest elisp-refs--pluralize () + (should (equal (elisp-refs--pluralize 0 "thing") "0 things")) + (should (equal (elisp-refs--pluralize 1 "thing") "1 thing")) + (should (equal (elisp-refs--pluralize 2 "thing") "2 things")) + (should (equal (elisp-refs--pluralize 1001 "thing") "1,001 things"))) + (ert-deftest elisp-refs--unindent-split-properties () "Ensure we can still unindent when properties are split into separate region. Regression test for a very subtle bug."