From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Kaushal Modi Newsgroups: gmane.emacs.devel Subject: Re: Generalize and standarize dired-plural-s Date: Sun, 18 Sep 2016 15:06:26 +0000 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1143a90ecb93ff053cc98a35 X-Trace: blaine.gmane.org 1474211270 13744 195.159.176.226 (18 Sep 2016 15:07:50 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 18 Sep 2016 15:07:50 +0000 (UTC) To: Tino Calancha , Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Sep 18 17:07:46 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bldh0-0002YT-CL for ged-emacs-devel@m.gmane.org; Sun, 18 Sep 2016 17:07:42 +0200 Original-Received: from localhost ([::1]:50434 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bldgy-0004wc-KL for ged-emacs-devel@m.gmane.org; Sun, 18 Sep 2016 11:07:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:47985) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bldg0-0004h1-Ek for emacs-devel@gnu.org; Sun, 18 Sep 2016 11:06:42 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bldfy-0005CS-Qr for emacs-devel@gnu.org; Sun, 18 Sep 2016 11:06:40 -0400 Original-Received: from mail-vk0-x230.google.com ([2607:f8b0:400c:c05::230]:33268) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bldfy-0005CF-KT for emacs-devel@gnu.org; Sun, 18 Sep 2016 11:06:38 -0400 Original-Received: by mail-vk0-x230.google.com with SMTP id 192so91232576vkl.0 for ; Sun, 18 Sep 2016 08:06:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=/B1vnBOQccAtke2qGBDeJBrXe4QRmhrAPeOvD6H7oLU=; b=cIgbfI53w80eKc1yx3mbpVEMtC1SIz+CwwR7e+8FzMA7neMrAJmoCiFyvPsSoVPPWE tByE6EKBsLXxVINII+qtKeDYlJ8OpD1XPcvhUviHbKYdOjA2KIXJevy0PfQIKQVJx6zV nL2JsNMi0yEYN7wN2FxMhUfVZTri9wpAuz+jnPZr6d3MBW4zDh+DcnlOYLrJrHJD4kDk 23+DcK/Cmzv70/6czdWsV+JtpyTEgDhwD/KSqsaAiCjyQFRJVakyIQd31kvwLVTAveC+ gF8SaDRwa405sQrSTrAcghmbocLBiA+7WGow4zpmTXkr0uaQ/hgPXVZVxHl6FGuSgplQ J3Lg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=/B1vnBOQccAtke2qGBDeJBrXe4QRmhrAPeOvD6H7oLU=; b=kczbqnsQau0k2jzlpzylSVXgEigwUagtMaJQFss7wzL5ojZNun+XPW0XFs+OwSbWE4 zdeZYw7v4nkd7ZnISrivAdF498hu7jYXBWGHc0uK8TxQqG8S3TBRYsULAPcVWYBkyUJ6 NRlS6RDmxpQKAX0JQhIv5aRU0fb+YHtt20jzJDKeEbj3X55SFdyy/muHUBLWwVTLa/bf VtJBZzMiNajEo/XilZ5Xk8duVqX+kC4jU0t4mi8YXpzBqzR7T/G/KM0pSuQ8RY65D/Xp KooBGSZuAwsRMVT+htgP5P4T9EYJBq8v6mqxAZFU+bq/XQThi0X4PAzkPB5bIkIknR9D +kvg== X-Gm-Message-State: AE9vXwPfEjTnCaL9yhYnS0FQVlmyv1Qa6Ysap7RPQHu88Ii0U+AbOOLCLHYLP2iJZy5Cwq8KgHb+Q/L+IP+bWA== X-Received: by 10.31.21.212 with SMTP id 203mr9411392vkv.113.1474211198241; Sun, 18 Sep 2016 08:06:38 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400c:c05::230 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:207554 Archived-At: --001a1143a90ecb93ff053cc98a35 Content-Type: text/plain; charset=UTF-8 On Sun, Sep 18, 2016, 10:00 AM Tino Calancha wrote: > > 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. > I agree. I have also had something in my emacs config that made me wish of the existence of a function like this. > 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). +1 > 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? > I like this idea. The only comment I have is that the "append 's' to pluralize" part should not be hard-coded into the string-plural-s function. How about have a "string-plural--conditions-function" variable (or something named like that), and then you funcall that variable in string-plural-s? The "string-plural--conditions-function" variable would be a lambda function that would accept an arg STRING and output a plural string for that STRING. Inside the lambda, would be an elaborate cond form that would decide how to pluralize the string this -> these grape -> grapes knife -> knives ruby -> rubies sheep -> sheep This "string-plural--conditions-function" variable will be quite an elaborate cond form as it would try to cover all the corner cases of English pluralization. I am suggesting this to be a separate function so that the logic of string-plural-s stays clear and succinct and the English grammar rules do not come in the way while understanding that function. -- Kaushal Modi --001a1143a90ecb93ff053cc98a35 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On Sun, Sep 18= , 2016, 10:00 AM Tino Calancha <tino.calancha@gmail.com> wrote:

Hi,

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

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

I agree. I have also had something in my emacs config that made me wish of= the existence of a function like this.
=C2=A0
II)
As you know, for some words the plural is different that just
appending "s" to the end.=C2=A0 For instance, in message.el:
(format
=C2=A0 "Really use %s possibly unknown group%s: %s? "
=C2=A0 (if (=3D (length errors) 1) "this" "these")
=C2=A0 (if (=3D (length errors) 1) "" "s")
=C2=A0 (mapconcat 'identity errors ", "))

"this" -> "these" is not handled by `dired-plural-s&= #39;.

I am wondering if it has sense to add a standard function,
`string-plural-s', covering both cases: I), II).=C2=A0

+1
=C2=A0
Th= en, we might do
`dired-plural-s' and alias for the new function.
We might update all the 'plularizations' in Emacs source code to us= e
the new function as well.

Following function could do the job:

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


What do you think about this idea?

I li= ke this idea.=C2=A0

The only comment I have is tha= t the "append 's' to pluralize" part should not be hard-c= oded into the string-plural-s function.

How about = have a "string-plural--conditions-function" variable (or somethin= g named like that), and then you funcall that variable in string-plural-s?<= /div>

The "string-plural--conditions-function"= variable would be a lambda function that would accept an arg STRING and ou= tput a plural string for that STRING.

Inside the l= ambda, would be an elaborate cond form that would decide how to pluralize t= he string

this -> these
grape -> g= rapes
knife -> knives
ruby -> rubies
sh= eep -> sheep

This =C2=A0"string-plural--co= nditions-function" variable will be quite an elaborate cond form as it= would try to cover all the corner cases of English pluralization. I am sug= gesting this to be a separate function so that the logic of string-plural-s= stays clear and succinct and the English grammar rules do not come in the = way while understanding that function.

--

Kaushal Modi

--001a1143a90ecb93ff053cc98a35--