|
3 | 3 | ;; Author: Bob Weiner
|
4 | 4 | ;;
|
5 | 5 | ;; Orig-Date: 1-Nov-91 at 00:44:23
|
6 |
| -;; Last-Mod: 24-Aug-24 at 01:31:41 by Bob Weiner |
| 6 | +;; Last-Mod: 18-Nov-24 at 20:16:58 by Bob Weiner |
7 | 7 | ;;
|
8 | 8 | ;; SPDX-License-Identifier: GPL-3.0-or-later
|
9 | 9 | ;;
|
@@ -554,7 +554,7 @@ Used only if the function `image-mode' is defined."
|
554 | 554 | ;; link is later resolved.
|
555 | 555 | ;;
|
556 | 556 | (defcustom hpath:variables
|
557 |
| - '(hyperb:dir load-path exec-path Info-directory-list sm-directory) |
| 557 | + '(hyperb:dir hywiki-directory load-path exec-path Info-directory-list sm-directory) |
558 | 558 | "*List of Emacs Lisp variable symbols to substitute within matching link paths.
|
559 | 559 | Each variable value, if bound, must be either a pathname or a list of pathnames.
|
560 | 560 | When embedded within a path, the format is ${variable}."
|
@@ -940,14 +940,16 @@ if (hpath:remote-available-p) returns nil."
|
940 | 940 |
|
941 | 941 | (defun hpath:at-p (&optional type non-exist)
|
942 | 942 | "Return delimited path or non-delimited remote path at point, if any.
|
943 |
| -Path is expanded and normalized. World-Wide Web urls are ignored |
944 |
| -and therefore dealt with by other code. Delimiters may be: |
945 |
| -double quotes, open and close single quote, whitespace, or |
946 |
| -Texinfo file references. If optional TYPE is the symbol \\='file or |
947 |
| -\\='directory, then only that path type is accepted as a match. |
948 |
| -Only locally reachable paths are checked for existence. With |
949 |
| -optional NON-EXIST, nonexistent local paths are allowed. |
950 |
| -Absolute pathnames must begin with a `/' or `~'." |
| 943 | +Path is expanded and normalized. See `hpath:is-p' for how the path |
| 944 | +is normalized. |
| 945 | +
|
| 946 | +World-Wide Web urls are ignored and therefore dealt with by other |
| 947 | +code. Delimiters may be: double quotes, open and close single |
| 948 | +quote, whitespace, or Texinfo file references. If optional TYPE |
| 949 | +is the symbol \\='file or \\='directory, then only that path type |
| 950 | +is accepted as a match. Only locally reachable paths are checked |
| 951 | +for existence. With optional NON-EXIST, nonexistent local paths |
| 952 | +are allowed. Absolute pathnames must begin with a `/' or `~'." |
951 | 953 | (let ((path (hpath:delimited-possible-path non-exist))
|
952 | 954 | subpath)
|
953 | 955 | (when path
|
@@ -1063,7 +1065,7 @@ Make any existing path within a file buffer absolute before returning."
|
1063 | 1065 | ;; match to in-file #anchor references
|
1064 | 1066 | (string-match "\\`#[^+\'\"<>#]+\\'" path))
|
1065 | 1067 | (setq path (concat mode-prefix buffer-file-name path)))
|
1066 |
| - ((string-match "\\`\\([^#]+\\)\\(#[^#+]*\\)\\'" path) |
| 1068 | + ((string-match "\\`\\([^#]+\\)\\(#[^#+]*.*\\)\\'" path) |
1067 | 1069 | ;; file and #anchor reference
|
1068 | 1070 | (setq suffix (match-string 2 path)
|
1069 | 1071 | path (match-string 1 path))
|
@@ -2024,12 +2026,25 @@ prior to calling this function."
|
2024 | 2026 | (error ""))
|
2025 | 2027 | var-group)))
|
2026 | 2028 |
|
2027 |
| -(defun hpath:shorten (path) |
2028 |
| - "Shorten and return a PATH. |
| 2029 | +(defun hpath:shorten (path &optional relative-to) |
| 2030 | + "Shorten and return a PATH optionally RELATIVE-TO other path. |
| 2031 | +If RELATIVE-TO is omitted or nil, set it to `default-directory'. |
2029 | 2032 | Replace Emacs Lisp variables and environment variables (format of
|
2030 | 2033 | ${var}) with their values in PATH. The first matching value for
|
2031 | 2034 | variables like `${PATH}' is used. Then abbreviate any remaining
|
2032 | 2035 | path."
|
| 2036 | + (setq path (expand-file-name (hpath:substitute-value path))) |
| 2037 | + (unless relative-to |
| 2038 | + (setq relative-to default-directory)) |
| 2039 | + (when (stringp relative-to) |
| 2040 | + (setq relative-to (expand-file-name |
| 2041 | + (hpath:substitute-value relative-to)) |
| 2042 | + path |
| 2043 | + (cond ((string-equal path relative-to) |
| 2044 | + "") |
| 2045 | + ((string-equal (file-name-directory path) relative-to) |
| 2046 | + (file-name-nondirectory path)) |
| 2047 | + (t (hpath:relative-to path relative-to))))) |
2033 | 2048 | (hpath:abbreviate-file-name (hpath:substitute-var path)))
|
2034 | 2049 |
|
2035 | 2050 | (defun hpath:substitute-value (path)
|
|
0 commit comments