Created
July 20, 2010 05:42
-
-
Save miyamuko/482576 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; 拡張名を指定して Chrome Extension をファイラで開く | |
;; M-x open-chrome-extension | |
;; つづきは GitHub で! | |
;; http://github.com/miyamuko/chrome-extension-mode | |
(require "json") | |
(defun open-chrome-extension (&optional pattern) | |
(interactive "sExtension Name (Regexp): ") | |
(let ((manifest (find-chrome-extension pattern :regexp t :case-fold t))) | |
(unless manifest | |
(message "~S not found." pattern) | |
(return-from filer-chrome-extension nil)) | |
(message "Found ~A/~A (~A)" | |
(chrome-extension-name manifest) | |
(chrome-extension-version manifest) | |
(chrome-extension-dir manifest)) | |
(open-chrome-extension1 manifest))) | |
(defun open-chrome-extension1 (manifest) | |
(let ((*filer-primary-directory* (chrome-extension-dir manifest)) | |
(*filer-secondary-directory* (default-directory))) | |
(multiple-value-bind (files result) | |
(let ((omode (get-ime-mode))) | |
(unwind-protect | |
(filer nil t nil t (not *filer-modal*)) | |
(and *filer-modal* (toggle-ime omode)))) | |
(when result | |
(ed::filer-readin-1 files))))) | |
(defun find-chrome-extension (pattern &key regexp case-fold) | |
(let ((predicate (cond (regexp | |
(if (or (not case-fold) | |
(and (eq case-fold :smart) | |
(not (string-match "[A-Z]" pattern)))) | |
#'string-match | |
#'string-matchp)) | |
(t | |
(if case-fold | |
#'string-equal | |
#'string=))))) | |
(find-if #'(lambda (name) | |
(funcall predicate pattern name)) | |
(list-chrome-extensions) | |
:key 'chrome-extension-name))) | |
(defun chrome-extension-name (manifest) | |
(cdr (assoc "name" manifest :test #'string=))) | |
(defun chrome-extension-version (manifest) | |
(cdr (assoc "version" manifest :test #'string=))) | |
(defun chrome-extension-dir (manifest) | |
(cdr (assoc "__dir__" manifest :test #'string=))) | |
(defun list-chrome-extensions () | |
(mapcar #'(lambda (manifest-file) | |
(let ((manifest (json:json-decode-file manifest-file))) | |
(acons "__dir__" (directory-namestring manifest-file) manifest))) | |
(directory (get-chrome-extension-directory) :wild "manifest.json" :absolute t :recursive t))) | |
(defun list-chrome-extension-names () | |
(mapcar #'chrome-extension-name (list-chrome-extensions))) | |
(defun get-local-app-data-directory () | |
(or (si:getenv "LOCALAPPDATA") ; Vista/7 | |
(merge-pathnames "Local Settings/Application Data" (si:getenv "USERPROFILE")))) ; XP | |
(defun get-chrome-base-directory () | |
(merge-pathnames "Google/Chrome" (get-local-app-data-directory))) | |
(defun get-chrome-application-directory () | |
(merge-pathnames "Application" (get-chrome-base-directory))) | |
(defun get-chrome-user-data-directory () | |
(merge-pathnames "User Data" (get-chrome-base-directory))) | |
(defun get-chrome-extension-directory () | |
(merge-pathnames "Default/Extensions" (get-chrome-user-data-directory))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment