]> git.eshelyaron.com Git - emacs.git/commitdiff
Port Grep argument autodetection to Android
authorPo Lu <luangruo@yahoo.com>
Tue, 29 Apr 2025 00:28:16 +0000 (08:28 +0800)
committerEshel Yaron <me@eshelyaron.com>
Tue, 29 Apr 2025 07:33:35 +0000 (09:33 +0200)
* lisp/progmodes/grep.el (grep-hello-file): On Android, copy
sample text to a real directory.

(cherry picked from commit 3279194bf2c859e76c95045c80a033fc54094f07)

lisp/progmodes/grep.el

index c395be14c1b9dc9bc40446e04c240dd430c653af..b23eabe200e0bfcfeb396ef77487ee70e799f974 100644 (file)
@@ -703,13 +703,26 @@ first capture group of `grep-heading-regexp'.")
           (or result 0))))
 
 (defun grep-hello-file ()
-  (let ((result
-         (if (file-remote-p default-directory)
-             (make-temp-file (file-name-as-directory (temporary-file-directory)))
-           (expand-file-name "HELLO" data-directory))))
-    (when (file-remote-p result)
-      (write-region "Copyright\n" nil result))
-    result))
+  (cond ((file-remote-p default-directory)
+         (let ((file-name (make-temp-file
+                           (file-name-as-directory
+                            (temporary-file-directory)))))
+           (when (file-remote-p result)
+             (write-region "Copyright\n" nil result))))
+        ((and (eq system-type 'android) (featurep 'android)) 
+         ;; /assets/etc is not accessible to grep or other shell
+         ;; commands on Android, and therefore the template must
+         ;; be copied to a location that is.
+         (let ((temp-file (concat temporary-file-directory
+                                  "grep-test.txt")))
+           (prog1 temp-file
+             (unless (file-regular-p temp-file)
+               ;; Create a temporary file if grep-text.txt can't be
+               ;; overwritten.
+               (when (file-exists-p temp-file)
+                 (setq temp-file (make-temp-file "grep-test-")))
+               (write-region "Copyright\n" nil temp-file)))))
+        (t (expand-file-name "HELLO" data-directory))))
 
 ;;;###autoload
 (defun grep-compute-defaults ()