From 63cbebb994f82c7e3713e5ede5b3e46c98a34f6c Mon Sep 17 00:00:00 2001 From: Po Lu Date: Fri, 14 Jun 2024 16:21:55 +0800 Subject: [PATCH] Port term.el's terminfo machinery to Android * 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 | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lisp/term.el b/lisp/term.el index c15f6cf2e9f..80be0237640 100644 --- a/lisp/term.el +++ b/lisp/term.el @@ -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) -- 2.39.2