Seiji Zenitani
zenit****@users*****
2005年 12月 17日 (土) 18:00:57 JST
Index: CarbonEmacsPackage/GPL/mac/mac-key-mode.el diff -u CarbonEmacsPackage/GPL/mac/mac-key-mode.el:1.7 CarbonEmacsPackage/GPL/mac/mac-key-mode.el:1.8 --- CarbonEmacsPackage/GPL/mac/mac-key-mode.el:1.7 Sat Dec 17 11:39:19 2005 +++ CarbonEmacsPackage/GPL/mac/mac-key-mode.el Sat Dec 17 18:00:57 2005 @@ -82,12 +82,12 @@ when `mac-key-mode' is on." :group 'mac-key-mode :type 'string) -(defcustom mac-key-use-smartactivate-osax nil - "If non-nil, `mac-key-show-in-finder' takes advandage of -Kurita-san's SmartActivate osax. For more details, visit -http://homepage.mac.com/tkurita/scriptfactory/." - :group 'mac-key-mode - :type 'boolean) + +(defvar mac-key-smartactivate-command nil + "Path to the activate command, provided by Kurita-san's SmartActivate package. +Visit http://homepage.mac.com/tkurita/scriptfactory/ for more details. +If non-nil, `mac-key-show-in-finder' takes advandage of it.") + (defvar mac-key-mode-map (let ((map (make-sparse-keymap))) @@ -221,7 +221,7 @@ (setq file dired-directory) (setq mode 'info)) (t - (setq mode 'open)) + (setq mode 'dir)) )) ((boundp 'buffer-file-name) (cond @@ -237,30 +237,30 @@ (cond ((eq mode 'info) - (do-applescript - (format " -try - tell application \"Finder\" - select (\"%s\" as POSIX file) - %s - end tell -on error - beep -end try" - (if (eq selection-coding-system 'sjis-mac) - (replace-regexp-in-string - "\\\\" "\\\\\\\\" - (encode-coding-string file selection-coding-system)) - (encode-coding-string file selection-coding-system)) - (if mac-key-use-smartactivate-osax - "ActivateProcess identifier \"com.apple.finder\"" - "activate") - ))) - ((eq mode 'open) - (shell-command "/usr/bin/open .")) - ) + ;; applescript error handling + ;; ref. http://fobj.com/hisa/w/CarbonEmacs.html + (condition-case err + (progn + (do-applescript + (format "tell application \"Finder\" to select (\"%s\" as POSIX file)" + (if (eq selection-coding-system 'sjis-mac) + (replace-regexp-in-string + "\\\\" "\\\\\\\\" + (encode-coding-string file selection-coding-system)) + (encode-coding-string file selection-coding-system)) + )) + (if mac-key-smartactivate-command + (shell-command + (concat mac-key-smartactivate-command + " -i com.apple.finder")) + (do-applescript "tell application \"Finder\" to activate")) + ) + (error err)) + ) + ((eq mode 'dir) + (shell-command "/usr/bin/open .")) - )) + ))) ;; Open Terminal.app @@ -268,27 +268,37 @@ (defun mac-key-open-terminal () "Document forthcoming..." (interactive) - (let ((dir "")) + (let ((dir nil)) + (cond - ((and (local-variable-p 'dired-directory) dired-directory) - (setq dir dired-directory)) - ((stringp (buffer-file-name)) - (setq dir (file-name-directory (buffer-file-name)))) + ((eq major-mode 'dired-mode) + (cond + ((string-match mac-key-remote-file-regexp dired-directory) + (error "Remote directories not supported")) + (t + (setq dir dired-directory)) + )) + ((boundp 'buffer-file-name) + (cond + ((string-match mac-key-remote-file-regexp buffer-file-name) + (error "Remote files not supported")) + (t + (setq dir (file-name-directory buffer-file-name))) + )) ) - (do-applescript - (format " -tell application \"Terminal\" - try - %s - do script with command \"cd %s\" - on error - beep - end try -end tell" dir -(if mac-key-use-smartactivate-osax - "ActivateProcess identifier \"com.apple.Terminal\"" - "activate") -)) + + (if (file-directory-p dir) + (condition-case err + (progn + (do-applescript + (format "tell application \"Terminal\" to do script with command \"cd %s\"" dir)) + (if mac-key-smartactivate-command + (shell-command + (concat mac-key-smartactivate-command + " -i com.apple.Terminal")) + (do-applescript "tell application \"Terminal\" to activate")) + ) + (error err))) ))