all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Char code to Emacs string.
@ 2011-06-01  7:59 Oleksandr Gavenko
  2011-06-01  8:30 ` Thierry Volpiatto
  2011-06-01 13:12 ` Eli Zaretskii
  0 siblings, 2 replies; 6+ messages in thread
From: Oleksandr Gavenko @ 2011-06-01  7:59 UTC (permalink / raw)
  To: help-gnu-emacs

This code not work because 'make-char' do not understand 'unicode' arg
(which intended to print chars with it unicode code):

(let (i (start ?\x1B6) (end ?\x1B7C))
   (setq i start)
   (while (<= i end)
     (message "%s - %x" (make-char 'unicode i) i)
     (setq i (+ 1 i))
     ) )

How I can get list of possible CHARSET for 'make-char'
and how this code must be fixed to work properly?




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

* Re: Char code to Emacs string.
  2011-06-01  7:59 Char code to Emacs string Oleksandr Gavenko
@ 2011-06-01  8:30 ` Thierry Volpiatto
  2011-06-01 13:12 ` Eli Zaretskii
  1 sibling, 0 replies; 6+ messages in thread
From: Thierry Volpiatto @ 2011-06-01  8:30 UTC (permalink / raw)
  To: help-gnu-emacs

Oleksandr Gavenko <gavenko@bifit.com.ua> writes:

> This code not work because 'make-char' do not understand 'unicode' arg
> (which intended to print chars with it unicode code):
>
> (let (i (start ?\x1B6) (end ?\x1B7C))
>   (setq i start)
>   (while (<= i end)
>     (message "%s - %x" (make-char 'unicode i) i)
>     (setq i (+ 1 i))
>     ) )
>
> How I can get list of possible CHARSET for 'make-char'
> and how this code must be fixed to work properly?
You can use `string' instead of `make-char'


#+BEGIN_SRC emacs-lisp
(let ((start ?\x1B6)
      (end   ?\x1B7C))
  (while (<= start end)
    (message "%s - %x" (string start) start)
    (sit-for 0.2)
    (setq start (+ 1 start))))

#+END_SRC

To store in a list:(maybe more useful)

#+BEGIN_SRC emacs-lisp
(let ((start ?\x1B6)
      (end   ?\x1B7C)
      result)
  (while (<= start end)
    (push (cons (string start) start) result)
    (setq start (+ 1 start)))
  (nreverse result))
;; => (("ƶ" . 438) ("Ʒ" . 439) ("Ƹ" . 440) ("ƹ" . 441)...)
#+END_SRC

-- 
A+ Thierry
Get my Gnupg key:
gpg --keyserver pgp.mit.edu --recv-keys 59F29997 




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

* Re: Char code to Emacs string.
  2011-06-01  7:59 Char code to Emacs string Oleksandr Gavenko
  2011-06-01  8:30 ` Thierry Volpiatto
@ 2011-06-01 13:12 ` Eli Zaretskii
  2011-06-02 12:31   ` Oleksandr Gavenko
  1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2011-06-01 13:12 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Oleksandr Gavenko <gavenko@bifit.com.ua>
> Date: Wed, 01 Jun 2011 10:59:29 +0300
> 
> This code not work because 'make-char' do not understand 'unicode' arg
> (which intended to print chars with it unicode code):
> 
> (let (i (start ?\x1B6) (end ?\x1B7C))
>    (setq i start)
>    (while (<= i end)
>      (message "%s - %x" (make-char 'unicode i) i)
>      (setq i (+ 1 i))
>      ) )
> 
> How I can get list of possible CHARSET for 'make-char'
> and how this code must be fixed to work properly?

make-char is an obsolete function that makes no sense at all in
Unicode-based Emacs.  Don't use it.  And it wouldn't have helped you,
because it returns the numerical code point of the character.  That's
because in Emacs, a character is just an integer, so every function
that _creates_ characters always returns an integer value.

What you want is not the character, but its string representation.
That's what prin1-char is for.



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

* Re: Char code to Emacs string.
  2011-06-01 13:12 ` Eli Zaretskii
@ 2011-06-02 12:31   ` Oleksandr Gavenko
  2011-06-02 14:36     ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Oleksandr Gavenko @ 2011-06-02 12:31 UTC (permalink / raw)
  To: help-gnu-emacs

On 01.06.2011 16:12, Eli Zaretskii wrote:
>> From: Oleksandr Gavenko<gavenko@bifit.com.ua>
>> Date: Wed, 01 Jun 2011 10:59:29 +0300
>>
>> This code not work because 'make-char' do not understand 'unicode' arg
>> (which intended to print chars with it unicode code):
>>
>> (let (i (start ?\x1B6) (end ?\x1B7C))
>>     (setq i start)
>>     (while (<= i end)
>>       (message "%s - %x" (make-char 'unicode i) i)
>>       (setq i (+ 1 i))
>>       ) )
>>
>> How I can get list of possible CHARSET for 'make-char'
>> and how this code must be fixed to work properly?
>
> make-char is an obsolete function that makes no sense at all in
> Unicode-based Emacs.  Don't use it.  And it wouldn't have helped you,
> because it returns the numerical code point of the character.  That's
> because in Emacs, a character is just an integer, so every function
> that _creates_ characters always returns an integer value.
>
> What you want is not the character, but its string representation.
> That's what prin1-char is for.
>
Thanks for answer. I always have more generic question about string
coding conversion.

What if I have some bytes and know its charset/coding and want convert
to Emacs string?

I search for such functions and also how get list of coding names for they.

Any point to existing code or ather help welcome.
'info elisp' take a few knowledge in this area.




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

* Re: Char code to Emacs string.
  2011-06-02 12:31   ` Oleksandr Gavenko
@ 2011-06-02 14:36     ` Eli Zaretskii
  2011-06-08 13:39       ` Oleksandr Gavenko
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2011-06-02 14:36 UTC (permalink / raw)
  To: help-gnu-emacs

> From: Oleksandr Gavenko <gavenko@bifit.com.ua>
> Date: Thu, 02 Jun 2011 15:31:46 +0300
> 
> What if I have some bytes and know its charset/coding and want convert
> to Emacs string?

If I understand correctly what you want, it's decode-coding-string (if
those "bytes" are given a string) or decode-coding-region (if they are
in a buffer).

If this is not what you want, please explain why and provide more
details/context for what you want to accomplish.

> and also how get list of coding names for they.

Not sure what you mean here.  If you want the full list of the
encodings supported by Emacs, then "C-h C TAB" will show them.  Is
that you are looking for?



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

* Re: Char code to Emacs string.
  2011-06-02 14:36     ` Eli Zaretskii
@ 2011-06-08 13:39       ` Oleksandr Gavenko
  0 siblings, 0 replies; 6+ messages in thread
From: Oleksandr Gavenko @ 2011-06-08 13:39 UTC (permalink / raw)
  To: help-gnu-emacs

On 02.06.2011 17:36, Eli Zaretskii wrote:
>> From: Oleksandr Gavenko<gavenko@bifit.com.ua>
>> Date: Thu, 02 Jun 2011 15:31:46 +0300
>>
>> What if I have some bytes and know its charset/coding and want convert
>> to Emacs string?
>
> If I understand correctly what you want, it's decode-coding-string (if
> those "bytes" are given a string) or decode-coding-region (if they are
> in a buffer).
>
I get that I want by:

(insert (decode-coding-string (unibyte-string ?\x21 ?\xff) 'utf-16-le))
A
(insert (decode-coding-string (unibyte-string ?\x21 ?\xff) 'cp1251))
!я

Previously I use (string ?\xff ?\xfa) to make string, which
convert \?xXX to some coding, so I get that I do not want.

>> and also how get list of coding names for they.
>
> Not sure what you mean here.  If you want the full list of the
> encodings supported by Emacs, then "C-h C TAB" will show them.  Is
> that you are looking for?
>
Encodings supported by Emacs, which can be passed to funcs that require
CODING as argument.

Seems you provide that I need. Also these values accessed via
'(coding-system-list)'.




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

end of thread, other threads:[~2011-06-08 13:39 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-06-01  7:59 Char code to Emacs string Oleksandr Gavenko
2011-06-01  8:30 ` Thierry Volpiatto
2011-06-01 13:12 ` Eli Zaretskii
2011-06-02 12:31   ` Oleksandr Gavenko
2011-06-02 14:36     ` Eli Zaretskii
2011-06-08 13:39       ` Oleksandr Gavenko

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.