misc:software:Emacs:単独のEmacsでファイルを開く

misc:software:Emacs:単独のEmacsでファイルを開く

概要

DropFile.exe (DropFile.ahk) を使うと、単独のEmacsでファイルを開くことができる。 Emacsが既に起動していればそれを使ってファイルを開き、そうでなければEmacsを起動してからファイルを開く。

使い方

DropFile.exe Emacs "emacs.exeの絶対パス" "開くファイルのパス"

なお、DropFile.ahk のソースコードは次の通りである。

#NoEnv
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance force


my_ahk_class = ahk_class %1%
my_app_path = %2%
my_file_path = %3%

if (my_file_path){
  IfWinNotExist, % my_ahk_class
  {
    Run, % my_app_path
    WinWait, % my_ahk_class
  }
  DropFiles(WinExist(my_ahk_class), my_file_path)
}

ExitApp


DropFiles(hwnd, files, ptX=0, ptY=0, fNC=False) {
  static char_type:= A_IsUnicode ? "UShort" : "UChar"
   , char_size := A_IsUnicode ? 2 : 1
   , isUnicode := A_IsUnicode ? 1 : 0
  files := RTrim(files, "`r`n`t ") . "`n`n"
  byte_length := StrLen(files) * char_size
  Loop, Parse, files
  If (A_LoopField = "`n")
    NumPut(0x00, files, (A_Index-1) * char_size, char_type)
  hDrop := DllCall("GlobalAlloc", "UInt", 0x42, "UInt",20 + byte_length, "Ptr")
  p := DllCall("GlobalLock", "Ptr", hDrop)
  NumPut(20 , p + 00, "Int") ; offset
  NumPut(ptX , p + 04, "Int") ; pt.x
  NumPut(ptY , p + 08, "Int") ; pt.y
  NumPut(fNC , p + 12, "Int") ; fNC
  NumPut(isUnicode, p + 16, "Int") ; fWide
  DllCall("RtlMoveMemory", "Ptr", p + 20, "Str", files, "UInt", byte_length)
  DllCall("GlobalUnlock", "Ptr", hDrop)
  PostMessage, WM_DROPFILES := 0x233, hDrop , 0, , ahk_id %hwnd%
}

Last modified : 2013/06/18 01:53:41 JST