[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/engine-mode 449c09afe5 26/71: Nest prefixed keymaps correc
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/engine-mode 449c09afe5 26/71: Nest prefixed keymaps correctly |
Date: |
Wed, 21 Dec 2022 09:59:09 -0500 (EST) |
branch: elpa/engine-mode
commit 449c09afe58372c76fc2729f252ef86d79c181d8
Author: Harry Schwartz <hello@harryrschwartz.com>
Commit: Harry Schwartz <hello@harryrschwartz.com>
Nest prefixed keymaps correctly
We'd been handling prefixes by defining a string `engine/keymap-prefix`
which contained the prefix, concatenating that with the `:keybinding`
when an engine was defined, and then binding the engine to that
resulting string. That's not great:
* Sometimes perfectly valid prefix keys aren't represented as
strings (e.g. `(kbd "s-/")`), so concatenation fails.
* Engines can't be automatically rebound to a new prefix once they've
been defined.
* Keymaps are just cleaner and easier to handle.
Instead, we're defining a proper keymap and doing away with
`engine/keymap-prefix`. This isn't great for backwards compatibility,
since folks may have been relying on setting that to get the correct
keymap. Sorry about that. =/
Now users will need to use `engine/set-prefix-key`, which binds the
keymap. This has the advantage of being a function, instead of just a
variable, so we should be able to modify it in the future without
disturbing the interface.
---
README.md | 10 +++-------
engine-mode.el | 29 ++++++++++++++++-------------
2 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/README.md b/README.md
index 108b6cbbb6..ac0be62837 100644
--- a/README.md
+++ b/README.md
@@ -80,17 +80,13 @@ As mentioned about, see the implementation of the
## Changing the keymap prefix
The default keymap prefix for `engine-mode` is `C-c /`. If you'd like
-to use a different prefix (say, `C-c s`), you can redefine it:
+to bind the keymap to an additional prefix (say, `C-c s`), you totally
+can:
```emacs
-(setq engine/keymap-prefix (kbd "C-c s"))
+(engine/set-keymap-prefix (kbd "C-c s"))
```
-Make sure you redefine the keymap prefix *before* you define your
-engines. `defengine` uses the prefix internally, so if you change the
-prefix after defining your engines you'll find that they still use the
-old prefix.
-
## Custom docstrings
`defengine` assigns each engine a reasonable default docstring, but
diff --git a/engine-mode.el b/engine-mode.el
index 6ad319178f..39067525ad 100644
--- a/engine-mode.el
+++ b/engine-mode.el
@@ -1,7 +1,7 @@
;;; engine-mode.el --- Define and query search engines from within Emacs.
;; Author: Harry R. Schwartz <hello@harryrschwartz.com>
-;; Version: 2015.05.19
+;; Version: 2015.06.13
;; URL: https://github.com/hrs/engine-mode/engine-mode.el
;; This file is NOT part of GNU Emacs.
@@ -23,7 +23,7 @@
;; results in your default browser.
;; The `defengine' macro can also take an optional key combination,
-;; prefixed with `engine/keymap-prefix' (which defaults to "C-c /"):
+;; prefixed with "C-c /":
;; (defengine duckduckgo
;; "https://duckduckgo.com/?q=%s"
@@ -50,17 +50,24 @@
;;; Code:
(eval-when-compile (require 'cl))
+(defvar engine-mode-map (make-sparse-keymap))
+(defvar engine-mode-prefixed-map (make-sparse-keymap))
+
(define-minor-mode engine-mode
"Minor mode for defining and querying search engines through Emacs.
\\{engine-mode-map}"
:global t
- :keymap (make-sparse-keymap))
+ :keymap engine-mode-map)
-(defcustom engine/keymap-prefix (kbd "C-c /")
- "Engine-mode keymap prefix."
- :group 'engine-mode
- :type 'string)
+(defun engine/set-keymap-prefix (prefix-key)
+ "Bind the engine-mode keymap to a new prefix.
+For example, to use \"C-c s\" instead of the default \"C-c /\":
+
+(engine/set-keymap-prefix (kbd \"C-c s\"))"
+ (define-key engine-mode-map prefix-key engine-mode-prefixed-map))
+
+(engine/set-keymap-prefix (kbd "C-c /"))
(defcustom engine/browser-function browse-url-browser-function
"The default browser function used when opening a URL in an engine.
@@ -96,12 +103,9 @@ Defaults to `browse-url-browser-function'."
(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 ,(engine/scope-keybinding keybinding))
+ `(define-key engine-mode-prefixed-map ,keybinding
(quote ,(engine/function-name engine-name)))))
(cl-defmacro defengine (engine-name search-engine-url &key keybinding
docstring (browser 'engine/browser-function) (term-transformation-hook
'identity))
@@ -130,8 +134,7 @@ In this case, searching for \"foobar\" will hit the url
The optional keyword argument `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 /'.
+Keybindings are in the `engine-mode-map', so they're prefixed.
For example, to search Wikipedia, use:
- [nongnu] elpa/engine-mode 3d4870c337 50/71: Fall back to the browse-url-browser-function, (continued)
- [nongnu] elpa/engine-mode 3d4870c337 50/71: Fall back to the browse-url-browser-function, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode f12a4e5ed1 03/71: rename engine -> engine-mode for consistency, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode 8851758d4d 21/71: Allow defengine to assign custom docstrings, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode 4e1d462a30 18/71: Add link to the EmacsNYC presentation, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode feb41a46e3 48/71: Escape docstring bol open-parentheses, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode 08d1a52ce6 43/71: Autoload engine-mode, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode def7195c87 55/71: Include dependency on format-spec, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode 75bca85a18 10/71: minor tweaks, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode bd2ea005b3 11/71: add a docstring for the defengine macro, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode c73489f15b 22/71: Add README documentation for custom docstrings, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode 449c09afe5 26/71: Nest prefixed keymaps correctly,
ELPA Syncer <=
- [nongnu] elpa/engine-mode e44d23f6c9 28/71: Add melpa-stable badge to README, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode c37373e36c 06/71: requiring engine-mode, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode 98020c5c8f 30/71: Update README text around Chrome script, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode 96b3488a6d 54/71: Bump version to 2.1.1, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode 30a361b27f 71/71: Remove the rfcs search engine from the docs, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode e99f205873 57/71: Document a definition of the Qwant search engine, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode 4f2abf66d9 53/71: Ensure that local keymaps aren't propagated, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode d99f9b4ab2 63/71: Prevent browse-url-browser-function shadowing, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode 7617af1c21 04/71: avoid multiple-evaluation issue for engine-name, ELPA Syncer, 2022/12/21
- [nongnu] elpa/engine-mode b84d806f75 07/71: fix documentation typo, ELPA Syncer, 2022/12/21