emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Files that begin with a period


From: Juanma Barranquero
Subject: Re: Files that begin with a period
Date: Mon, 20 Oct 2008 11:03:27 +0200

On Sun, Oct 19, 2008 at 22:04, Stefan Monnier <address@hidden> wrote:

> Nothing: I agree 100% with your change and just reminded that it would
> additionally be good to try and use user-emacs-directory (i.e. move
> those files into ~/.emacs.d).

Sixteen months ago we had a longish thread about introducing a new
function to help defaulting configuration files to .emacs.d (and
changing the name of `user-emacs-directory'):

http://lists.gnu.org/archive/html/emacs-devel/2007-06/msg00755.html

I have an old patch with the following:

--- lisp/subr.el        13 Jun 2007 00:03:28 -0000      1.555
+++ lisp/subr.el        25 Jun 2007 13:13:33 -0000
@@ -2042,5 +2042,5 @@
 (put 'cl-assertion-failed 'error-message "Assertion failed")

-(defconst user-emacs-directory
+(defconst user-data-directory
   (if (eq system-type 'ms-dos)
       ;; MS-DOS cannot have initial dot.
@@ -2049,5 +2049,21 @@
   "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-data-path'.")
+
+(defun locate-user-data-path (new-name &optional old-name)
+  "Return an absolute per-user Emacs-specific path.
+If OLD-NAME is non-nil and ~/OLD-NAME exists, return ~/OLD-NAME.
+Else return NEW-NAME in `user-data-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-data-directory)))
+        (make-directory user-data-directory t))  ;; don't catch errors
+      (expand-file-name new-name user-data-directory)))))

The idea was to help converting something like this:

(defcustom savehist-file
  (cond
   ;; Backward compatibility with previous versions of savehist.
   ((file-exists-p "~/.emacs-history") "~/.emacs-history")
   ((and (not (featurep 'xemacs)) (file-directory-p user-emacs-directory))
    (concat user-emacs-directory "history"))
   ((and (featurep 'xemacs) (file-directory-p "~/.xemacs/"))
    "~/.xemacs/history")
   ;; For users without `~/.emacs.d/' or `~/.xemacs/'.
   (t (convert-standard-filename "~/.emacs-history")))
  ...)

into

(defcustom savehist-file
  (locate-user-data-path "history" ".emacs-history")
  ...)

In the thread there was much discussion about names, and I haven't
tried to maintain the patch up-to-date. I still think a function like
this one would be helpful, though.

  Juanma




reply via email to

[Prev in Thread] Current Thread [Next in Thread]