[Macemacsjp-users 865] Re: mac-key-mode.el with multibyte file/directory name

アーカイブの一覧に戻る

Nozomu Ando nand****@mac*****
2006年 1月 3日 (火) 05:06:57 JST


Nozomu Ando <nand****@mac*****> writes:
> mac-key-mode.el に関してですが、私の環境は英語環境だから、ということも
> あるのだと思いますが、マルチバイト文字を含むファイル名/ディレクトリ名に
> 関してうまく動かないようです。
>
> というわけで、mac-key-show-in-finder と mac-key-open-terminal に関して
> 改変してみました。CVS HEAD へのパッチを添付します。
>
> 変更点は:
>
> ファイル名を do-applescript に渡す時に <<data utf8xxxx>> as Unicode text
> の形式で渡す (<< >> は実際には mac-roman の ?\307 ?\310 で、
> xxxx は utf-8 の文字列のの16進表現)

この <<data utf8xxxx>> の形式では、高々 127 バイトのデータしか渡せない
ことがわかりました。申し訳ないです。

というわけで、文字列を分割して渡し、applescript 側で結合するようにしました。
CVS HEAD に対する diff です。

よろしくお願いします。
---
Nozomu Ando


*** mac-key-mode.el	01 Jan 2006 00:54:39 +0900	1.11
--- mac-key-mode.el	03 Jan 2006 04:40:09 +0900	
***************
*** 227,236 ****
  
  ;; utf8 code by Ando-san
  (defun mac-key-applescript-utf8data (str)
!   (concat "\307data utf8"
!           (mapconcat (lambda (ch) (format "%02X" ch))
!                      (encode-coding-string str 'utf-8) "")
!           "\310"))
  
  ;; Show In Finder
  
--- 227,248 ----
  
  ;; utf8 code by Ando-san
  (defun mac-key-applescript-utf8data (str)
!   (let ((len (length str))
! 	(len1 31) ;XXX: 254/2/4. utf-8 is 4byte per code point at most.
! 	(reslist '(")"))
! 	pos epos)
!     (setq pos len)
!     (while (> pos 0)
!       (setq epos pos)
!       (setq pos (max (- pos len1) 0))
!       (setq reslist (cons " & (\307data utf8"
! 			  (cons (mapconcat (lambda (ch) (format "%02X" ch))
! 					   (encode-coding-string
! 					    (substring str pos epos)
! 					    'utf-8) "")
! 				(cons "\310 as Unicode text)"
! 				      reslist)))))
!     (apply 'concat "(\"\"" reslist)))
  
  ;; Show In Finder
  
***************
*** 272,280 ****
            (progn
              (do-applescript
               (concat
!               "tell application \"Finder\" to select (("
                (mac-key-applescript-utf8data file)
!               " as Unicode text) as POSIX file)"))
  ;;              (format "tell application \"Finder\" to select (\"%s\" as POSIX file)"
  ;;                      (if (eq selection-coding-system 'sjis-mac)
  ;;                          (replace-regexp-in-string
--- 284,292 ----
            (progn
              (do-applescript
               (concat
!               "tell application \"Finder\" to select ("
                (mac-key-applescript-utf8data file)
!               " as POSIX file)"))
  ;;              (format "tell application \"Finder\" to select (\"%s\" as POSIX file)"
  ;;                      (if (eq selection-coding-system 'sjis-mac)
  ;;                          (replace-regexp-in-string
***************
*** 326,334 ****
              (progn
                (do-applescript
                 (concat "tell application \"Terminal\" to do script"
!                        " with command \"cd \" & quoted form of ("
!                        (mac-key-applescript-utf8data dir)
!                        " as Unicode text)"))
  ;;                (format "tell application \"Terminal\" to do script with command \"cd %s\"" dir))
                (if mac-key-smartactivate-command
                    (shell-command
--- 338,345 ----
              (progn
                (do-applescript
                 (concat "tell application \"Terminal\" to do script"
!                        " with command \"cd \" & quoted form of "
!                        (mac-key-applescript-utf8data dir)))
  ;;                (format "tell application \"Terminal\" to do script with command \"cd %s\"" dir))
                (if mac-key-smartactivate-command
                    (shell-command



Macemacsjp-users メーリングリストの案内
アーカイブの一覧に戻る