From 3cdf0b29133b89af66c72ac6cbedc6158e75ee4d Mon Sep 17 00:00:00 2001 From: Kyle Meyer Date: Mon, 15 Jun 2015 23:03:03 -0400 Subject: Use default value for webjump queries --- lisp/init-external.el | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'lisp') 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) -- cgit v1.2.3