From bdf0aa7761d1c1a3bc0652b2fdc4a54b3acdb06a Mon Sep 17 00:00:00 2001 From: Torsten Hilbrich Date: Thu, 1 Oct 2020 19:22:47 +0200 Subject: dictionary: Allow searching for region content If a region is active when calling dictionary-search it will present the region's contents as default. Suggested-By: Jean Louis --- dictionary.el | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/dictionary.el b/dictionary.el index f9f2cc4..25f3514 100644 --- a/dictionary.el +++ b/dictionary.el @@ -1080,6 +1080,14 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"." (insert "\n"))) list)) +;; Returns a sensible default for dictionary-search: +;; - if region is active returns its contents +;; - otherwise return the word near the point +(defun dictionary-search-default () + (if (use-region-p) + (buffer-substring-no-properties (region-beginning) (region-end)) + (current-word t))) + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; User callable commands ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -1089,7 +1097,7 @@ If PATTERN is omitted, it defaults to \"[ \\f\\t\\n\\r\\v]+\"." "Search the `word' in `dictionary' if given or in all if nil. It presents the word at point as default input and allows editing it." (interactive - (list (let ((default (current-word t))) + (list (let ((default (dictionary-search-default))) (read-string (if default (format "Search word (%s): " default) "Search word: ") -- cgit v1.2.3