emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

decode-coding-string gone awry?


From: David Kastrup
Subject: decode-coding-string gone awry?
Date: Sun, 13 Feb 2005 04:50:49 +0100
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

Hi,

I have the problem that within preview-latex there is a function that
assembles UTF-8 strings from single characters.  This function, when
used manually, mostly works.  It is called within a process sentinel
and fails rather consistently there with a current CVS Emacs.  I
include the code here since I don't know what might be involved here:
regexp-quote, substring, char-to-string etc.  The starting string is
taken from a buffer containing only ASCII (inserted by a process with
coding-system 'raw-text).

Output looks like shown below.


(defun preview-error-quote (string)
  "Turn STRING with potential ^^ sequences into a regexp.
To preserve sanity, additional ^ prefixes are matched literally,
so the character represented by ^^^ preceding extended characters
will not get matched, usually."
  (let (output case-fold-search)
    (while (string-match 
"\\^\\{2,\\}\\(\\(address@hidden)\\|[8-9a-f][0-9a-f]\\)"
                         string)
      (setq output
            (concat output
                    (regexp-quote (substring string
                                             0
                                             (- (match-beginning 1) 2)))
                    (if (match-beginning 2)
                        (concat
                         "\\(?:" (regexp-quote
                                  (substring string
                                             (- (match-beginning 1) 2)
                                             (match-end 0)))
                         "\\|"
                         (char-to-string
                          (logxor (aref string (match-beginning 2)) 64))
                         "\\)")
                      (char-to-string
                       (string-to-number (match-string 1 string) 16))))
            string (substring string (match-end 0))))
    (setq output (concat output (regexp-quote string)))
    (if (featurep 'mule)
        (prog2
            (message "%S %S " output buffer-file-coding-system)
            (setq output (decode-coding-string output 
buffer-file-coding-system))
          (message "%S\n" output))
      output)))

The prog2 is just for the sake of debugging.  What we get here is
something akin to

"r Weise \\$f\\$ um~\\$1\\$ erhöht und \\$e\\$" mule-utf-8-unix 
#("r Weise \\$f\\$ um~\\$1\\$ erh\xc2\x81Á\xc2\xb6ht und \\$e\\$" 0 26 nil 26 
28 (display "\\201" help-echo utf-8-help-echo untranslated-utf-8 129) 28 29 nil 
29 31 (display "\\266" help-echo utf-8-help-echo untranslated-utf-8 182) 31 43 
nil)

when this is called in a mule-utf-8-unix buffer with
(preview-error-quote "r Weise $f$ um~$1$ erh^^c3^^b6ht und $e$")

Namely, the decoding from utf-8 does not work.  The original strings
are multibyte before the conversion and look reasonable, with the
bytes produced by char-to-string.

Unfortunately, when I call this stuff by hand instead from the
process-sentinel, it mostly works, so it would appear to be dependent
on some uninitialized stuff or similar that is different in the
process sentinel.

Anybody have a clue what might go wrong here?

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum




reply via email to

[Prev in Thread] Current Thread [Next in Thread]