diff options
| author | Daniel Mendler <mail@daniel-mendler.de> | 2023-03-14 17:45:32 +0100 |
|---|---|---|
| committer | Daniel Mendler <mail@daniel-mendler.de> | 2023-03-14 17:45:32 +0100 |
| commit | 684ada93bb2e55366bbb48278d344025cfb69b75 (patch) | |
| tree | acf5844cfe82159e5f29cb01bcb27bb8f491efe9 /compat-29.el | |
| parent | 32e737b145fef05105e2bad4ca34ca41072e9569 (diff) | |
compat-29: Add directory-abbrev-apply and directory-abbrev-make-regexp
Diffstat (limited to 'compat-29.el')
| -rw-r--r-- | compat-29.el | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/compat-29.el b/compat-29.el index fee1f5c..c74a866 100644 --- a/compat-29.el +++ b/compat-29.el @@ -623,6 +623,31 @@ The variable list SPEC is the same as in `if-let*'." ;;;; Defined in files.el +(compat-defun directory-abbrev-make-regexp (directory) ;; <compat-tests:directory-abbrev-make-regexp> + "Create a regexp to match DIRECTORY for `directory-abbrev-alist'." + (let ((regexp + ;; We include a slash at the end, to avoid spurious + ;; matches such as `/usr/foobar' when the home dir is + ;; `/usr/foo'. + (concat "\\`" (regexp-quote directory) "\\(/\\|\\'\\)"))) + ;; The value of regexp could be multibyte or unibyte. In the + ;; latter case, we need to decode it. + (if (multibyte-string-p regexp) + regexp + (decode-coding-string regexp + (if (eq system-type 'windows-nt) + 'utf-8 + locale-coding-system))))) + +(compat-defun directory-abbrev-apply (filename) ;; <compat-tests:directory-abbrev-apply> + "Apply the abbreviations in `directory-abbrev-alist' to FILENAME. +Note that when calling this, you should set `case-fold-search' as +appropriate for the filesystem used for FILENAME." + (dolist (dir-abbrev directory-abbrev-alist filename) + (when (string-match (car dir-abbrev) filename) + (setq filename (concat (cdr dir-abbrev) + (substring filename (match-end 0))))))) + (compat-defun file-name-split (filename) ;; <compat-tests:file-name-split> "Return a list of all the components of FILENAME. On most systems, this will be true: |
