unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Utf8 symbols in completing-read completion item
@ 2022-10-20 11:40 Heime via Users list for the GNU Emacs text editor
  2022-10-20 21:02 ` Jean Louis
  2022-10-21  0:11 ` Michael Heerdegen
  0 siblings, 2 replies; 9+ messages in thread
From: Heime via Users list for the GNU Emacs text editor @ 2022-10-20 11:40 UTC (permalink / raw)
  To: Heime via Users list for the GNU Emacs text editor

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?

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Utf8 symbols in completing-read completion item
  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
  2022-10-20 22:00   ` Heime
  2022-10-21  0:11 ` Michael Heerdegen
  1 sibling, 1 reply; 9+ messages in thread
From: Jean Louis @ 2022-10-20 21:02 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

* 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/



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Utf8 symbols in completing-read completion item
  2022-10-20 21:02 ` Jean Louis
@ 2022-10-20 22:00   ` Heime
  2022-10-21  2:54     ` Jean Louis
  2022-10-21  6:18     ` Eli Zaretskii
  0 siblings, 2 replies; 9+ messages in thread
From: Heime @ 2022-10-20 22:00 UTC (permalink / raw)
  To: Jean Louis; +Cc: Heime via Users list for the GNU Emacs text editor

------- Original Message -------
On Thursday, October 20th, 2022 at 9:02 PM, Jean Louis <bugs@gnu.support> wrote:


> * 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:
 
So you use hash table because it is fast to process.

Nevertheless, my question is more focused on the best way to insert
utf8 characters in COLLECTION.  Is it acceptable to include utf8 characters
in COLLECTION?  From where does one copy the utf8 characters compatible with
emacs?




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Utf8 symbols in completing-read completion item
  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
@ 2022-10-21  0:11 ` Michael Heerdegen
  1 sibling, 0 replies; 9+ messages in thread
From: Michael Heerdegen @ 2022-10-21  0:11 UTC (permalink / raw)
  To: help-gnu-emacs

Heime via Users list for the GNU Emacs text editor
<help-gnu-emacs@gnu.org> writes:

> Am using "completing-read" to input greek letters.

You already know C-x 8 RET?  Try with GREEK RET in minibuffer for
example.

Michael.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Utf8 symbols in completing-read completion item
  2022-10-20 22:00   ` Heime
@ 2022-10-21  2:54     ` Jean Louis
  2022-10-21  3:33       ` Heime
  2022-10-21  6:18     ` Eli Zaretskii
  1 sibling, 1 reply; 9+ messages in thread
From: Jean Louis @ 2022-10-21  2:54 UTC (permalink / raw)
  To: Heime; +Cc: Heime via Users list for the GNU Emacs text editor

* Heime <heimeborgia@protonmail.com> [2022-10-21 01:04]:
> So you use hash table because it is fast to process.

No, but because it holds 2 values, and you explained you want one
value displayed, but different value used, that is why key and value
concept make sense.

> Nevertheless, my question is more focused on the best way to insert
> utf8 characters in COLLECTION.  Is it acceptable to include utf8 characters
> in COLLECTION?  From where does one copy the utf8 characters compatible with
> emacs?

Emacs works well with UTF-8. Question is rather where is the actual
problem?

-- 
Jean

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

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Utf8 symbols in completing-read completion item
  2022-10-21  2:54     ` Jean Louis
@ 2022-10-21  3:33       ` Heime
  2022-10-21  3:43         ` Michael Heerdegen
  0 siblings, 1 reply; 9+ messages in thread
From: Heime @ 2022-10-21  3:33 UTC (permalink / raw)
  To: Jean Louis; +Cc: Heime via Users list for the GNU Emacs text editor

------- Original Message -------
On Friday, October 21st, 2022 at 2:54 AM, Jean Louis <bugs@gnu.support> wrote:


