diff options
| author | Stefan Kangas | 2021-11-09 07:01:54 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2021-11-09 07:02:14 +0100 |
| commit | 719e90b6dd7f122578358ac2a3f9b0a5cfba5612 (patch) | |
| tree | ee36c1bc03abcd173a16fd77780093cc5cef8dac | |
| parent | e538122fa4839352e1b63e983ed4aed64d47ca0e (diff) | |
| download | emacs-features/user-directory.tar.gz emacs-features/user-directory.zip | |
user-file: Change &optional OLD-NAME to &rest OLD-NAMESfeatures/user-directory
* lisp/user-directory.el (user-file): Change &optional OLD-NAME
argument into &rest OLD-NAMES. Significantly improve doc string.
(user-directory--find-old-name): Update for above change.
| -rw-r--r-- | lisp/user-directory.el | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/lisp/user-directory.el b/lisp/user-directory.el index 55fe50f7bad..884c877ce18 100644 --- a/lisp/user-directory.el +++ b/lisp/user-directory.el | |||
| @@ -227,14 +227,13 @@ of recently opened files probably belong here." | |||
| 227 | 227 | ||
| 228 | ;;;; user-file | 228 | ;;;; user-file |
| 229 | 229 | ||
| 230 | (defun user-directory--find-old-name (old-name) | 230 | (defun user-directory--find-old-name (old-names) |
| 231 | "Create a list of readable file names based on OLD-NAME. | 231 | "Create a list of readable file names based on OLD-NAMES. |
| 232 | OLD-NAME is a string or a list, as in `user-file'. | 232 | OLD-NAME is a string or a list, as in `user-file'. |
| 233 | 233 | ||
| 234 | This is an internal helper function to `user-file'." | 234 | This is an internal helper function to `user-file'." |
| 235 | (catch 'found | 235 | (catch 'found |
| 236 | (dolist (name (or (and (listp old-name) old-name) | 236 | (dolist (old-name old-names) |
| 237 | (list old-name))) | ||
| 238 | (mapcar (lambda (name) | 237 | (mapcar (lambda (name) |
| 239 | (when (file-readable-p name) | 238 | (when (file-readable-p name) |
| 240 | (throw 'found name))) | 239 | (throw 'found name))) |
| @@ -243,32 +242,37 @@ This is an internal helper function to `user-file'." | |||
| 243 | user-emacs-directory)))))) | 242 | user-emacs-directory)))))) |
| 244 | 243 | ||
| 245 | ;;;###autoload | 244 | ;;;###autoload |
| 246 | (defun user-file (type name &optional old-name) | 245 | (defun user-file (type name &rest old-names) |
| 247 | "Return an absolute per-user Emacs-specific file name. | 246 | "Return an absolute per-user Emacs-specific file name for NAME in directory TYPE. |
| 248 | TYPE should be a symbol and is passed as an argument to | 247 | TYPE should be a symbol and is passed as an argument to |
| 249 | `user-directory'. | 248 | `user-directory'. |
| 250 | 249 | ||
| 251 | 1. If NEW-NAME exists in the directory for TYPE, return it. | 250 | Optional argument OLD-NAMES is a list of file names, either |
| 251 | absolute or relative (see below). | ||
| 252 | 252 | ||
| 253 | 2. Else if OLD-NAME is non-nil and OLD-NAME exists, return OLD-NAME. | 253 | 1. If NAME exists in the user directory for TYPE, return it. |
| 254 | OLD-NAME is an absolute file name or a list of absolute file | ||
| 255 | names. If it is a list, try each of the names in the list. | ||
| 256 | 254 | ||
| 257 | 3. Else return NEW-NAME in the directory for TYPE, creating the | 255 | 2. Try each file name in OLD-NAMES in order, and return the first |
| 258 | directory if it does not exist. (Only the top level directory | 256 | one that exists and is readable. If a file name is relative, |
| 259 | for that type will be created, as with `user-directory'.) | 257 | first look for it in the user directory for TYPE and then in |
| 258 | `user-emacs-directory'. | ||
| 260 | 259 | ||
| 261 | Note: in contrast with `locate-user-emacs-file', OLD-NAME is not | 260 | 3. If no file could be found, return NEW-NAME in the directory |
| 262 | a relative but an absolute file name. This typically means that | 261 | for TYPE, creating the top level TYPE directory if it does not |
| 263 | you will need to add an explicit \"~/\" at the beginning of the | 262 | exist (just as if calling `user-directory' directly). |
| 264 | string, when converting calls from that function to this one." | 263 | |
| 264 | Note: in contrast to the OLD-NAME argument to | ||
| 265 | `locate-user-emacs-file', file names in OLD-NAMES are not | ||
| 266 | relative to the user home directory. When converting a call to | ||
| 267 | that function to use this one, add \"~/\" at the beginning of the | ||
| 268 | third argument." | ||
| 265 | (convert-standard-filename | 269 | (convert-standard-filename |
| 266 | (let* ((dir (user-directory type)) | 270 | (let* ((dir (user-directory type)) |
| 267 | (new-name (expand-file-name name dir))) | 271 | (new-name (expand-file-name name dir))) |
| 268 | (abbreviate-file-name | 272 | (abbreviate-file-name |
| 269 | (or (and old-name | 273 | (or (and old-names |
| 270 | (not (file-readable-p new-name)) | 274 | (not (file-readable-p new-name)) |
| 271 | (user-directory--find-old-name old-name)) | 275 | (user-directory--find-old-name old-names)) |
| 272 | new-name))))) | 276 | new-name))))) |
| 273 | 277 | ||
| 274 | (provide 'user-directory) | 278 | (provide 'user-directory) |