[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 783a511d1e3: Handle /assets and /content file names in `android-b
From: |
Po Lu |
Subject: |
master 783a511d1e3: Handle /assets and /content file names in `android-browse-url' |
Date: |
Thu, 15 Feb 2024 01:24:42 -0500 (EST) |
branch: master
commit 783a511d1e31b5c9e5f9cb8ec27fd91d1b9078c9
Author: Po Lu <luangruo@yahoo.com>
Commit: Po Lu <luangruo@yahoo.com>
Handle /assets and /content file names in `android-browse-url'
* lisp/net/browse-url.el (android-browse-url): New function.
* lisp/term/android-win.el (android-browse-url-internal): Update
function declaration.
* src/androidselect.c (Fandroid_browse_url): Rename to...
(Fandroid_browse_url_internal): ... this.
(syms_of_androidselect): Adjust to match.
---
lisp/net/browse-url.el | 2 +-
lisp/term/android-win.el | 44 ++++++++++++++++++++++++++++++++++++++++++++
src/androidselect.c | 20 +++++++++++++-------
3 files changed, 58 insertions(+), 8 deletions(-)
diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el
index bc2a7db9a8b..ddc57724343 100644
--- a/lisp/net/browse-url.el
+++ b/lisp/net/browse-url.el
@@ -1324,7 +1324,7 @@ and instant messengers instead of opening it in a web
browser."
:type 'boolean
:version "30.1")
-(declare-function android-browse-url "androidselect.c")
+(declare-function android-browse-url "../term/android-win")
;;;###autoload
(defun browse-url-default-android-browser (url &optional _new-window)
diff --git a/lisp/term/android-win.el b/lisp/term/android-win.el
index e0d252f17e0..b7b0920626e 100644
--- a/lisp/term/android-win.el
+++ b/lisp/term/android-win.el
@@ -480,5 +480,49 @@ the UTF-8 coding system."
(concat locale-base locale-modifier)))
+;; Miscellaneous functions.
+
+(declare-function android-browse-url-internal "androidselect.c")
+
+(defun android-browse-url (url &optional send)
+ "Open URL in an external application.
+
+URL should be a URL-encoded URL with a scheme specified unless
+SEND is non-nil. Signal an error upon failure.
+
+If SEND is nil, start a program that is able to display the URL,
+such as a web browser. Otherwise, try to share URL using
+programs such as email clients.
+
+If URL is a file URI, convert it into a `content' address
+accessible to other programs."
+ (when-let* ((uri (url-generic-parse-url url))
+ (filename (url-filename uri))
+ ;; If `uri' is a file URI and the file resides in /content
+ ;; or /assets, copy it to a temporary file before
+ ;; providing it to other programs.
+ (replacement-url (and (string-match-p
+ "/\\(content\\|assets\\)[/$]"
+ filename)
+ (prog1 t
+ (copy-file
+ filename
+ (setq filename
+ (make-temp-file
+ "local"
+ nil
+ (let ((extension
+ (file-name-extension
+ filename)))
+ (if extension
+ (concat "."
+ extension)
+ nil))))
+ t))
+ (concat "file://" filename))))
+ (setq url replacement-url))
+ (android-browse-url-internal url send))
+
+
(provide 'android-win)
;; android-win.el ends here.
diff --git a/src/androidselect.c b/src/androidselect.c
index 5b23c559d2c..61f1c6045db 100644
--- a/src/androidselect.c
+++ b/src/androidselect.c
@@ -237,15 +237,21 @@ DEFUN ("android-clipboard-exists-p",
Fandroid_clipboard_exists_p,
return rc ? Qt : Qnil;
}
-DEFUN ("android-browse-url", Fandroid_browse_url,
- Sandroid_browse_url, 1, 2, 0,
- doc: /* Open URL in an external application. URL should be a
-URL-encoded URL with a scheme specified unless SEND is non-nil.
-Signal an error upon failure.
+DEFUN ("android-browse-url-internal", Fandroid_browse_url_internal,
+ Sandroid_browse_url_internal, 1, 2, 0,
+ doc: /* Open URL in an external application.
+
+URL should be a URL-encoded URL with a scheme specified unless SEND is
+non-nil. Signal an error upon failure.
If SEND is nil, start a program that is able to display the URL, such
as a web browser. Otherwise, try to share URL using programs such as
-email clients. */)
+email clients.
+
+If URL is a file URI, convert it into a `content' address accessible to
+other programs. Files inside the /content or /assets directories cannot
+be opened through such addresses, which this function does not provide
+for. Use `android-browse-url' instead. */)
(Lisp_Object url, Lisp_Object send)
{
Lisp_Object value;
@@ -803,7 +809,7 @@ syms_of_androidselect (void)
defsubr (&Sandroid_set_clipboard);
defsubr (&Sandroid_get_clipboard);
defsubr (&Sandroid_clipboard_exists_p);
- defsubr (&Sandroid_browse_url);
+ defsubr (&Sandroid_browse_url_internal);
defsubr (&Sandroid_get_clipboard_targets);
defsubr (&Sandroid_get_clipboard_data);
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 783a511d1e3: Handle /assets and /content file names in `android-browse-url',
Po Lu <=