all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Heime <heimeborgia@protonmail.com>
Cc: Heime via Users list for the GNU Emacs text editor
	<help-gnu-emacs@gnu.org>
Subject: Re: Utf8 symbols in completing-read completion item
Date: Fri, 21 Oct 2022 00:02:33 +0300	[thread overview]
Message-ID: <Y1G3aQu5DdM93Ypf@protected.localdomain> (raw)
In-Reply-To: <ABtps27WUcWCGDjOhrZaUD1hz-TU7d1UmVhNd3pOTkxM4LX1D9iaLHjwKGbfqzbaOXxzfHVwAHap3WWs1axyvTsh3UU6vATvHb27w52jDAY=@protonmail.com>

* Heime via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org> [2022-10-20 15:26]:
> Am using "completing-read" to input greek letters. To introduce the corresponding utf8
> symbol I just copy it in the completion item, then match with a pcase that includes the
> utf8 symbol. Is this the correct way of doing so?

Your Lisp formatting is not readable:

(defun nuket-greek (actm)
"TODO"

(interactive
(list
(let ( (cseq '("alpha α" "beta β" "gamma" "delta" "epsilon" "zeta" "eta")) )
(completing-read "Nuke: " cseq nil t "eta"))))

(pcase actm

("alpha α" (insert "\\alpha"))

("beta β" (insert "\\beta"))

("eta" (insert "\\eta"))) )


I can read better when I format it this way:

(defun nuket-greek (actm)
  "TODO."
(interactive
 (list
  (let ((cseq '("alpha α" "beta β" "gamma" "delta" "epsilon" "zeta" "eta")))
    (completing-read "Nuke: " cseq nil t "eta"))))
(pcase actm
  ("alpha α" (insert "\\alpha"))
  ("beta β" (insert "\\beta"))
  ("eta" (insert "\\eta"))))

Myself I do not know what is \\alpha, but maybe you use that for
LaTeX or something. Personally I don't like complicated
`interactive' statements, it looks ugly.

I would use the features that beautiful function `completing-read' offers:

(completing-read PROMPT COLLECTION &optional PREDICATE REQUIRE-MATCH
INITIAL-INPUT HIST DEF INHERIT-INPUT-METHOD)

Read a string in the minibuffer, with completion.
PROMPT is a string to prompt with; normally it ends in a colon and a space.
COLLECTION can be a list of strings, an alist, an obarray or a hash table.

What I see is that you wish to choose something like "alpha α"
 and then to get different result like "\\alpha".

Following may give you the result automatically, by using hash:

(let ((hash (make-hash-table :test #'equal)))
  (puthash "alpha α" "\\alpha" hash)
  (puthash "beta β" "\\beta" hash)
  (puthash "gamma" "\\gamma" hash)
  (puthash "delta" "\\delta" hash)
  (puthash "epsilon" "\\epsilon" hash)
  (puthash "zeta" "\\zeta" hash)
  (puthash "eta" "\\eta" hash)
  (gethash (completing-read "Choose: " hash nil t) hash)

I would put larger lists into hash by using this:

(let ((list '("alpha α" "\\alpha"
	      "beta β" "\\beta"
	      "gamma" "\\gamma"
	      "delta" "\\delta"
	      "epsilon" "\\epsilon"
	      "zeta" "\\zeta"
	      "eta" "\\eta"))
      (hash (make-hash-table :test #'equal)))
  (while list
    (let ((key (pop list))
	  (value (pop list)))
      (puthash key value hash)))
  (gethash (completing-read "Choose: " hash nil t) hash)) ⇒ "\\epsilon"

When I say larger list, my lists are huge and would not have time to
use single `puthash` one by one, I must let program do it.


-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



  reply	other threads:[~2022-10-20 21:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-20 11:40 Utf8 symbols in completing-read completion item Heime via Users list for the GNU Emacs text editor
2022-10-20 21:02 ` Jean Louis [this message]
2022-10-20 22:00   ` Heime
2022-10-21  2:54     ` Jean Louis
2022-10-21  3:33       ` Heime
2022-10-21  3:43         ` Michael Heerdegen
2022-10-21  4:16           ` Heime
2022-10-21  6:18     ` Eli Zaretskii
2022-10-21  0:11 ` Michael Heerdegen

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=Y1G3aQu5DdM93Ypf@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=heimeborgia@protonmail.com \
    --cc=help-gnu-emacs@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.