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

posgtres/emacs interface utf-8 enablement



The attached patch, applied to

	http://www.chez.com/emarsden/download/pg.el

makes it possible to interface to PostgreSQL from Emacs/Mule-UCS using
Unicode.  Without this patch, the Lisp code crashes.

PostgreSQL multibyte characters can also be displayed using psql under the
new xterm with option -u8.

PostreSQL should be recompiled after ./configure --with-mb=UNICODE.

Moreover, I attached a better version of the 'textcoding' scsh program
sent here yesterday.  If I have time I'd like to try to bind iconvlib into
scsh.

--
phm
#!/usr/local/bin/scsh \
-e textcoding -s
!#

; find out the coding of a textfile that observes the Emacs File Variables convention
; (see the chapter on 'file variables' in the Emacs Info manual)

(define (displine str) (display (string-append str (string #\newline))))
(define (fatal err str) (displine str) (exit err))
(define (textfile? f) (regexp-search (rx "text") (run/string (file ,f))))
(define args '())
(define file "")
(define size 0)
(define codingre (rx (: bow "coding: " (submatch (** 4 24 (| alphanum "-"))) eow)))
(define port 0)
(define match #f)

(define (headgetcoding) 
  (let ((line (read-line port)))
    (set! match (regexp-search (rx (: "-*- " (submatch (+ any)) " -*-")) line))
    (and match   
	 (set! match (regexp-search codingre line) (match:substring match 1)))
    match))

(define (eofsearch re)
  (let loop ((line (read-line port)))
    (cond
     ((not (string? line)) #f)
     ((begin (set! match (regexp-search re line)) match) #t)
     (else (loop (read-line port)))
     ) ) )

(define (tailgetcoding)
  (seek port (max 0 (- size 800)))
  (and (eofsearch (rx "Local Variables:")) (eofsearch codingre))
  ) 

(define (textcoding command-line)
  (set! args (cdr command-line))
  (and (null? args) (fatal 5 "need 1 argument"))
  (set! file (car args))
  (or (file-readable? file) (fatal 4 "no such file"))
  (or (textfile? file) (fatal 3 "not even a text file"))
  (set! size (file-size file))
  (set! port (open-input-file file))
  (if (or (headgetcoding) (tailgetcoding)) 
      (displine (match:substring match 1))
      (displine "no coding found") 
      )
  (close port)
  (exit (if match 0 1))
)

; Local Variables:
; coding: utf-8
; mode: scheme
; End:
4a5,6
> ;;; 1999-01-20 patched for multibyte capability py Hartmut PILCH <phm@xxxxxxx>
> ;;;         thanks to hints from KATAYAMA Yoshio <kate@xxxxxxxxx>
303a306
> (defconst pg:coding-system nil "* set this to a coding system that postgres was compiled to work with.\nE.g., when Postgres as configured with --with-mb=UNICODE and is used from Mule-UCS-enabled Emacs, set this to 'utf-8")
320c323,325
<            (set-buffer-process-coding-system 'no-conversion 'no-conversion)))
---
>            (set-buffer-process-coding-system 'no-conversion 'no-conversion)
> 	   (set-buffer-multibyte nil)
> ))
513c518
< (defsubst pg:text-parser (str) str)
---
> (defsubst pg:text-parser (str) (if pg:coding-system (decode-coding-string str pg:coding-system) str))
860c865
<     (process-send-string process (concat str padding))))
---
>     (process-send-string process (concat (if pg:coding-system (encode-coding-string str pg:coding-system) str) padding))))