diff --git a/rg.el b/rg.el index 5108a9d..e754380 100644 --- a/rg.el +++ b/rg.el @@ -144,6 +144,19 @@ Disabling this setting can break functionality of this package." :type 'boolean :group 'rg) +(defcustom rg-w32-unicode nil + "Enable Unicode support on Windows. +A workaround for NTEmacs subprocess not supporting Unicode arguments." + :type 'boolean + :group 'rg) + +(defcustom rg-w32-ripgrep-proxy + (expand-file-name "rg-w32-ripgrep-proxy.bat" user-emacs-directory) + "An automatically generated temporary batch file. +Used to proxy ripgrep Unicode arguments." + :type 'string + :group 'rg) + ;;;###autoload (defvar rg-command-line-flags-function 'identity "Function to modify command line flags of a search. @@ -297,10 +310,19 @@ are command line flags to use for the search." (when (member system-type '(darwin windows-nt)) (list "."))))) - (grep-expand-template - (mapconcat 'identity (cons (rg-executable) (delete-dups command-line)) " ") - pattern - (if (rg-is-custom-file-pattern files) "custom" files)))) + (let ((command (grep-expand-template + (mapconcat 'identity (cons (rg-executable) (delete-dups command-line)) " ") + pattern + (if (rg-is-custom-file-pattern files) "custom" files)))) + (cond ((and (eq system-type 'windows-nt) rg-w32-unicode) + (with-temp-file rg-w32-ripgrep-proxy + (set-buffer-multibyte t) + (setq buffer-file-coding-system 'utf-8-dos) + (insert (format "@echo off\n")) + (insert (format "chcp 65001 > nul\n")) + (insert (format "%s\n" command))) + rg-w32-ripgrep-proxy) + (t command))))) (defun rg-invoke-rg-type-list () "Invokes rg --type-list and return the result."