0
1

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 5 years have passed since last update.

CygwinでEmacs Diredを使ってWindowsアプリを起動する話

Posted at

はじめに

Emacs標準ファイラのDiredでWindowsアプリを起動したくなったので設定してみた

概要

既にdired-open.elというDiredからWindowsアプリでファイルを開くパッケージがリリースされているけれど、拡張子ごとに設定をしなければならないのが面倒だったので、追加パッケージ無しでWindowsの関連付けに基づいてファイルが開けるスクリプトを考えた。

環境

Windows10 Pro 64bit
Cygwin 64bit
GNU Emacs 26.3 (build 1, x86_64-pc-cygwin)

スクリプト

本体

CygwinにはWindowsコマンドプロンプトのSTARTコマンドに相当する、cygstartコマンドが存在するためこれを利用する。カーソル位置またはマークしたファイル/フォルダに対してcygstartコマンドを実行する。

;; markしたファイルに対して`cygstart`コマンドを実行する
(defun dired-do-open-with-application ()
  (interactive)
    (let ((files (dired-get-marked-files t current-prefix-arg)))
      (dired-do-shell-command "cygstart ?" nil files)))

ちなみに、MacOSの場合はcygstartの部分をopenコマンドに書き換えることで簡単に対応できる

キー割り当て

;; キーバインド
(define-key dierd-mode-map (kbd "C-c o") 'dired-do-open-with-application)
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?