1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Emacsで開いているファイルをPhpStorm/IntelliJ IDEAでひらく

Last updated at Posted at 2018-09-09

とっさにEmacsでファイルを開いてしまう癖があり、
PhpStorm/IntelliJ でファイルをまた探すのが面倒なので作りました。逆はこれ。

中身をみていただくとわかりますがopenコマンドの-aオプションをつけてアプリケーションを指定してるだけ。

init.el
(defun my/get-curernt-path ()
  (if (equal major-mode 'dired-mode)
      default-directory
	(buffer-file-name)))

;; 現在のファイルをPhpstormで開く
(defun open-phpstorm ()
  (interactive)
  (let ((fPath (my/get-curernt-path)))
    (when fPath
      (shell-command-to-string (concat "open -a /Applications/PhpStorm.app " fPath)))))

;; 現在のファイルをIntelliJ IDEAで開く
(defun open-idea ()
  (interactive)
  (let ((fPath (my/get-curernt-path)))
    (when fPath
      (shell-command-to-string (concat "open -a /Applications/IntelliJ\\ IDEA.app " fPath)))))

;; (global-set-key (kbd "C-c 5") 'open-phpstorm)
(global-set-key (kbd "C-c 5") 'open-idea)

おまけ

上記のelispを応用すればクリップボードにファイルのパスを保存したりFinderを開くことができる。

init.el
(defun my/copy-current-path ()
  (interactive)
  (let ((fPath (my/get-curernt-path)))
    (when fPath
      (message "stored path: %s" fPath)
      (kill-new (file-truename fPath)))))

;; 現在のbuffferのディレクトリをfinderで開く
(defun open-finder ()
  (interactive)
  (let ((fPath (file-name-directory (my/get-curernt-path))))
    (when fPath
      (shell-command-to-string (concat "open " fPath)))))


(global-set-key (kbd "C-c 1") 'my/copy-current-path)
(global-set-key (kbd "C-c 4") 'open-finder)

参考 Emacs で現在のファイルのパスを取得してクリップボードに保存 (org-link も)

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?