all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Generalize and standarize dired-plural-s
@ 2016-09-18 14:00 Tino Calancha
  2016-09-18 15:06 ` Kaushal Modi
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Tino Calancha @ 2016-09-18 14:00 UTC (permalink / raw)
  To: Emacs developers; +Cc: tino.calancha


Hi,

I)
dired.el introduces the function `dired-plural-s' to pluralize
correctly output messages as:
(format "Kill Dired buffer%s of %s, too? "
         (dired-plural-s (length buf-list))
         (file-name-nondirectory fn))

In this example, it returns "s" if (length buf-list) > 1.  Otherwise,
it returns "".
Of course, this task is not exclusive of Dired: many other packages
in Emacs source code do the same thing.

II)
As you know, for some words the plural is different that just
appending "s" to the end.  For instance, in message.el:
(format
  "Really use %s possibly unknown group%s: %s? "
  (if (= (length errors) 1) "this" "these")
  (if (= (length errors) 1) "" "s")
  (mapconcat 'identity errors ", "))

"this" -> "these" is not handled by `dired-plural-s'.

I am wondering if it has sense to add a standard function, 
`string-plural-s', covering both cases: I), II).  Then, we might do
`dired-plural-s' and alias for the new function.
We might update all the 'plularizations' in Emacs source code to use
the new function as well.

Following function could do the job:

(defun string-plural-s (arg &optional string plural)
   "\
Return plural of STRING if ARG is nil, or an integer >1, or a seq of 
length >1.
If ARG is =1 or a sequence of length =1, return STRING.
Optional arg PLURAL is the plural of STRING.
If STRING is nil, return \"s\" or \"\"."
   (let ((single (or string ""))
         (plural (if (and string plural) plural
                   (apply #'string (append string "s" nil)))))
     (cond ((natnump arg)
            (if (= arg 1) single plural))
           ((null arg) plural)
           ((consp arg)
            (if (null (cdr arg)) single plural))
           ((arrayp arg)
            (if (= (length arg) 1) single plural))
           (t
            (signal 'wrong-type-argument
                    (list arg 'natnump 'listp 'arrayp))))))


What do you think about this idea?

Regards,
Tino



^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-09-18 20:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-18 14:00 Generalize and standarize dired-plural-s Tino Calancha
2016-09-18 15:06 ` Kaushal Modi
2016-09-18 15:12 ` Drew Adams
2016-09-18 17:45 ` Yuri Khan
2016-09-18 19:28   ` Tino Calancha
2016-09-18 20:47     ` Yuri Khan

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.