From: Tino Calancha <tino.calancha@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Cc: tino.calancha@gmail.com
Subject: Generalize and standarize dired-plural-s
Date: Sun, 18 Sep 2016 23:00:21 +0900 (JST) [thread overview]
Message-ID: <alpine.DEB.2.20.1609182258230.29669@calancha-pc> (raw)
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
next reply other threads:[~2016-09-18 14:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-18 14:00 Tino Calancha [this message]
2016-09-18 15:06 ` Generalize and standarize dired-plural-s 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.DEB.2.20.1609182258230.29669@calancha-pc \
--to=tino.calancha@gmail.com \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.