[Top][All Lists]

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

Re: Don't concat directories to file names

From: Juanma Barranquero
Subject: Re: Don't concat directories to file names
Date: Fri, 15 Jun 2007 13:21:37 +0200

On 6/15/07, Stephen J. Turnbull <address@hidden> wrote:

XEmacs doesn't enforce it (we can't without imposing a gratuitous
incompatibility, since until now Emacs hasn't really had the concept),


but the variable `user-init-directory' is available to any library
that wants an Emacs-specific place to put things.  This is normally
initialized to "~/.xemacs" by startup.el.

Then the recently introduced `user-emacs-directory' should be renamed
to `user-init-directory', or aliased, I think (but it doesn't make
much sense to alias a just created var). The variable currently must
end with a directory separator, but that could be fixed.

But all in all, what I'm interested is having a public function so
modules that currently do

 (defvar my-module-setup-file "~/.my-module-data")


 (defvar my-module-setup-file
  (cond ((file-exists-p "~/.my-module-data") "~/.my-module-data")
        ((file-directory-p "~/.emacs.d/" "~/.emacs.d/my-module-setup"))
        (t ...)))

can be easily transformed to

 (defvar my-module-setup-file
  (user-emacs-file "my-module-data"  ; back-compatible
                   "my-module-setup" ; optional, default to above

i.e. (it's a reworked version):

(defun user-emacs-file (name &optional new-name)
 "Convert NAME to an absolute per-user Emacs-specific path.
If \"~/NAME\" exists, or `user-emacs-directory' is nil, return \"~/NAME\".
Else, return \"`user-emacs-directory'/NEW-NAME\", or /NAME if NEW-NAME is nil."
  (let ((at-home (expand-file-name name (concat "~" init-file-user))))
    (if (or (file-readable-p at-home)
            (null user-emacs-directory))
      (or (file-accessible-directory-p (directory-file-name
          (progn (make-directory user-emacs-directory) t)  ;; don't
catch errors
          (expand-file-name (or new-name name) user-emacs-directory))))))

That function makes use of `user-emacs-directory' (that'd be
`user-init-directory', in XEmacs); uses `convert-standard-filename'
and, as requested, creates the ~/.emacs.d (~/.xemacs) directory on the

People wanting to use the same setup files in X?Emacs will have to
make user-(emacs|init)-directory point to the right place, or perhaps
set it to nil (and then `user-emacs-file' defers to ~/ and does not
try to create any dir).



reply via email to

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