]> git.eshelyaron.com Git - emacs.git/commitdiff
Port term.el's terminfo machinery to Android
authorPo Lu <luangruo@yahoo.com>
Fri, 14 Jun 2024 08:21:55 +0000 (16:21 +0800)
committerEshel Yaron <me@eshelyaron.com>
Sat, 15 Jun 2024 17:21:14 +0000 (19:21 +0200)
* lisp/term.el (term-generate-db-directory): New function.  Copy
/assets/etc/e to the cache directory, on Android, and return the
same.
(term-exec-1): Call term-generate-db-directory in place of
data-directory.

(cherry picked from commit f66341a13be57bec6c89f75d26444b42ca3f1ecf)

lisp/term.el

index c15f6cf2e9f97278385e54a9526fea2a0bcf35a4..80be023764081393a7cceef59a4520a5876056d7 100644 (file)
@@ -1712,6 +1712,29 @@ Nil if unknown.")
                   "case $BASH_VERSION in [0123].*|4.[0123].*) exit 43;; esac")
                (error 0)))))))
 
+(defun term-generate-db-directory ()
+  "Return the name of a directory holding Emacs's terminfo files.
+If `data-directory' is accessible to subprocesses, as on systems besides
+Android, return the same and no more.  Otherwise, copy terminfo files
+from the same directory to a temporary location, and return the latter."
+  (if (not (featurep 'android))
+      data-directory
+    (progn
+      (let* ((dst-directory (expand-file-name "eterm-db/e"
+                                              temporary-file-directory))
+             (parent (directory-file-name
+                      (file-name-directory dst-directory)))
+             (src-directory (expand-file-name "e" data-directory)))
+        (when (file-newer-than-file-p src-directory dst-directory)
+          (message "Generating Terminfo database...")
+          (with-demoted-errors "Generating Terminfo database: %s"
+            ;; Arrange that the directory be writable.
+            (dolist (x (directory-files-recursively parent "" t t))
+              (set-file-modes x #o700))
+            (delete-directory dst-directory t)
+            (copy-directory src-directory dst-directory nil t t)))
+        parent))))
+
 ;; This auxiliary function cranks up the process for term-exec in
 ;; the appropriate environment.
 
@@ -1725,7 +1748,8 @@ Nil if unknown.")
         (nconc
          (list
           (format "TERM=%s" term-term-name)
-          (format "TERMINFO=%s" data-directory)
+          (format "TERMINFO=%s"
+                   (term-generate-db-directory))
           (format term-termcap-format "TERMCAP="
                   term-term-name term-height term-width)