Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

EmacsからVimiumを操作する

More than 1 year has passed since last update.

「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上でジャンプしたいキーを入力

以上です!!

blue0513
Emacs / Software Engineer at M3, Inc
https://blue0513.github.io/show_room/
m3dev
インターネット、最新IT技術を活用し日本・世界の医療を改善することを目指します
https://m3.recruitment.jp/engineer/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away