From effba3d828bb3502edbbb56e34efbd3a2cd49969 Mon Sep 17 00:00:00 2001 From: JSDurand Date: Mon, 18 Aug 2025 18:08:13 +0800 Subject: input: Convert buffer region to a specified input method * input-conf.el (durand-convert-region-by-input-method): A helper to convert buffer text according to a chosen input method. I think this is sometimes convenient. --- input-conf.el | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/input-conf.el b/input-conf.el index ce01599..1ea7f0d 100644 --- a/input-conf.el +++ b/input-conf.el @@ -124,5 +124,24 @@ then enters the string STR, and returns the inputted string." (kill-buffer temp-buffer) result)) +(defun durand-convert-region-by-input-method (start end method) + "Convert the string in the region between START and END by the +input-method METHOD. + +See the function `durand-convert-string-by-input-method' for +more." + (interactive + (append + (cond ((region-active-p) + (list (region-beginning) (region-end))) + ((list (point) (point)))) + (list (read-input-method-name "By which input method: ")))) + (let* ((str (buffer-substring-no-properties start end)) + (converted + (durand-convert-string-by-input-method str method))) + (delete-region start end) + (goto-char start) + (insert converted))) + (provide 'input-conf) ;;; input-conf.el ends here -- cgit v1.2.3-18-g5258