summaryrefslogtreecommitdiff
path: root/lisp/subr.el
diff options
context:
space:
mode:
authorJuanma Barranquero <lekktu@gmail.com>2008-10-24 09:39:27 +0000
committerJuanma Barranquero <lekktu@gmail.com>2008-10-24 09:39:27 +0000
commitd6c180c46bcd0e492695aefee576d51a7bdf32e6 (patch)
tree5c234b6bd9501b91148dc39777f612b9fc1cadd8 /lisp/subr.el
parentecd43cb971723a8573afaa4ba6c8d50de7aa6db5 (diff)
downloademacs-d6c180c46bcd0e492695aefee576d51a7bdf32e6.tar.gz
New function `locate-user-emacs-file'.
* subr.el (locate-user-emacs-file): New function. (user-emacs-directory): Mention it in docstring. * completion.el (save-completions-file-name): * filesets.el (filesets-menu-cache-file): * image-dired.el (image-dired-dir, image-dired-db-file) (image-dired-temp-image-file, image-dired-gallery-dir) (image-dired-temp-rotate-image-file): * savehist.el (savehist-file): * server.el (server-auth-dir): * startup.el (auto-save-list-file-prefix): * thumbs.el (thumbs-thumbsdir): * tutorial.el (tutorial--saved-dir): * play/gamegrid.el (gamegrid-user-score-file-directory): Use it. * url.el (url-configuration-directory): Use `locate-user-emacs-file'. * NEWS: New function `locate-user-emacs-file'.
Diffstat (limited to 'lisp/subr.el')
-rw-r--r--lisp/subr.el19
1 files changed, 18 insertions, 1 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 40311c4e1f4..5a1f4d42ee2 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2156,7 +2156,24 @@ On other systems, this variable is normally always nil.")
"~/.emacs.d/")
"Directory beneath which additional per-user Emacs-specific files are placed.
Various programs in Emacs store information in this directory.
-Note that this should end with a directory separator.")
+Note that this should end with a directory separator.
+See also `locate-user-emacs-file'.")
+
+(defun locate-user-emacs-file (new-name &optional old-name)
+ "Return an absolute per-user Emacs-specific file name.
+If OLD-NAME is non-nil and ~/OLD-NAME exists, return ~/OLD-NAME.
+Else return NEW-NAME in `user-emacs-directory', creating the
+directory if it does not exist."
+ (convert-standard-filename
+ (let* ((home (concat "~" (or init-file-user "")))
+ (at-home (and old-name (expand-file-name old-name home))))
+ (if (and at-home (file-readable-p at-home))
+ at-home
+ (unless (or purify-flag ;; don't create dir while dumping
+ (file-accessible-directory-p
+ (directory-file-name user-emacs-directory)))
+ (make-directory user-emacs-directory t)) ;; don't catch errors
+ (expand-file-name new-name user-emacs-directory)))))
;;;; Misc. useful functions.