42145
[spacemacs/layers/+web-services/search-
engine/](https://github.com/syl20bnr/spacemacs/tree/master/layers/%2Bweb-
services/search-engine)
を参考にして、`.spacemacs`における`dotspacemacs/layersのdotspacemacs-configuration-
layers`に`search-engine`を追加し、`dotspacemacs/user-config`に

```

    (push '(wikipedia-ja
            :name "ウィキペディア"
            :url "https://ja.wikipedia.org/w/index.php?search=%s")
          search-engine-alist)
    
```

を追加しました  
その後 `SPC q R (restart-emacs)` でSpacemacsを再起動して `SPC a / (search-engine-
select)` から"ウィキペディア"を選択すると

> "Wrong type argument: commandp, engine/search-wikipedia-ja"

とエラーが出て日本語ウィキペディアでの検索ができません(他の検索エンジンは正常に動作しています)  
現在使っている`.spacemacs`をリネームしSpacemacsを再起動してまっさらな`.spacemacs`に同様の操作を行っても結果は同じでした

ちなみに`HELM M-x (SPC SPC)`で engine/search で絞り込んだ結果には`engine/search-wikipedia-
ja`は存在していませんでした

何が間違っているのでしょうか？よろしくお願いします
CC BY-SA 3.0
2018-02-22T23:17:46.103
41938
2018-03-05T12:09:16.967
2018-02-24T20:35:46.867
27509
27509
question
emacs elisp spacemacs
Spacemacsのsearch-engineレイヤーの検索エンジンの新規登録に関して
`~/.emacs.d/layers/+web-services/search-engine` ディレクトリの packages.el および
funcs.el を編集すると Spacemacs のアップデートのときエラーが出てしまうので `~/.emacs.d/private/search-
engine-revision` ディレクトリを作成しそこに新規で packages.el および funcs.el を作り，.spacemacs の
`dotspacemacs-configuration-layers` に `search-engine-revision` を追加しました．

  * packages.el (投稿の都合上 URL は消去してありますが `~/.emacs.d/layers/+web-services/search-engine/packages.el` の URL と同じです)
```     (defconst search-engine-revision-packages

      '((search-engine :excluded t))
    (setq search-engine-packages
          '(engine-mode)
          search-engine-alist
          '((amazon
             :name "Amazon"
             :url "")
            (bing
             :name "Bing"
             :url "")
            (duck-duck-go
             :name "Duck Duck Go"
             :url "")
            (google
             :name "Google"
             :url "")
            (google-images
             :name "Google Images"
             :url "")
            (github
             :name "Github"
             :url "")
            (google-maps
             :name "Google Maps"
             :url "")
            (twitter
             :name "Twitter"
             :url "")
            (project-gutenberg
             :name "Project Gutenberg"
             :url "")
            (youtube
             :name "YouTube"
             :url "")
            (stack-overflow
             :name "Stack Overflow"
             :url "")
            (spacemacs-issues
             :name "Spacemacs Issues"
             :url "")
            (spacemacs-pullrequests
             :name "Spacemacs Pull Requests"
             :url "")
            (wikipedia
             :name "Wikipedia"
             :url "")
            (wolfram-alpha
             :name "Wolfram Alpha"
             :url "")
            ))
    
    (defun search-engine/init-engine-mode ()
      (use-package engine-mode
        :commands (defengine spacemacs/search-engine-select)
        :defines search-engine-alist
        :init
        (progn
          (spacemacs/set-leader-keys
            "a/" 'spacemacs/search-engine-select)
          (dolist (engine search-engine-alist)
            (let ((func (intern (format "engine/search-%S" (car engine)))))
              (autoload func "engine-mode" nil 'interactive))))
        :config
        (progn
          (engine-mode t)
          (dolist (engine search-engine-alist)
            (let* ((cur-engine (car engine))
                   (engine-url (plist-get (cdr engine) :url)))
              (eval `(defengine ,cur-engine ,engine-url)))))))
    
```

  * funcs.el
```     (with-eval-after-load "helm"

      (defun spacemacs/helm-search-engine-select ()
        "Set search engine to use with helm."
        (interactive)
        (helm :sources (helm-build-sync-source "Search Engines Revision"
                          :candidates (mapcar (lambda (engine)
                                                (cons (plist-get (cdr engine) :name)
                                                      (intern (format "engine/search-%S"
                                                                      (car engine)))))
                                              search-engine-alist)
                          :action (lambda (candidate) (call-interactively candidate))
                          :migemo t))))
    
    (defun spacemacs/ivy-search-engine-select ()
      "Set search engine to use with ivy."
      (interactive)
      (ivy-read "Search Engines: "
                (mapcar (lambda (engine)
                          (cons (plist-get (cdr engine) :name)
                                (intern (format "engine/search-%S"
                                                (car engine)))))
                        search-engine-alist)
                :action (lambda (candidate) (call-interactively (cdr candidate)))))
    
    (defun spacemacs/search-engine-select ()
      "Set search engine to use."
      (interactive)
      (search-engine/init-engine-mode)
      (if (configuration-layer/layer-usedp 'ivy)
          (call-interactively 'spacemacs/ivy-search-engine-select)
        (call-interactively 'spacemacs/helm-search-engine-select)))
    
```

これで .spacemacs の `dotspacemacs/user-config`
に以下のコードを追加すると日本語版スタック・オーバーフローと日本語版ウィキペディアも検索対象として helm で表示させ migemo
を用いて絞り込めるようになります．

```

      (push '(stack-overflow-ja
              :name "スタック・オーバーフロー"
              :url "https://ja.stackoverflow.com/search?q=%s")
            search-engine-alist)
      (push '(wikipedia-ja
              :name "ウィキペディア"
              :url "https://ja.wikipedia.org/w/index.php?search=%s")
            search-engine-alist)
    
```
CC BY-SA 3.0
2018-03-05T12:09:16.967
42145
2018-03-05T12:09:16.967
27509
41938
answer