unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* display/encoding issue from python-code
@ 2024-08-12 12:45 Andreas Röhler
  2024-08-12 13:03 ` Stephen Berman
  0 siblings, 1 reply; 3+ messages in thread
From: Andreas Röhler @ 2024-08-12 12:45 UTC (permalink / raw)
  To: help-gnu-emacs@gnu.org

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

Hi,

got a display and encoding issue from some python-code:

day = [
     r'\d{2}',    #  "DD"
]

In a plain python-file all seems fine.

See attached align-day.py

But, check with the following snippet:

(defun my-test()
   (interactive)
   (set-buffer (get-buffer-create "my-test-buffer"))
   (switch-to-buffer (current-buffer))
   (python-mode)
   (insert "day = [
     r'\d{2}',    #  \"DD\"
]"))

In my-test-buffer instead of

r'\d

appears

r'^?

See attached my-test.png

Not only that it looks strange, ‘\d’ now seems to count as one character 
in buffer, so ‘string-match’ for example doesn't return the correct 
position any more.

Setting ‘buffer-file-coding-system’ to ‘utf-8-unix’ explicitly didn't help.

Any suggestion?

Thanks,
Andreas

GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.33, 
cairo version 1.16.0) of 2024-08-12

[-- Attachment #2: align-day.py --]
[-- Type: text/x-python, Size: 35 bytes --]

day = [
    r'\d{2}'    #  "DD" 
]

[-- Attachment #3: my-test.png --]
[-- Type: image/png, Size: 123187 bytes --]

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

* Re: display/encoding issue from python-code
  2024-08-12 12:45 display/encoding issue from python-code Andreas Röhler
@ 2024-08-12 13:03 ` Stephen Berman
  2024-08-12 18:22   ` Andreas Röhler
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Berman @ 2024-08-12 13:03 UTC (permalink / raw)
  To: Andreas Röhler; +Cc: help-gnu-emacs@gnu.org

On Mon, 12 Aug 2024 14:45:06 +0200 Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:

> Hi,
>
> got a display and encoding issue from some python-code:
>
> day = [
>     r'\d{2}',    #  "DD"
> ]
>
> In a plain python-file all seems fine.
>
> See attached align-day.py
>
> But, check with the following snippet:
>
> (defun my-test()
>   (interactive)
>   (set-buffer (get-buffer-create "my-test-buffer"))
>   (switch-to-buffer (current-buffer))
>   (python-mode)
>   (insert "day = [
>     r'\d{2}',    #  \"DD\"
> ]"))
>
> In my-test-buffer instead of
>
> r'\d
>
> appears
>
> r'^?
>
> See attached my-test.png
>
> Not only that it looks strange, ‘\d’ now seems to count as one character in
> buffer, so ‘string-match’ for example doesn't return the correct position any
> more.
>
> Setting ‘buffer-file-coding-system’ to ‘utf-8-unix’ explicitly didn't help.
>
> Any suggestion?

When using Lisp to insert a string containing a backslash, you have to
double the backslash:

(insert "day = [
    r'\\d{2}',    #  \"DD\"
]")

Steve Berman



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

* Re: display/encoding issue from python-code
  2024-08-12 13:03 ` Stephen Berman
@ 2024-08-12 18:22   ` Andreas Röhler
  0 siblings, 0 replies; 3+ messages in thread
From: Andreas Röhler @ 2024-08-12 18:22 UTC (permalink / raw)
  To: Stephen Berman; +Cc: help-gnu-emacs@gnu.org


Am 12.08.24 um 15:03 schrieb Stephen Berman:
> On Mon, 12 Aug 2024 14:45:06 +0200 Andreas Röhler <andreas.roehler@easy-emacs.de> wrote:
>
>> Hi,
>>
>> got a display and encoding issue from some python-code:
>>
>> day = [
>>      r'\d{2}',    #  "DD"
>> ]
>>
>> In a plain python-file all seems fine.
>>
>> See attached align-day.py
>>
>> But, check with the following snippet:
>>
>> (defun my-test()
>>    (interactive)
>>    (set-buffer (get-buffer-create "my-test-buffer"))
>>    (switch-to-buffer (current-buffer))
>>    (python-mode)
>>    (insert "day = [
>>      r'\d{2}',    #  \"DD\"
>> ]"))
>>
>> In my-test-buffer instead of
>>
>> r'\d
>>
>> appears
>>
>> r'^?
>>
>> See attached my-test.png
>>
>> Not only that it looks strange, ‘\d’ now seems to count as one character in
>> buffer, so ‘string-match’ for example doesn't return the correct position any
>> more.
>>
>> Setting ‘buffer-file-coding-system’ to ‘utf-8-unix’ explicitly didn't help.
>>
>> Any suggestion?
> When using Lisp to insert a string containing a backslash, you have to
> double the backslash:
>
> (insert "day = [
>      r'\\d{2}',    #  \"DD\"
> ]")
>
> Steve Berman


Oh yeah, thanks!





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

end of thread, other threads:[~2024-08-12 18:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-12 12:45 display/encoding issue from python-code Andreas Röhler
2024-08-12 13:03 ` Stephen Berman
2024-08-12 18:22   ` Andreas Röhler

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).