mozrepl でリロード、タブ操作、Google・ALC 検索

参考

(autoload 'moz-minor-mode "moz" "Mozilla Minor and Inferior Mozilla Modes" t)
(moz-minor-mode t)

(defun moz-close-tab-or-window ()
  (interactive)
  (comint-send-string (inferior-moz-process) "BrowserCloseTabOrWindow();"))
(global-set-key (kbd "C-M-c") 'moz-close-tab-or-window)

(defun moz-undo-close-tab ()
  (interactive)
  (comint-send-string (inferior-moz-process) "undoCloseTab();"))
(global-set-key (kbd "C-M-u") 'moz-undo-close-tab)

(defun moz-send-message (moz-command)
  (comint-send-string
   (inferior-moz-process)
   (concat moz-repl-name ".pushenv('printPrompt', 'inputMode'); "
           moz-repl-name ".setenv('inputMode', 'line'); "
           moz-repl-name ".setenv('printPrompt', false); undefined; "))
  (comint-send-string
   (inferior-moz-process)
   (concat moz-command
           moz-repl-name ".popenv('inputMode', 'printPrompt'); undefined;\n")))

(defun moz-reload ()
  (interactive)
  (comint-send-string (inferior-moz-process) "BrowserReload();"))
(global-set-key (kbd "C-<f5>") 'moz-reload)

(defun moz-next-tab ()
  (interactive)
  (moz-send-message "getBrowser().mTabContainer.advanceSelectedTab(1, true);\n"))
(global-set-key (kbd "C-M-.") 'moz-next-tab)

(defun moz-prev-tab ()
  (interactive)
  (moz-send-message "getBrowser().mTabContainer.advanceSelectedTab(-1, true);\n"))
(global-set-key (kbd "C-M-,") 'moz-prev-tab)

(defun moz-open-uri-in-new-tab (uri &optional param)
  (let ((p (if param param "")))
    (moz-send-message
     (concat
      "gBrowser.selectedTab = gBrowser.addTab();\n"
      (format
       "content.location=\"%s%s\";\n"
       uri
       (http-url-encode p 'utf-8)))))
  )

(defun moz-google-search (word)
  (interactive "sSearch Word: ")
  (moz-open-uri-in-new-tab "http://www.google.co.jp/search?hl=ja&q=" word)
  )
(global-set-key (kbd "C-<f3>") 'moz-google-search)

(defun moz-alc-search (word)
  (interactive "sSearch Word: ")
  (moz-open-uri-in-new-tab "http://eow.alc.co.jp/search?q=" word)
  )
(global-set-key (kbd "C-<f4>") 'moz-alc-search)