GNU TeXmacsUser manualReferenceAboutEnglish
The URL system

TeXmacs uses a tree representation for urls. This allows us to generalize the concept of an url and allow paths and patterns to be regarded as urls too. There are three main types of urls:

There are several formats for parsing (and printing) urls:

When an explicit operation on urls need to be performed, like reading a file, the url is first “resolved” into a single url with a unique name (modulo symbolic links) for the resource (first match). Next, the url is “concretized” as a system-specific file name which is understood by the operating system. Note that for remote urls this may involve downloading a file. Concretized urls should be used quickly and not memorized, since such names may be the names of temporary files, which can be destroyed afterwards.

From Scheme, urls are represented by a special data type; the routines below also accept strings, which are converted using the Unix format (the system format on Windows), so that ~, environment variables and the separators / and : may be used in them. The C++ implementation can be found in

System/Classes/url.cpp

and

System/Files/file.cpp

, and the glue definitions in

Scheme/Glue/build-glue-basic.scm

.

1.Construction and conversion

(string->url s)

(system->url s)

(unix->url s)
(parse a url)

Convert a string into a url, using the standard, the system and the unix format respectively. The routine (root->url r) creates a url with root (protocol) r, and (url-unix dir name) the concatenation of two strings in the unix format. The routine url->url returns its argument (it converts a string into a url).

(url->string u)

(url->system u)

(url->unix u)
(print a url)

Convert a url into a string, using the standard, the system and the unix format respectively. The routine (url->stree u) returns the internal tree representation of u.

(url-append u1 u2)

(url-or u1 u2)
(concatenation and alternatives)

Concatenate two urls (i.e. u2 relative to u1), resp. build the url which stands for either u1 or u2. The routine (url-ref u i) returns the child i (1 or 2) of a concatenation or of an alternative: since a:b:c is stored as a or (b or c), its second child is b:c. Use (url->list u) and (list->url l) to convert between alternatives and lists.

(url-none)

(url-any)

(url-wildcard pattern)

(url-parent)

(url-ancestor)

(url-pwd)
(special urls)

Respectively the url which matches nothing (tested by url-none?), the url which matches anything, a file name pattern with * wildcards (such as "*.tm"), the parent directory .., an arbitrary ancestor directory …, and the current working directory.

(url-temp)

(url-temp-dir)

(url-scratch prefix postfix i)
(temporary urls)

Return a fresh temporary file name, the directory for temporary files, and the first url prefixjpostfix with j⩾i which does not exist in the TeXmacs scratch directory $TEXMACS_HOME_PATH/texts/scratch (created if needed) (this is used for the names of new unnamed buffers, which satisfy url-scratch?).

2.Navigation

(go-to-url u . opt-from)
(Jump to the url @u)

Opens a new buffer with the contents of the resource at u. This can be either a full URL or a file path, absolute or relative to the current buffer-master. Both types of argument accept parameters. The second, optional argument, is an optional path for the cursor history.

You can pass parameters in u in two ways: appending a hash # and some text, like in some/path/some-file.tm#blah will open the file and jump to the first label of name blah found, if any; this works for TeXmacs, generic and Html files. The other possibility is the usual way in the web: append a question mark ? followed by pairs parameter=value. The parameters line, column and select, which respectively jump to the chosen location and select the given text at that line, are supported for the source code formats (Scheme, C++, Java, Scala, Python and Julia; see source-file-post in

link-navigate.scm

). The parameters are ignored for tmfs urls.

3.Predicates

(url-concat? u)
(Returns #t if @u contains multiple subdirs)

Scheme]

(url-concat? "a/b")

#t

Scheme]

(url-concat? "file.ext")

#f

(url-or? u)
(#t if the url contains an alternative)

Scheme]

(url-or? "a/b:c")

#t

Scheme]

(url-or? "a/b")

#f

On unix systems, the colon separates alternatives in the system format; on Windows, the semicolon is used instead. See also url-atomic?, which tests whether a url consists of a single name, and url-expand below.

(url-rooted? u)
(Test whether @u is absolute)

