;;; -*- lexical-binding: t -*- ;; ;; this file: ;; https://dataswamp.org/~incal/emacs-init/get-search-string.el (require 'string) (defun get-search-string (ps) "Ask for a search string with the prompt string PS.\n If there is a region, use the region text as default. Otherwise use the word at point.\n The default string is killed, so it can be yanked and modified." (let*((default-search (if (use-region-p) (buffer-substring-no-properties (region-beginning) (region-end)) (let ((point-word (thing-at-point 'symbol t))) (if (stringp point-word) (decode-coding-string point-word 'utf-8-emacs-unix) "") ))) (max-len 20) (peek (if (> (length default-search) max-len) (format "%s..." (substring default-search 0 max-len)) default-search) )) (when (string-data-p default-search) (kill-new default-search) ) (read-string (format "%s" (if (string-data-p peek) (format "%s [%s]: " ps peek) (format "%s: " ps) )) nil nil default-search) )) (provide 'get-search-string)