LoginSignup
4
5

More than 5 years have passed since last update.

EmacsからVimiumを操作する

Posted at

「EmacsからChromeを操作する」のつづきです
もうちょっとだけ操作性を向上させます

何ができるの?

Emacsからフォーカスを外すことなく、Chromeアプリ「Vimium」を起動・操作できます
(Vimium: The Hacker's Browser. Vimium provides keyboard shortcuts for navigation and control in the spirit of Vim.)

untitled2.gif

どうやるの?

AppleScriptの準備

Vimium起動用のAppleScript

Google Chrome上でFキーを押す動きをシミュレート

ファイル名: chrome_vimium

#!/usr/bin/osascript

tell application "Google Chrome" to activate
tell application "System Events"
     tell process "Google Chrome"
           keystroke "f"
     end tell
end tell

tell application "Emacs" to activate

Vimium操作用のAppleScript

Google Chrome上に表示されたキーを押す動きをシミュレート

ファイル名: chrome_vimium_input

#!/usr/bin/osascript

-- 引数: 押したいキー
on run argv
   set myinput to (item 1 of argv)
   tell application "Google Chrome" to activate
   tell application "System Events"
    tell process "Google Chrome"
           keystroke myinput
    end tell
   end tell
   tell application "Emacs" to activate
end run

各スクリプトは適当なPathに配置して実行権限を付与してください

init.elの準備

;; Vimium起動用の関数
;; スクリプトへのPathはお好みで
(defun my-vimium()
  (interactive)
  (call-process-shell-command
   "~/shellscript/chrome_vimium/chrome_vimium&"
   nil 0))

;; お好みで
(global-set-key (kbd "H-e") 'my-vimium)

;; Vimium操作用の関数
;; スクリプトへのPathはお好みで
(defun my-vimium-input(my-input)
  (interactive "sString:")
  (call-process-shell-command
   (concat "~/shellscript/chrome_vimium/chrome_vimium_input " my-input)
   nil 0))

;; お好みで
(global-set-key (kbd "H-w") 'my-vimium-input)

実行

  1. Emacs上でM-x my-vimium (上記の例だと "H-e")
  2. Chromeにジャンプ用のキーが表示される
  3. Emacs上でM-x my-vimium-input(上記の例だと "H-w")
  4. Emacs上でジャンプしたいキーを入力

以上です!!

4
5
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
4
5