Return #t if the url is absolute. Absolute urls may be for instance full paths in the file system or internet URLs starting with a protocol specification like ftp or http. The tmfs urls are also understood to be rooted. See also url-rooted-tmfs?, url-rooted-web? and url-rooted-protocol?.

(url-rooted-tmfs? u)
(Test whether @u belongs to the TeXmacs file system)

Return #t if u is an URL of the form tmfs://…. Such URLs designate documents generated by Scheme handlers; see the TeXmacs file system. The variant (url-rooted-tmfs-protocol? u class) also checks that the first component after tmfs:// is class.

(url-descends? u base)
(Test whether @u lies below @base)

Test whether u equals or descends from base, in a purely syntactic way (the urls are not resolved). If base is an alternative, it suffices that u descends from one of them; if u is an alternative, all of them must descend from base. The predicate (url-secure? u) checks whether u descends from the $TEXMACS_SECURE_PATH.

Scheme]

(url-descends? "/a/b/c.tm" "/a")

#t

(url-regular? u)
(Test whether the url refers to regular file)

Applies only to filesystem urls. Returns #t if the url is a regular file, #f otherwise. See also url-directory? and url-link?.

Scheme]

(url-regular? "$TEXMACS_PATH/LICENSE")

#t

Scheme]

(url-directory? u)
(Test whether the url refers to a directory)

Applies only to filesystem urls. Returns #t if the url is a directory and it exists, #f otherwise.

Scheme]

(url-directory? "/tmp")

#t

Scheme]

(url-directory? "/tmp_not_exist")

#f

Scheme]

(url-directory? "$TEXMACS_PATH/LICENSE")

#f

Scheme]

(url-link? u)
(Test whether the url refers to a symbolic link)

Applies only to filesystem urls. Returns #t if the url is a symbolic link, #f otherwise.

(url-test? u filter)
(Test the type and permissions of a file)

The filter is a string of letters, all of which must be satisfied: f (regular file), d (directory), l (symbolic link), r, w, x (readable, writable, executable). Other letters are ignored, and the empty filter always succeeds.

(url-exists? u)

(url-exists-in-path? u)
(Test whether a file exists)

Test whether u resolves to an existing file, resp. whether an executable of name u exists in the $PATH.

(url-newer? u1 u2)

(url-last-modified u)

(url-size u)
(File attributes)

Test whether u1 was modified more recently than u2; return the time of the last modification of u (in seconds since the epoch); return the size of the file u in bytes.

4.Operations

(url-head u)
(Return the directory part of @u)

Scheme]

(url-head "/tmp")

<url />

Scheme]

(url-head "/tmp/a.out")

<url /tmp>

(url-tail u)
(Return the file name without path of @u)

Scheme]

(url-tail "/tmp")

<url tmp>

Scheme]

(url-tail "/tmp/hello.tm")

<url hello.tm>

(url-format u)
(Returns the file format of @u)

Determine the file format of u (such as "texmacs", "latex" or "generic") from its suffix; for a tmfs url, the format is given by the handler of its class (see tmfs-format).

(url-suffix u)
(Returns the suffix (extension) of @u)

Scheme]

(url-suffix "/tmp/hello.tm")

"tm"

(url-basename u)
(Return the basename as string for @u)

Scheme]

(url-basename "/tmp")

"tmp"

Scheme]

(url-basename "/tmp/hello.tm")

"hello"

(url-glue u s)
(Returns @u with suffix @s appended)

Scheme]

(url-glue (url-basename (current-buffer)) ".new")

<url url.en.new>

(url-unglue u n)
(Removes @n characters from the suffix of @u)

Scheme]

(url-unglue (current-buffer) 3) ;output edited

<url (…)/src/TeXmacs/doc/devel/scheme/api/url.en>

(url-relative base u)
(Prepends the head of @base to @u)

Scheme]

(url-relative "/a/b/c.tm" "d.tm")

<url /a/b/d.tm>

(url-delta base u)
(Computes the change in url from @base to @u)

Scheme]

