aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2021-11-09 07:01:54 +0100
committerStefan Kangas2021-11-09 07:02:14 +0100
commit719e90b6dd7f122578358ac2a3f9b0a5cfba5612 (patch)
treeee36c1bc03abcd173a16fd77780093cc5cef8dac
parente538122fa4839352e1b63e983ed4aed64d47ca0e (diff)
downloademacs-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.el42
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.
232OLD-NAME is a string or a list, as in `user-file'. 232OLD-NAME is a string or a list, as in `user-file'.
233 233
234This is an internal helper function to `user-file'." 234This 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.
248TYPE should be a symbol and is passed as an argument to 247TYPE should be a symbol and is passed as an argument to
249`user-directory'. 248`user-directory'.
250 249
2511. If NEW-NAME exists in the directory for TYPE, return it. 250Optional argument OLD-NAMES is a list of file names, either
251absolute or relative (see below).
252 252
2532. Else if OLD-NAME is non-nil and OLD-NAME exists, return OLD-NAME. 2531. 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
2573. Else return NEW-NAME in the directory for TYPE, creating the 2552. 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
261Note: in contrast with `locate-user-emacs-file', OLD-NAME is not 2603. If no file could be found, return NEW-NAME in the directory
262a relative but an absolute file name. This typically means that 261 for TYPE, creating the top level TYPE directory if it does not
263you will need to add an explicit \"~/\" at the beginning of the 262 exist (just as if calling `user-directory' directly).
264string, when converting calls from that function to this one." 263
264Note: in contrast to the OLD-NAME argument to
265`locate-user-emacs-file', file names in OLD-NAMES are not
266relative to the user home directory. When converting a call to
267that function to use this one, add \"~/\" at the beginning of the
268third 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)