Skip to content

Instantly share code, notes, and snippets.

@mechairoi
Last active December 12, 2015 06:38
Show Gist options
  • Save mechairoi/4730136 to your computer and use it in GitHub Desktop.
Save mechairoi/4730136 to your computer and use it in GitHub Desktop.
;;; Commentary
;; Select and activate google chrome tabs by anything interface
;;; Requirements
;; https://github.com/mechairoi/crxel
;;; Usage
;; (require 'anything-chrome-tabs)
;; (crxel/start 9649)
;; (define-key global-map "C-t" 'anything-chrome-tabs)
(provide 'anything-chrome-tabs)
(require 'crxel)
(require 'anything-config)
(defun chrome-tab-url (tab)
(cdr-safe (assq 'url tab)))
(defun chrome-tab-title (tab)
(cdr-safe (assq 'title tab)))
(defun chrome-tab-id (tab)
(cdr-safe (assq 'id tab)))
(defun chrome-activate-tab (tab)
(crxel/eval (format "chrome.tabs.update(%s, { active: true });"
(chrome-tab-id tab))
:fail 'error))
(defun anything-chrome-tabs ()
(interactive)
(crxel/eval "var callback = window.crxel.callback;
chrome.tabs.query({}, function(tabs) {
callback(JSON.stringify(tabs));
});"
:async t
:success (lambda (data)
(anything-chrome-tabs-0
(append
(json-read-from-string data) nil)))
:fail 'error))
(defun anything-chrome-tabs-0 (tabs)
(anything-other-buffer
`((name . "Chrome Tabs")
(candidates . ,tabs)
(action . (("Activate" . chrome-activate-tab)))
(candidate-transformer . (lambda (tabs)
(mapcar (lambda (tab)
(cons
(concat
(chrome-tab-url tab)
"\n"
(chrome-tab-title tab))
tab)) tabs)))
(migemo)
(multiline))
"*anything chrome tabs*"))
@tmaeda
Copy link

tmaeda commented Mar 9, 2014

これは興味深いですね。

一点間違いを見つけましたのでお知らせです。
quote が足りないようです。

;;  (define-key global-map "C-t" 'anything-chrome-tabs)

@mechairoi
Copy link
Author

おお、指摘ありがとうございます!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment