From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.help Subject: Re: How to read an integer from the minibuffer Date: Fri, 12 Nov 2021 14:21:32 +0700 Message-ID: References: <87ee7nqomk.fsf@mbork.pl> <874k8jz372.fsf@yahoo.com> <87czn7qhx7.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="5957"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Po Lu , Help Gnu Emacs mailing list To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Fri Nov 12 08:22:55 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mlQti-0001Gu-JW for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 12 Nov 2021 08:22:54 +0100 Original-Received: from localhost ([::1]:37698 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mlQtg-0001Fz-QC for geh-help-gnu-emacs@m.gmane-mx.org; Fri, 12 Nov 2021 02:22:52 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:50780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mlQsu-0001Dc-Uc for help-gnu-emacs@gnu.org; Fri, 12 Nov 2021 02:22:04 -0500 Original-Received: from [2607:f8b0:4864:20::931] (port=43533 helo=mail-ua1-x931.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mlQst-0002r8-F6 for help-gnu-emacs@gnu.org; Fri, 12 Nov 2021 02:22:04 -0500 Original-Received: by mail-ua1-x931.google.com with SMTP id v3so16949562uam.10 for ; Thu, 11 Nov 2021 23:22:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=meePI+xAq0MXU7EgamMlSppe0WHH0IrzR5YcdmsD1zg=; b=Wq0rklF0REwjbrEarFltOKj3JX0A9On/x0D2vDPf4nABRCfrg0KAU0zsGEym4vs37c slxaQprlzZekCZgpKLo6L8dszNKCkZ/1JyfXbP1FFq8EaMbHsHPot8yVaMjrFHBZBno5 6a4TnB9yNzZ2KjXq8Kia9rncd/5e8qm0esxkpaQuX+Waj5hiTNaLj1elsiuk5euoXKTy FbmE5LCew4i3pNQcBIG0uLgLPT/462e3J2jXuspyKLukV2Nf8qazzgzFulsiU+i+G/bU /c0eZ+FiNyHITztaOlL+4QUedPac/N9/9ggO0R6iWZfgWjsLPHU+0c1Hko/6IOrakwFZ TkPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=meePI+xAq0MXU7EgamMlSppe0WHH0IrzR5YcdmsD1zg=; b=LabH6+4iUNQKpSGTTwa7jzMqLbRQ2WgRK5LkwM3lG6ywx5TjwzGfo8NEYd12SbToMI 5nunuuMl/eBWeFZeEHDhGNXiAK86Trot2tpDxPuW+sgJX8/ibIw3f64JTxfyl1VUNtx7 smCkjICU5UX8nwP1j+z8p8zgHAXYnDJHtZiLMZnXazsyldvamjk13vQAJO/Vc0ji702W K9ZLQhrEbySaHx9Pulp5T8RUlrphn4TCH2Rw0MNIxIxNpELAGq95LR7+0rBD5X+LVxtH qyFnm3bjnQjuzTn1kYGJLFp8JODeETdzjxrIUCWtVxzdgQ/2vlRUC797fsQM3xyD1uEB VxoQ== X-Gm-Message-State: AOAM532MxJCruKnq67rrA1sXDjmhtDEZ5x3EvJyXu5DAwhbWBtiVrGZV tmnLIO6Zv2rd6kwt1RTKK+ooFRrv3f7ahJuGA7c= X-Google-Smtp-Source: ABdhPJwe5RUaYp05D1pNOzgKM2ebrFe7elFJfAfBePptM6ZTXpZXcd34KUUrpAEErVlk8Wq7UPzYZM+6+2cS+75dHpY= X-Received: by 2002:a05:6102:105b:: with SMTP id h27mr7164757vsq.60.1636701721899; Thu, 11 Nov 2021 23:22:01 -0800 (PST) In-Reply-To: <87czn7qhx7.fsf@mbork.pl> X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::931 (failed) Received-SPF: pass client-ip=2607:f8b0:4864:20::931; envelope-from=yurivkhan@gmail.com; helo=mail-ua1-x931.google.com X-Spam_score_int: -12 X-Spam_score: -1.3 X-Spam_bar: - X-Spam_report: (-1.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:134531 Archived-At: On Thu, 11 Nov 2021 at 14:19, Marcin Borkowski wrote: > >> How do I do that? One way would be to use `read-from-minibuffer' with > >> a suitable keymap, but that seems slightly low-level. If that is the > >> way to go, is there a good way to set up a keymap so that nothing exce= pt > >> some specified characters are self-inserting? IOW, is `suppress-keyma= p' > >> the way to go or is there some other way? > > > > Perhaps you're looking for `read-number'? > > Thanks, that is nice, but not very general. Another value I want to > read is a time in the hh:mm format, for example. There are lots of examples out there of form controls trying to prevent the user from entering invalid data, and they demonstrate many things you can get wrong while implementing one. A form control for integer numbers only permits typing digits (as you initially asked). Now the user cannot enter -42. Okay, after a bug report and a fix, the control now permits the minus sign. But the control validates the entry after every keypress, so, as soon as the user starts typing, they are presented with an error message, =E2=80=9C=E2=80=98-=E2=80=99 is not a valid integer=E2=80=9D. Well= , duh, I just started typing, let me finish it! My bank=E2=80=99s money transfer web form=E2=80=99s amount field filters ke= ypresses to only allow digits. One, I cannot paste a number I copied from an invoice opened elsewhere. Two, I cannot press Ctrl+L to activate my browser=E2=80=99s address bar, or switch to another tab with Ctrl+PgUp, Ctrl+PgDn, or Alt+[1=E2=80=A69]. Three, I can=E2=80=99t move my cursor if I inadvertently skip or mistype a digit, e.g., to correct a 1000 to 15000, I cannot type =E2=80=98=E2=86=90 =E2=86=90 =E2=86=90 5=E2=80=99, I h= ave to type =E2=80=98backspace backspace backspace 5 0 0 0=E2=80=99. A license activation input box in a proprietary software installer wants a string of 20 semi-random letters. Since no one can reliably enter that in one go, it splits those 20 letters into 4 groups of 5 and presents them as separate input boxes. As a courtesy to the user, as soon as 5 letters are typed in the first box, the cursor automatically moves to the second box. However, if you mistype the last of those 5 letters, Backspace does not delete it, because technically you=E2=80=99re in the second box and it=E2=80=99s technically e= mpty, there=E2=80=99s nothing to delete. Also, you can=E2=80=99t paste the whole = 20-letter code in one go, because the first box is limited to 5 letters. A bank money transfer is confirmed with a 4-digit code that is sent in an SMS message. As soon as you type the 4th digit, it goes on to verify the code, without you having to press Enter. However, this means you cannot immediately correct a mistyped 4th digit; you get a =E2=80=9Cverification failed=E2=80=9D message first. Guideline: Perform input validation only after the user has indicated they are finished with data entry.