all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: Tino Calancha <tino.calancha@gmail.com>,
	Emacs developers <emacs-devel@gnu.org>
Subject: Re: Generalize and standarize dired-plural-s
Date: Sun, 18 Sep 2016 15:06:26 +0000	[thread overview]
Message-ID: <CAFyQvY2A6KgypwD7aD_ekfL4sTN8pxPSum5Ur07nKt_SZ5zxmw@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1609182258230.29669@calancha-pc>

[-- Attachment #1: Type: text/plain, Size: 3224 bytes --]

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? "
>          (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

[-- Attachment #2: Type: text/html, Size: 4790 bytes --]

  reply	other threads:[~2016-09-18 15:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-18 14:00 Generalize and standarize dired-plural-s Tino Calancha
2016-09-18 15:06 ` Kaushal Modi [this message]
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=CAFyQvY2A6KgypwD7aD_ekfL4sTN8pxPSum5Ur07nKt_SZ5zxmw@mail.gmail.com \
    --to=kaushal.modi@gmail.com \
    --cc=emacs-devel@gnu.org \
    --cc=tino.calancha@gmail.com \
    /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.