aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorsten Hilbrich <torsten.hilbrich@gmx.net>2020-10-01 19:22:47 +0200
committerTorsten Hilbrich <torsten.hilbrich@gmx.net>2020-10-01 19:27:48 +0200
commitbdf0aa7761d1c1a3bc0652b2fdc4a54b3acdb06a (patch)
tree2683db22a7deb48203e187a9d3af7bc367ad5cf5
parent46ee5d9ba15cac7282ed73c8b4c272a969c6159e (diff)
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 <bugs@gnu.support>
-rw-r--r--dictionary.el10
1 files changed, 9 insertions, 1 deletions
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: ")