Follow new-style (and also UCS-16) Cygwin symlinks.
authorOleksandr Gavenko <gavenkoa@gmail.com>
Fri, 30 Sep 2011 01:01:49 +0300
changeset 709 2cb49be54b21
parent 708 659c1d14b849
child 713 e321e3b0c550
Follow new-style (and also UCS-16) Cygwin symlinks.
.emacs-my
--- a/.emacs-my	Tue Sep 27 10:37:34 2011 +0300
+++ b/.emacs-my	Fri Sep 30 01:01:49 2011 +0300
@@ -255,11 +255,25 @@
   "If t 'cmdproxy.exe' will be used as shell. Affect on M-x shell like
   commands. If nil, 'sh' will be used." )
 
+(defun follow-cygwin-symlink ()
+  "Follow new-style (and also UCS-16) Cygwin symlinks."
+  (save-excursion
+    (goto-char 0)
+    (when (looking-at "!<symlink>\xff\xfe")
+      (find-alternate-file
+       (substring
+        (decode-coding-string
+         (buffer-substring (match-end 0) (point-max))
+         'utf-16-le)
+        0 -1)                           ; -1 for stripping final \0.
+       ))))
+
 (when (eq system-type 'windows-nt)
   (ignore-errors
     (require 'cygwin-mount)
     (cygwin-mount-activate)
     )
+  (add-hook 'find-file-hooks 'follow-cygwin-symlink)
   ;; Workaround for Cygwin shell, when set 'CYGWIN=noglob'. By default 'shell-quote-argument'
   ;; quoted by double '\' chars this cause failure.
   (defun shell-quote-argument (argument)