branch: externals/compat commit dd436797d16eda951c871cac370a5dadf654ce73 Author: Philip Kaludercic <phil...@posteo.net> Commit: Philip Kaludercic <phil...@posteo.net>
Add make-lock-file-name --- MANUAL | 1 + compat-28.el | 10 ++++++++++ compat-tests.el | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/MANUAL b/MANUAL index 5c202e9641..f7219f2cb1 100644 --- a/MANUAL +++ b/MANUAL @@ -395,6 +395,7 @@ provided by Compat by default: - Function: file-modes-number-to-symbolic :: See [[info:elisp#Changing Files][(elisp) Changing Files]]. - Function: file-backup-file-names :: See [[info:elisp#Backup Names][(elisp) Backup Names]]. +- Function: make-lock-file-name :: Defined in ~files.el~. These functions are prefixed with ~compat~ prefix, and are only loaded when ~compat-28~ is required: diff --git a/compat-28.el b/compat-28.el index 2d6a55bf4e..2f8c330355 100644 --- a/compat-28.el +++ b/compat-28.el @@ -675,6 +675,16 @@ recent files are first." (push candidate files)))) (sort files #'file-newer-than-file-p))) +(compat-defun make-lock-file-name (filename) + "Make a lock file name for FILENAME. +This prepends \".#\" to the non-directory part of FILENAME, and +doesn't respect `lock-file-name-transforms', as Emacs 28.1 and +onwards does." + (expand-file-name + (concat + ".#" (file-name-nondirectory filename)) + (file-name-directory filename))) + ;;;; Defined in minibuffer.el (compat-defun format-prompt (prompt default &rest format-args) diff --git a/compat-tests.el b/compat-tests.el index 6da09815c5..f59e33540b 100644 --- a/compat-tests.el +++ b/compat-tests.el @@ -1615,5 +1615,22 @@ being compared against." (ought "/:a" "/:a") (ought (concat "/ssh:" (system-name) ":/:a") "/ssh::a")) +(compat-deftest make-lock-file-name + (ought (expand-file-name ".#") "") + (ought (expand-file-name ".#a") "a") + (ought (expand-file-name ".#foo") "foo") + (ought (expand-file-name ".#.") ".") + (ought (expand-file-name ".#.#") ".#") + (ought (expand-file-name ".#.a") ".a") + (ought (expand-file-name ".#.#") ".#") + (ought (expand-file-name "a/.#") "a/") + (ought (expand-file-name "a/.#b") "a/b") + (ought (expand-file-name "a/.#.#") "a/.#") + (ought (expand-file-name "a/.#.") "a/.") + (ought (expand-file-name "a/.#.b") "a/.b") + (ought (expand-file-name "a/.#foo") "a/foo") + (ought (expand-file-name "bar/.#b") "bar/b") + (ought (expand-file-name "bar/.#foo") "bar/foo")) + (provide 'compat-tests) ;;; compat-tests.el ends here