シェルモードに入るcd c:/dir/to/path
と、シェルモードがそれに追従しdefault-directory
、c:/dir/to/path
それは良いことです。しかし、特定のファイル(c:/another/dir/file.ext)にアクセスしているときに、入力せずに既存のシェルディレクトリをそのファイルに移動するにはどうすればよいcd c:/antoher/dir/file.ext
ですか?
emacsにそのための既存の機能はありますか? かなり探しましたが、残念ながら見つかりませんでした。
Win7 で Emacs 24.2.1 を使用しています。
編集:
以下のような見栄えの悪い関数を書きました。提案/アドバイスをいただければ幸いです (私は elisp の初心者です)。(プレフィックス付きの対話型呼び出しを使用すると、シェル バッファーと現在のディレクトリが表示されます。これよりも優れたものがすでに発明されているのではないかと繰り返し考えています)。
(defun my-shell-with-current-directory (&optional arg)
(interactive "P")
(let* ((sp (get-process "shell"))
(spbuf (and sp (process-buffer sp)))
(dir (if buffer-file-name (file-name-directory buffer-file-name) default-directory)))
(if (and arg sp spbuf dir)
(progn
(comint-simple-send sp (concat "cd /d " dir))
(display-buffer spbuf)
(save-excursion
(set-buffer spbuf)
(cd dir)
)
)
(progn
(shell)
(comint-simple-send sp "setlocal enableextensions")
)
)
)
)