A question about URI handling.

Massimiliano Gubinelli <[email protected]> Fri, 7 Feb 2025 18:46:50 +0000
Newsgroups gmane.editors.texmacs.devel
Message-ID <[email protected]>
--===============3798466086723210369==
Content-Type: multipart/alternative;
	boundary="Apple-Mail=_C3FCB63B-4FF3-417E-B854-71E32553A95A"


--Apple-Mail=_C3FCB63B-4FF3-417E-B854-71E32553A95A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
	charset=utf-8

Hi all,

 I would like to initiate some conversation about specific aspects of =
the codebase, so that we gradually build some shared knowledge which is =
not necessarily distillable in more permanent documentation.

I was looking at the way the \hlink tag works, and in particular what =
happens when links are clicked.

I noted that TeXmacs allow very few schema:

url
url_general (string name, int type=3D URL_SYSTEM) {
  if (starts (name, "local:")) return url_local (name (6, N (name)));
  if (starts (name, "file://")) return url_file (name (7, N (name)));
  if (starts (name, "http://")) return url_http (name (7, N (name)));
  if (starts (name, "https://")) return url_https (name (8, N (name)));
  if (starts (name, "ftp://")) return url_ftp (name (6, N (name)));
  if (starts (name, "tmfs://")) return url_tmfs (name (7, N (name)));
  if (starts (name, "//")) return url_blank (name (2, N (name)));
  #ifdef OS_ANDROID
  if (starts (name, "content://")) return url_content (name (10, N =
(name)));
  #endif
  if (heuristic_is_path (name, type)) return url_path (name, type);
  if (heuristic_is_default (name, type)) return url_default (name, =
type);
  if (heuristic_is_mingw_default (name, type)) return url_mingw_default =
(name, type);
  if (type !=3D URL_CLEAN_UNIX) {
    if (heuristic_is_http (name)) return url_http (name);
    if (heuristic_is_ftp (name)) return url_ftp (name);
  }
  return url_get_name (name, type);
}

I would like to handle some more (some are OS specific, and this is ok). =
In general would be better that if a schema is not recognised, we just =
invoke the standard OS handler. (MacOS for example can handle a wide =
variety of schemas, some of them which are not standard, e.g. to refer =
to email in the Mail.app or to dates in Calendar.app).

What is the reason of the code duplication there? all the functions =
url_XXXX perform more or less all the same operations. Also why there is =
an #ifdef?=20

I understand there is a problem about parsing strings, since =E2=80=9C:=E2=
=80=9D can also mean union of paths and not only delimit the URL schema, =
but we could try to have a more versatile handling here.


Max






--Apple-Mail=_C3FCB63B-4FF3-417E-B854-71E32553A95A
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html;
	charset=utf-8

