branch: elpa/engine-mode commit 70bbde97bf39f5453ad93a5f6f1601d6bfccbb02 Author: Harry Schwartz <ha...@thoughtbot.com> Commit: Harry Schwartz <ha...@thoughtbot.com>
define a prefix key (which defaults to "C-c /") --- README.md | 11 ++++++----- engine-mode.el | 24 ++++++++++++++++++------ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 553dc818d2..020d3383d1 100644 --- a/README.md +++ b/README.md @@ -16,12 +16,13 @@ executed it will take the selected region (or prompt for input, if no region is selected) and search GitHub for it, displaying the results in your default browser. -The `defengine` macro can also take an optional key combination: +The `defengine` macro can also take an optional key combination, +prefixed with `engine/keymap-prefix' (which defaults to "C-c /"): ```emacs (defengine duckduckgo "https://duckduckgo.com/?q=%s" - "C-c / d") + "d") ``` `C-c / d` is now bound to the new function `engine/search-duckduckgo`! @@ -47,14 +48,14 @@ load path and globally enabling it: (defengine duckduckgo "https://duckduckgo.com/?q=%s" - "C-c / d") + "d") (defengine github "https://github.com/search?ref=simplesearch&q=%s") (defengine google "http://www.google.com/search?ie=utf-8&oe=utf-8&q=%s" - "C-c / g") + "g") (defengine google-images "http://www.google.com/images?hl=en&source=hp&biw=1440&bih=795&gbv=2&aq=f&aqi=&aql=&oq=&q=%s") @@ -76,7 +77,7 @@ load path and globally enabling it: (defengine wikipedia "http://www.wikipedia.org/search-redirect.php?language=en&go=Go&search=%s" - "C-c / w") + "w") (defengine wiktionary "https://www.wikipedia.org/search-redirect.php?family=wiktionary&language=en&go=Go&search=%s") diff --git a/engine-mode.el b/engine-mode.el index 7f9bb88f04..c8a565d32c 100644 --- a/engine-mode.el +++ b/engine-mode.el @@ -1,8 +1,8 @@ ;;; engine-mode.el --- Define and query search engines from within Emacs. ;; Author: Harry R. Schwartz <he...@harryrschwartz.com> -;; Version: 2014.05.06 -;; URL: https://github.com/hrs/engine-mode/engine.el +;; Version: 2014.05.12 +;; URL: https://github.com/hrs/engine-mode/engine-mode.el ;; This file is NOT part of GNU Emacs. @@ -22,11 +22,12 @@ ;; no region is selected) and search GitHub for it, displaying the ;; results in your default browser. -;; The `defengine' macro can also take an optional key combination: +;; The `defengine' macro can also take an optional key combination, +;; prefixed with `engine/keymap-prefix' (which defaults to "C-c /"): ;; (defengine duckduckgo ;; "https://duckduckgo.com/?q=%s" -;; "C-c / d") +;; "d") ;; `C-c / d' is now bound to the new function ;; engine/search-duckduckgo'! Nifty. @@ -54,6 +55,11 @@ :global t :keymap (make-sparse-keymap)) +(defcustom engine/keymap-prefix (kbd "C-c /") + "Engine-mode keymap prefix." + :group 'engine-mode + :type 'string) + (defun engine/search-prompt (engine-name) (concat "Search " (capitalize engine-name) ": ")) @@ -81,9 +87,12 @@ (capitalize (symbol-name engine-name)) " for the selected text. Prompt for input if none is selected.")) +(defun engine/scope-keybinding (keybinding) + (concat engine/keymap-prefix " " keybinding)) + (defun engine/bind-key (engine-name keybinding) (when keybinding - `(define-key engine-mode-map (kbd ,keybinding) + `(define-key engine-mode-map (kbd ,(engine/scope-keybinding keybinding)) (quote ,(engine/function-name engine-name))))) (defmacro defengine (engine-name search-engine-url &optional keybinding) @@ -95,11 +104,14 @@ standing in for the search term. The optional value `keybinding' is a string describing the key to bind the new function. +Keybindings are prefixed by the `engine/keymap-prefix', which +defaults to `C-c /'. + For example, to search Wikipedia, use: (defengine wikipedia \"http://www.wikipedia.org/search-redirect.php?language=en&go=Go&search=%s\" - \"C-c / w\") + \"w\") Hitting \"C-c / w\" will be bound to the newly-defined `engine/search-wikipedia' function."