> * Heime heimeborgia@protonmail.com [2022-10-21 01:04]:
> 
> > So you use hash table because it is fast to process.
> 
> 
> No, but because it holds 2 values, and you explained you want one
> value displayed, but different value used, that is why key and value
> concept make sense.
> 
> > Nevertheless, my question is more focused on the best way to insert
> > utf8 characters in COLLECTION. Is it acceptable to include utf8 characters
> > in COLLECTION? From where does one copy the utf8 characters compatible with
> > emacs?
> 
> 
> Emacs works well with UTF-8. Question is rather where is the actual
> problem?

Because I started inserting symbols not from "read-char-by-name" but by copying
the actual utf symbol from the web, which should have the same unicode for display
in emacs.  Is that acceptable to do?



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Utf8 symbols in completing-read completion item
  2022-10-21  3:33       ` Heime
@ 2022-10-21  3:43         ` Michael Heerdegen
  2022-10-21  4:16           ` Heime
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Heerdegen @ 2022-10-21  3:43 UTC (permalink / raw)
  To: help-gnu-emacs

Heime <heimeborgia@protonmail.com> writes:

> Because I started inserting symbols not from "read-char-by-name" but
> by copying the actual utf symbol from the web, which should have the
> same unicode for display in emacs.  Is that acceptable to do?

Ah - now I understand what you were trying to ask.  I think (and I do
not know much about this) if your interprogram copy encoding stuff is
not misconfigured that should all work fine out of the box.

Michael.




^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Utf8 symbols in completing-read completion item
  2022-10-21  3:43         ` Michael Heerdegen
@ 2022-10-21  4:16           ` Heime
  0 siblings, 0 replies; 9+ messages in thread
From: Heime @ 2022-10-21  4:16 UTC (permalink / raw)
  To: Michael Heerdegen; +Cc: help-gnu-emacs

------- Original Message -------
On Friday, October 21st, 2022 at 3:43 AM, Michael Heerdegen <michael_heerdegen@web.de> wrote:


> Heime heimeborgia@protonmail.com writes:
> 
> > Because I started inserting symbols not from "read-char-by-name" but
> > by copying the actual utf symbol from the web, which should have the
> > same unicode for display in emacs. Is that acceptable to do?
> 
> 
> Ah - now I understand what you were trying to ask. I think (and I do
> not know much about this) if your interprogram copy encoding stuff is
> not misconfigured that should all work fine out of the box.
> 
> Michael.

Wanted to ask, in case I would have to rode them again.  They are showing up
as expected.  Except for a few which have not been rendered - would I would 
think have some problem inside a utf-8 encoded page.  So I am updating
or removing only those.



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: Utf8 symbols in completing-read completion item
  2022-10-20 22:00   ` Heime
  2022-10-21  2:54     ` Jean Louis
@ 2022-10-21  6:18     ` Eli Zaretskii
  1 sibling, 0 replies; 9+ messages in thread
From: Eli Zaretskii @ 2022-10-21  6:18 UTC (permalink / raw)
  To: help-gnu-emacs

> Date: Thu, 20 Oct 2022 22:00:31 +0000
> From: Heime <heimeborgia@protonmail.com>
> Cc: Heime via Users list for the GNU Emacs text editor <help-gnu-emacs@gnu.org>
> Nevertheless, my question is more focused on the best way to insert
> utf8 characters in COLLECTION.  Is it acceptable to include utf8 characters
> in COLLECTION?  From where does one copy the utf8 characters compatible with
> emacs?

To avoid confusion, please use the correct terminology.  There's no
such thing as "utf8 characters"; UTF-8 is an _encoding_ used to
serialize Unicode character codepoints into a stream of bytes that can
then be written to a file or send via the network.  IOW, UTF-8 is a
sequence of one or more bytes that represent a Unicode codepoint.  The
correct terminology is "Unicode characters" or "non-ASCII characters"
(since you mean characters beyond the ASCII range).  Unicode
character codepoints are 32-bit entities, whereas their UTF-8 encoding
can take between 1 and 4 bytes.  Suggested reading:

  https://en.wikipedia.org/wiki/UTF-8

Also, _all_ Unicode characters are compatible with Emacs.



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-10-21  6:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).