emacs-devel
[Top][All Lists]
Advanced

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

init-dir unification (Was: Use .emacs.d in savehist.el)


From: Chong Yidong
Subject: init-dir unification (Was: Use .emacs.d in savehist.el)
Date: Fri, 4 Nov 2005 13:48:37 -0500 (EST)

I've coded up a proof-of-concept for handling .emacs.d/* with a common
interface.  The attached patch also includes changes to custom.el,
shell.el, and gamegrid.el, to help evaluate whether or not this is
actually useful in practice.

What do people think?  Is it worth making such a change?  Is there a
better way to do things?



*** emacs/lisp/simple.el.~1.760.~       2005-11-02 17:48:21.000000000 -0500
--- emacs/lisp/simple.el        2005-11-03 18:44:28.000000000 -0500
***************
*** 5368,5373 ****
--- 5368,5413 ----
         buffer-invisibility-spec)
      (setq buffer-invisibility-spec nil)))
  
+ (defun init-directory (&optional name create)
+   "Return the absolute directory name of an init directory.
+ If optional argument NAME is nil, the specified directory is a
+ directory, usually named .emacs.d, in the home directory of
+ `init-file-user'.  (On some operating systems, the directory may
+ be named differently from .emacs.d).
+ 
+ If NAME is a non-absolute filename, it specifies the name of a
+ subdirectory in .emacs.d.  If NAME is an absolute filename, it
+ specifies itself, rather than a subdirectory of .emacs.d.
+ 
+ If optional argument CREATE is non-nil, the directory and all of
+ its parent directories are created if they do not exist."
+   (let ((dir (convert-standard-filename
+             (if (and name (file-name-absolute-p name))
+                 name
+               (expand-file-name
+                (concat (file-name-as-directory
+                         (concat "~" init-file-user "/.emacs.d"))
+                        name))))))
+     (if create
+       (make-directory dir t))
+     (if (not (file-readable-p dir))
+       (error "Could not read directory %s" dir)
+       dir)))
+ 
+ (defun user-customization-file-name (name &optional subdirectory dotfile)
+   "Return the filename of a file NAME in the init directory.
+ If SUBDIRECTORY is non-nil, look in that subdirectory of the init
+ directory, which is usually named .emacs.d, in the home directory
+ of `init-file-user', creating the subdirectory and parent
+ directories if necessary.  (On some operating systems, the
+ directory may be named differently from .emacs.d).
+ 
+ If DOTFILE is non-nil, try that first."
+   (or (and dotfile
+          (file-readable-p (expand-file-name dotfile "~/"))
+          dotfile)
+       (concat (init-directory subdirectory t) name)))
+ 
  ;; Minibuffer prompt stuff.
  
  ;(defun minibuffer-prompt-modification (start end)
*** emacs/lisp/custom.el.~1.104.~       2005-10-24 12:17:11.000000000 -0400
--- emacs/lisp/custom.el        2005-11-03 17:43:16.000000000 -0500
***************
*** 1002,1012 ****
  (defvar custom-loaded-themes nil
    "Custom themes that have been loaded.")
  
! (defcustom custom-theme-directory
!   (if (eq system-type 'ms-dos)
!        ;; MS-DOS cannot have initial dot.
!        "~/_emacs.d/"
!       "~/.emacs.d/")
    "Directory in which Custom theme files should be written.
  `load-theme' searches this directory in addition to load-path.
  The command `customize-create-theme' writes the files it produces
--- 1002,1008 ----
  (defvar custom-loaded-themes nil
    "Custom themes that have been loaded.")
  
! (defcustom custom-theme-directory nil
    "Directory in which Custom theme files should be written.
  `load-theme' searches this directory in addition to load-path.
  The command `customize-create-theme' writes the files it produces
***************
*** 1056,1064 ****
    ;; Note we do no check for validity of the theme here.
    ;; This allows to pull in themes by a file-name convention
    (interactive "SCustom theme name: ")
!   (let ((load-path (if (file-directory-p custom-theme-directory)
!                      (cons custom-theme-directory load-path)
!                    load-path)))
      (require (or (get theme 'theme-feature)
                 (custom-make-theme-feature theme)))))
  
--- 1052,1061 ----
    ;; Note we do no check for validity of the theme here.
    ;; This allows to pull in themes by a file-name convention
    (interactive "SCustom theme name: ")
!   (let* ((dir (init-directory custom-theme-directory))
!          (load-path (if (file-directory-p dir)
!                         (cons dir load-path)
!                       load-path)))
      (require (or (get theme 'theme-feature)
                 (custom-make-theme-feature theme)))))
  
*** emacs/lisp/cus-theme.el.~1.13.~     2005-09-05 15:50:02.000000000 -0400
--- emacs/lisp/cus-theme.el     2005-11-03 17:42:15.000000000 -0500
***************
*** 107,118 ****
    (let ((name (widget-value custom-theme-name))
        (doc (widget-value custom-theme-description))
        (variables (widget-value custom-theme-variables))
!       (faces (widget-value custom-theme-faces)))
      (switch-to-buffer (concat name "-theme.el"))
      (emacs-lisp-mode)
!     (unless (file-exists-p custom-theme-directory)
!       (make-directory (file-name-as-directory custom-theme-directory) t))
!     (setq default-directory custom-theme-directory)
      (setq buffer-file-name (expand-file-name (concat name "-theme.el")))
      (let ((inhibit-read-only t))
        (erase-buffer))
--- 107,117 ----
    (let ((name (widget-value custom-theme-name))
        (doc (widget-value custom-theme-description))
        (variables (widget-value custom-theme-variables))
!       (faces (widget-value custom-theme-faces))
!       (dir (init-directory custom-theme-directory t)))
      (switch-to-buffer (concat name "-theme.el"))
      (emacs-lisp-mode)
!     (setq default-directory dir)
      (setq buffer-file-name (expand-file-name (concat name "-theme.el")))
      (let ((inhibit-read-only t))
        (erase-buffer))
*** emacs/lisp/shell.el.~1.133.~        2005-09-17 14:20:40.000000000 -0400
--- emacs/lisp/shell.el 2005-11-03 18:39:42.000000000 -0500
***************
*** 546,555 ****
      (let* ((prog (or explicit-shell-file-name
                     (getenv "ESHELL") shell-file-name))
           (name (file-name-nondirectory prog))
!          (startfile (concat "~/.emacs_" name))
           (xargs-name (intern-soft (concat "explicit-" name "-args"))))
-       (if (not (file-exists-p startfile))
-         (setq startfile (concat "~/.emacs.d/.emacs_" name)))
        (apply 'make-comint-in-buffer "shell" buffer prog
             (if (file-exists-p startfile) startfile)
             (if (and xargs-name (boundp xargs-name))
--- 546,555 ----
      (let* ((prog (or explicit-shell-file-name
                     (getenv "ESHELL") shell-file-name))
           (name (file-name-nondirectory prog))
!          (startfile (user-customization-file-name
!                      (concat "init." name) nil
!                      (concat ".emacs_" name)))
           (xargs-name (intern-soft (concat "explicit-" name "-args"))))
        (apply 'make-comint-in-buffer "shell" buffer prog
             (if (file-exists-p startfile) startfile)
             (if (and xargs-name (boundp xargs-name))
*** emacs/lisp/play/gamegrid.el.~1.22.~ 2005-08-01 11:30:16.000000000 -0400
--- emacs/lisp/play/gamegrid.el 2005-11-03 17:58:23.000000000 -0500
***************
*** 66,72 ****
  (defvar gamegrid-score-file-length 50
    "Number of high scores to keep")
  
! (defvar gamegrid-user-score-file-directory "~/.emacs.d/games"
    "A directory for game scores which can't be shared.
  If Emacs was built without support for shared game scores, then this
  directory will be used.")
--- 66,72 ----
  (defvar gamegrid-score-file-length 50
    "Number of high scores to keep")
  
! (defvar gamegrid-user-score-file-directory "games"
    "A directory for game scores which can't be shared.
  If Emacs was built without support for shared game scores, then this
  directory will be used.")
***************
*** 496,506 ****
          (gamegrid-shared-game-dir
           ;; If `gamegrid-shared-game-dir' is non-nil, then
           ;; "update-gamescore" program is setuid, so don't use it.
!          (unless (file-exists-p
!                   (directory-file-name gamegrid-user-score-file-directory))
!            (make-directory gamegrid-user-score-file-directory t))
!          (gamegrid-add-score-insecure file score
!                                       gamegrid-user-score-file-directory))
          (t (let ((f (expand-file-name
                       gamegrid-user-score-file-directory)))
               (when (file-writable-p f)
--- 496,503 ----
          (gamegrid-shared-game-dir
           ;; If `gamegrid-shared-game-dir' is non-nil, then
           ;; "update-gamescore" program is setuid, so don't use it.
!          (gamegrid-add-score-insecure
!             file score (init-directory gamegrid-user-score-file-directory t)))
          (t (let ((f (expand-file-name
                       gamegrid-user-score-file-directory)))
               (when (file-writable-p f)





reply via email to

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