(url-delta "/a/b/c/file.tm" "/a/b")

<url ../../b>

(url-root u)
(Returns the root (protocol) of @u)

Scheme]

(url-root (current-buffer))

"default"

Scheme]

(url-root "https://www.texmacs.org")

"https"

(url-unroot u)
(Removes the root (protocol) of @u)

Scheme]

(url-unroot "/a/b/c")

<url a/b/c>

Scheme]

(url-unroot "https://www.texmacs.org")

<url www.texmacs.org>

(url-expand u)

(url-factor u)
(Distribute concatenation over alternatives)

The routine url-expand rewrites a/(b:c) into a/b:a/c, and also expands the ancestor pattern …. The routine url-factor is the inverse operation; it also sorts the alternatives.

Scheme]

(url-expand (url-append "a" (url-or "b" "c")))

<url a/b:a/c>

The C++ routines reroot (change the protocol of a url) and sort (order the alternatives of a url) are not exported to Scheme.

5.File operations

(string-load u)

(string-save s u)

(string-append-to-file s u)
(read and write files)

Return the contents of the file u as a string, resp. write the string s into u, or append it at its end. Saving to a tmfs url goes through the handler of its class (see the TeXmacs file system), and appending to a tmfs url is a fatal error.

(system-copy from to)

(system-move from to)

(system-remove u)

(system-mkdir u)

(system-rmdir u)

(system-rmdir-recursive u)
(operations on files and directories)

Copy, move or remove files, create or remove a directory (which must be empty for system-rmdir), and remove a directory with all its contents. The routine (url-remove u) removes a file, through the handler of its class for a tmfs url.

(url-autosave u suffix)

(url-wrap u)

(url-backup u)

(url-backup? u)
(auxiliary files of a document)

The routine url-autosave returns the url where u is autosaved, u followed by suffix, or #f when the file cannot be autosaved (for a tmfs url, the handler decides). The routine url-wrap returns the url of the file wrapped by a tmfs url, if any. The routine url-backup returns the name of the backup of u in $TEXMACS_HOME_PATH/texts/backup, and url-backup? tests whether a url is such a backup. These routines are defined in

tm-files.scm

and

file.cpp

.

(url-cache-invalidate u)
(forget a downloaded file)

Remove the remote url u from the cache of downloaded files, so that it is downloaded again the next time it is used.

6.Resolution

The following routines take urls with alternatives and wildcards and look up the matching files. Here filter is a string as for url-test?; the default filter in C++ is "fr" (existing readable regular files).

(url-complete u filter)
(Find all matches)

Return the alternative of all files which match u and satisfy filter. For instance, (url-read-directory dir pattern) is implemented using url-complete and returns the list of files in dir matching the wildcard pattern:

(url-read-directory "$TEXMACS_PATH/styles" "*.ts")
(url-resolve u filter)
(Find the first match)

Like url-complete, but only return the first match, or (url-none) if there is none. The variant (url-resolve-in-path u) looks for an executable in the $PATH.

(url-search-upwards dir name stops)
(Find a file in a directory tree)

Look for a file called name in dir and its subdirectories; if there is none, look in the parent directory, and so on. The search goes up only while an ancestor directory has a name in the list of strings stops, and never beyond such a directory. The result is (url-none) if nothing is found.

(url-grep what u)
(Files which contain a string)

Return the alternative of the files matching u which contain the string what (the results are cached).

(url-resolve-pattern u)

(url-exists-in-tex? u)
(Special search paths)

Find a background pattern, also in the directories of $TEXMACS_PATTERN_PATH, resp. test whether a file can be found by the TeX tools (kpsewhich).

(url-concretize u)

(url-materialize u filter)
(System file name for a url)

The routine url-concretize returns the system specific file name for a resolved url; for remote urls this may involve downloading the file into a temporary file. The routine url-materialize first resolves u using filter and then concretizes the result. The variant url-concretize* returns a url instead of a string, url-sys-concretize returns a string which is escaped for use in shell commands, and system-url->string is the same as url-sys-concretize.

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".