summaryrefslogtreecommitdiff
path: root/lisp
diff options
context:
space:
mode:
authorKyle Meyer <kyle@kyleam.com>2015-06-15 23:03:03 -0400
committerKyle Meyer <kyle@kyleam.com>2015-06-15 23:03:03 -0400
commit3cdf0b29133b89af66c72ac6cbedc6158e75ee4d (patch)
tree2b49753c3c11538f7c0a36a3b20e77bf06fa92b8 /lisp
parent3f6259886af723b281c138a6ce79bf4ffae22789 (diff)
downloademacs.d-3cdf0b29133b89af66c72ac6cbedc6158e75ee4d.tar.gz
Use default value for webjump queries
Diffstat (limited to 'lisp')
-rw-r--r--lisp/init-external.el22
1 files changed, 21 insertions, 1 deletions
diff --git a/lisp/init-external.el b/lisp/init-external.el
index 836ab14..e1429f6 100644
--- a/lisp/init-external.el
+++ b/lisp/init-external.el
@@ -258,6 +258,26 @@ Otherwise, if ARG is non-nil, prompt with buffers from
[simple-query "wikipedia.org"
"wikipedia.org/wiki/" ""])))
-(define-key km/external-map "j" 'webjump)
+(defun km/webjump-read-string (prompt)
+ "Like `webjump-read-string', but set default."
+ (let* ((default (if (use-region-p)
+ (buffer-substring-no-properties
+ (region-beginning) (region-end))
+ (thing-at-point 'symbol)))
+ (prompt (if default
+ (format "%s (%s): " prompt default)
+ (concat prompt ": ")))
+ (input (read-string prompt nil nil default)))
+ (unless (webjump-null-or-blank-string-p input)
+ (substring-no-properties input))))
+
+(defun km/webjump ()
+ "Run`webjump' with symbol at point or region as default query.
+This affects only sites in the `simple-query' format."
+ (interactive)
+ (cl-letf (((symbol-function 'webjump-read-string) #'km/webjump-read-string))
+ (call-interactively #'webjump)))
+
+(define-key km/external-map "j" 'km/webjump)
(provide 'init-external)