unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Chong Yidong <cyd@stupidchicken.com>
Cc: ihs_4664@yahoo.com, "Kim F. Storm" <storm@cua.dk>,
	rms@gnu.org, miles@gnu.org
Subject: init-dir unification (Was: Use .emacs.d in savehist.el)
Date: Fri,  4 Nov 2005 13:48:37 -0500 (EST)	[thread overview]
Message-ID: <20051104184837.28E2F1207E6@localhost.localdomain> (raw)

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)))
  \f
+ (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)))
+ \f
  ;; 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)))))
  \f
--- 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)))))
  \f
*** 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	other threads:[~2005-11-04 18:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-04 18:48 Chong Yidong [this message]
2005-11-05  7:55 ` init-dir unification Juri Linkov
2005-11-05 11:11   ` Chong Yidong
2005-11-05 12:29     ` Juri Linkov
2005-11-05 23:43 ` init-dir unification (Was: Use .emacs.d in savehist.el) Richard M. Stallman
2005-11-06 22:58   ` init-dir unification Chong Yidong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051104184837.28E2F1207E6@localhost.localdomain \
    --to=cyd@stupidchicken.com \
    --cc=ihs_4664@yahoo.com \
    --cc=miles@gnu.org \
    --cc=rms@gnu.org \
    --cc=storm@cua.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).