<html><head><meta http-equiv=3D"content-type" content=3D"text/html; =
charset=3Dutf-8"></head><body style=3D"overflow-wrap: break-word; =
-webkit-nbsp-mode: space; line-break: after-white-space;">Hi =
all,<div><br></div><div>&nbsp;I would like to initiate some conversation =
about specific aspects of the codebase, so that we gradually build some =
shared knowledge which is not necessarily distillable in more permanent =
documentation.</div><div><br></div><div>I was looking at the way the =
\hlink tag works, and in particular what happens when links are =
clicked.</div><div><br></div><div>I noted that TeXmacs allow very few =
schema:</div><div><br></div><div><div style=3D"color: rgb(204, 204, =
204); background-color: rgb(31, 31, 31); font-family: Menlo, Monaco, =
&quot;Courier New&quot;, monospace; font-size: 12px; line-height: 18px; =
white-space: pre;"><div><span style=3D"color: rgb(78, 201, =
176);">url</span></div><div><span style=3D"color: rgb(220, 220, =
170);">url_general</span> (<span style=3D"color: rgb(78, 201, =
176);">string</span> <span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(86, 156, 214);">int</span> =
<span style=3D"color: rgb(156, 220, 254);">type</span><span =
style=3D"color: rgb(212, 212, 212);">=3D</span> <span style=3D"color: =
rgb(86, 156, 214);">URL_SYSTEM</span>) {</div><div>  <span style=3D"color:=
 rgb(197, 134, 192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">starts</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(206, 145, =
120);">"local:"</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_local</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span> <span style=3D"color: rgb(220, 220, =
170);">(</span><span style=3D"color: rgb(181, 206, 168);">6</span>, =
<span style=3D"color: rgb(220, 220, 170);">N</span> (<span style=3D"color:=
 rgb(156, 220, 254);">name</span>)<span style=3D"color: rgb(220, 220, =
170);">)</span>);</div><div>  <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">starts</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(206, 145, =
120);">"file://"</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_file</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span> <span style=3D"color: rgb(220, 220, =
170);">(</span><span style=3D"color: rgb(181, 206, 168);">7</span>, =
<span style=3D"color: rgb(220, 220, 170);">N</span> (<span style=3D"color:=
 rgb(156, 220, 254);">name</span>)<span style=3D"color: rgb(220, 220, =
170);">)</span>);</div><div>  <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">starts</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(206, 145, =
120);">"http://"</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_http</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span> <span style=3D"color: rgb(220, 220, =
170);">(</span><span style=3D"color: rgb(181, 206, 168);">7</span>, =
<span style=3D"color: rgb(220, 220, 170);">N</span> (<span style=3D"color:=
 rgb(156, 220, 254);">name</span>)<span style=3D"color: rgb(220, 220, =
170);">)</span>);</div><div>  <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">starts</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(206, 145, =
120);">"https://"</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_https</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span> <span style=3D"color: rgb(220, 220, =
170);">(</span><span style=3D"color: rgb(181, 206, 168);">8</span>, =
<span style=3D"color: rgb(220, 220, 170);">N</span> (<span style=3D"color:=
 rgb(156, 220, 254);">name</span>)<span style=3D"color: rgb(220, 220, =
170);">)</span>);</div><div>  <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">starts</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(206, 145, =
120);">"ftp://"</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_ftp</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span> <span style=3D"color: rgb(220, 220, =
170);">(</span><span style=3D"color: rgb(181, 206, 168);">6</span>, =
<span style=3D"color: rgb(220, 220, 170);">N</span> (<span style=3D"color:=
 rgb(156, 220, 254);">name</span>)<span style=3D"color: rgb(220, 220, =
170);">)</span>);</div><div>  <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">starts</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(206, 145, =
120);">"tmfs://"</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_tmfs</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span> <span style=3D"color: rgb(220, 220, =
170);">(</span><span style=3D"color: rgb(181, 206, 168);">7</span>, =
<span style=3D"color: rgb(220, 220, 170);">N</span> (<span style=3D"color:=
 rgb(156, 220, 254);">name</span>)<span style=3D"color: rgb(220, 220, =
170);">)</span>);</div><div>  <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">starts</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(206, 145, =
120);">"//"</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_blank</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span> <span style=3D"color: rgb(220, 220, =
170);">(</span><span style=3D"color: rgb(181, 206, 168);">2</span>, =
<span style=3D"color: rgb(220, 220, 170);">N</span> (<span style=3D"color:=
 rgb(156, 220, 254);">name</span>)<span style=3D"color: rgb(220, 220, =
170);">)</span>);</div><div>  <span style=3D"color: rgb(197, 134, =
192);">#ifdef</span><span style=3D"color: rgb(86, 156, 214);"> =
OS_ANDROID</span></div><div>  <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">starts</span> (name, <span style=3D"color: rgb(206, 145, =
120);">"content://"</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_content</span> (<span style=3D"color: rgb(220, 220, =
170);">name</span> (<span style=3D"color: rgb(181, 206, =
168);">10</span>, <span style=3D"color: rgb(220, 220, 170);">N</span> =
(name)));</div><div><span style=3D"color: rgb(197, 134, 192);">  =
#endif</span></div><div>  <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">heuristic_is_path</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(156, 220, =
254);">type</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_path</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(156, 220, =
254);">type</span>);</div><div>  <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">heuristic_is_default</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(156, 220, =
254);">type</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_default</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(156, 220, =
254);">type</span>);</div><div>  <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">heuristic_is_mingw_default</span> (<span style=3D"color: rgb(156, =
220, 254);">name</span>, <span style=3D"color: rgb(156, 220, =
254);">type</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_mingw_default</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(156, 220, =
254);">type</span>);</div><div>  <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(156, 220, 254);">type</span> =
<span style=3D"color: rgb(212, 212, 212);">!=3D</span> <span =
style=3D"color: rgb(86, 156, 214);">URL_CLEAN_UNIX</span>) {</div><div>  =
  <span style=3D"color: rgb(197, 134, 192);">if</span> (<span =
style=3D"color: rgb(220, 220, 170);">heuristic_is_http</span> (<span =
style=3D"color: rgb(156, 220, 254);">name</span>)) <span style=3D"color: =
rgb(197, 134, 192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_http</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>);</div><div>    <span style=3D"color: rgb(197, 134, =
192);">if</span> (<span style=3D"color: rgb(220, 220, =
170);">heuristic_is_ftp</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>)) <span style=3D"color: rgb(197, 134, =
192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_ftp</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>);</div><div>  }</div><div>  <span style=3D"color: =
rgb(197, 134, 192);">return</span> <span style=3D"color: rgb(220, 220, =
170);">url_get_name</span> (<span style=3D"color: rgb(156, 220, =
254);">name</span>, <span style=3D"color: rgb(156, 220, =
254);">type</span>);</div><div>}</div></div></div><div><br></div><div>I =
would like to handle some more (some are OS specific, and this is ok). =
In general would be better that if a schema is not recognised, we just =
invoke the standard OS handler. (MacOS for example can handle a wide =
variety of schemas, some of them which are not standard, e.g. to refer =
to email in the Mail.app or to dates in =
Calendar.app).</div><div><br></div><div>What is the reason of the code =
duplication there? all the functions url_XXXX perform more or less all =
the same operations. Also why there is an =
#ifdef?&nbsp;</div><div><br></div><div>I understand there is a problem =
about parsing strings, since =E2=80=9C:=E2=80=9D can also mean union of =
paths and not only delimit the URL schema, but we could try to have a =
more versatile handling =
here.</div><div><br></div><div><br></div><div>Max</div><div><br></div><div=
><br></div><div><br></div><div><br></div><div><br></div></body></html>=

--Apple-Mail=_C3FCB63B-4FF3-417E-B854-71E32553A95A--


--===============3798466086723210369==
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: base64
Content-Disposition: inline

X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KVGV4bWFjcy1k
ZXYgbWFpbGluZyBsaXN0ClRleG1hY3MtZGV2QGdudS5vcmcKaHR0cHM6Ly9saXN0cy5nbnUub3Jn
L21haWxtYW4vbGlzdGluZm8vdGV4bWFjcy1kZXYK

--===============3798466086723210369==--