ヽ(´・肉・`)ノログ

How do we fighting without fighting?

anyhting-c-rurema を作ってみよう

手順

  1. 1つ以上の情報源の
    • name 属性で情報源の名前を指定
  2. 候補を列挙し
    • candidate 属性で候補を求める方法(関数・変数・リスト)を指定
  3. 候補をパターンによって絞り込み
  4. 1つ以上のアクションを選択し
  5. アクションを実行
    • action 属性で指定

つまり

  1. name
  2. candidate
  3. action

の 3 つを定義すればいい.

scratch に以下を書いて C-M-x を押すと実行できる.

(setq anything-c-print-test-candidates '("Lisp" "Scheme" "Ruby"))
(defvar anything-c-source-print-test
  '((name . "Print Test")
    (candidates . (lambda () anything-c-print-test-candidates))
    (action . message)))

作ってみる

作り

呼び出し階層はこんな感じになっているようだ

(defvar anything-c-source-google-suggest
  '((name . "Google Suggest")
    (candidates . anything-c-google-suggest-set-candidates)
    (action . (("Google Search" . anything-c-google-suggest-action)))
    (volatile)
    (requires-pattern . 3)
    (delayed)))
(defun anything-c-google-suggest-set-candidates ()
  "Set candidates with result and number of google results found."
  (let ((suggestions (anything-c-google-suggest-fetch anything-input)))
    (setq suggestions (loop for i in suggestions
                         for interval = (- anything-gg-sug-lgh-flag (length (car i)))
                         for elm = (concat (car i)
                                           (make-string (+ 2 interval) ? )
                                           "(" (cdr i) " results)")
                         collect (cons elm (car i))))
    (if (some (lambda (data) (equal (cdr data) anything-input)) suggestions)
        suggestions
        ;; if there is no suggestion exactly matching the input then
        ;; prepend a Search on Google item to the list
        (append
         suggestions
         (list (cons (concat "Search for " "'" anything-input "'" " on Google")
                     anything-input))))))
(defun anything-c-google-suggest-action (candidate)
  "Default action to jump to a google suggested candidate."
  (let ((arg (concat anything-c-google-suggest-search-url
                                 (url-hexify-string candidate))))
    (anything-aif anything-c-google-suggest-default-browser-function
        (funcall it arg)
      (anything-c-browse-url arg))))
このエントリーをはてなブックマークに追加