unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* init-dir unification (Was: Use .emacs.d in savehist.el)
@ 2005-11-04 18:48 Chong Yidong
  2005-11-05  7:55 ` init-dir unification Juri Linkov
  2005-11-05 23:43 ` init-dir unification (Was: Use .emacs.d in savehist.el) Richard M. Stallman
  0 siblings, 2 replies; 6+ messages in thread
From: Chong Yidong @ 2005-11-04 18:48 UTC (permalink / raw)
  Cc: ihs_4664, Kim F. Storm, rms, miles

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)

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: init-dir unification
  2005-11-04 18:48 init-dir unification (Was: Use .emacs.d in savehist.el) Chong Yidong
@ 2005-11-05  7:55 ` Juri Linkov
  2005-11-05 11:11   ` Chong Yidong
  2005-11-05 23:43 ` init-dir unification (Was: Use .emacs.d in savehist.el) Richard M. Stallman
  1 sibling, 1 reply; 6+ messages in thread
From: Juri Linkov @ 2005-11-05  7:55 UTC (permalink / raw)
  Cc: miles, ihs_4664, storm, rms, emacs-devel

> What do people think?  Is it worth making such a change?  Is there a
> better way to do things?
>[...]
> ! (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"

It is misleading for users when such variable contains a name relative
to some other directory name instead of the absolute directory name.
I think a better way to do this is:

    (defvar gamegrid-user-score-file-directory (init-directory "games")

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: init-dir unification
  2005-11-05  7:55 ` init-dir unification Juri Linkov
@ 2005-11-05 11:11   ` Chong Yidong
  2005-11-05 12:29     ` Juri Linkov
  0 siblings, 1 reply; 6+ messages in thread
From: Chong Yidong @ 2005-11-05 11:11 UTC (permalink / raw)
  Cc: ihs_4664, storm, emacs-devel, rms, miles

>>   (defvar gamegrid-score-file-length 50
>>     "Number of high scores to keep")
>>   
>> ! (defvar gamegrid-user-score-file-directory "games"
>
> It is misleading for users when such variable contains a name relative
> to some other directory name instead of the absolute directory name.
> I think a better way to do this is:
>
>     (defvar gamegrid-user-score-file-directory (init-directory "games")

The idea is that the directory is not created until it is used.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: init-dir unification
  2005-11-05 11:11   ` Chong Yidong
@ 2005-11-05 12:29     ` Juri Linkov
  0 siblings, 0 replies; 6+ messages in thread
From: Juri Linkov @ 2005-11-05 12:29 UTC (permalink / raw)
  Cc: ihs_4664, storm, emacs-devel, rms, miles

>>> ! (defvar gamegrid-user-score-file-directory "games"
>>
>> It is misleading for users when such variable contains a name relative
>> to some other directory name instead of the absolute directory name.
>> I think a better way to do this is:
>>
>>     (defvar gamegrid-user-score-file-directory (init-directory "games")
>
> The idea is that the directory is not created until it is used.

Yes, that is why I removed the second argument `t' from the call to
your function `init-directory', so it will not create the directory
at the variable definition.  I think the directory should be created
immediately before the package starts writing the configuration file.

-- 
Juri Linkov
http://www.jurta.org/emacs/

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: init-dir unification (Was: Use .emacs.d in savehist.el)
  2005-11-04 18:48 init-dir unification (Was: Use .emacs.d in savehist.el) Chong Yidong
  2005-11-05  7:55 ` init-dir unification Juri Linkov
@ 2005-11-05 23:43 ` Richard M. Stallman
  2005-11-06 22:58   ` init-dir unification Chong Yidong
  1 sibling, 1 reply; 6+ messages in thread
From: Richard M. Stallman @ 2005-11-05 23:43 UTC (permalink / raw)
  Cc: ihs_4664, miles, storm, emacs-devel

The argument NAME to init-directory, and the argument SUBDIRECTORY of
user-customization-file-name, make the code harder to understand.  As
far as I can see, they are unnecessary.  Why do you think this is
necessary?  If there is no important reason for it, let's get rid of
it.

Aside from that, the name user-customization-file-name is painfully
long.  Please call it user-profile-name or profile-file-name
instead.

That function belongs in subr.el or files.el, not simple.el.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: init-dir unification
  2005-11-05 23:43 ` init-dir unification (Was: Use .emacs.d in savehist.el) Richard M. Stallman
@ 2005-11-06 22:58   ` Chong Yidong
  0 siblings, 0 replies; 6+ messages in thread
From: Chong Yidong @ 2005-11-06 22:58 UTC (permalink / raw)
  Cc: ihs_4664, miles, storm, emacs-devel

"Richard M. Stallman" <rms@gnu.org> writes:

> The argument NAME to init-directory, and the argument SUBDIRECTORY of
> user-customization-file-name, make the code harder to understand.  As
> far as I can see, they are unnecessary.  Why do you think this is
> necessary?

To allow Lisp programs to save into subdirectories of .emacs.d, just
like we do for auto-save list files: ~/.emacs.d/auto-save-list/

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2005-11-06 22:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-04 18:48 init-dir unification (Was: Use .emacs.d in savehist.el) Chong Yidong
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

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).