all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* A couple of locate-user-emacs-file questions
@ 2013-06-20  2:09 Juanma Barranquero
  2013-06-20 20:14 ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Juanma Barranquero @ 2013-06-20  2:09 UTC (permalink / raw)
  To: Emacs developers

The following patch


=== modified file 'lisp/term/x-win.el'
--- lisp/term/x-win.el 2013-04-06 14:06:39 +0000
+++ lisp/term/x-win.el 2013-06-20 01:36:56 +0000
@@ -118,13 +118,11 @@

 (defun emacs-session-filename (session-id)
   "Construct a filename to save the session in based on SESSION-ID.
-If the directory ~/.emacs.d exists, we make a filename in there, otherwise
-a file in the home directory."
-  (let ((basename (concat "session." session-id))
- (emacs-dir user-emacs-directory))
-    (expand-file-name (if (file-directory-p emacs-dir)
-  (concat emacs-dir basename)
- (concat "~/.emacs-" basename)))))
+Return a filename in `user-emacs-directory', unless the session file
+already exists in the home directory."
+  (let ((basename (concat "session." session-id)))
+    (locate-user-emacs-file basename
+                            (concat ".emacs-" basename))))

 (defun emacs-session-save ()
   "This function is called when the window system is shutting down.


is mildly incompatible, in the sense that some external tool *could*
potentially depend on the session file being in $HOME; but that seems
unlikely. Does anyone see a problem with it?


And speaking of `locate-user-emacs-file', there are a couple of cases
(in cmuscheme.el and shell.el, both related to passing a filename to
comint only if the file does really exist) that could benefit from it,
if there was a way to tell it to check for OLDNAME and NEWNAME, but
return nil (and not create `user-emacs-directory') if neither file
exists. Something like this (diff -b to ignore irrelevant indentation
changes):


=== modified file 'lisp/subr.el'
--- lisp/subr.el 2013-06-14 04:11:00 +0000
+++ lisp/subr.el 2013-06-20 01:56:40 +0000
@@ -2537,24 +2537,26 @@
   :group 'initialization
   :version "24.4")

-(defun locate-user-emacs-file (new-name &optional old-name)
+(defun locate-user-emacs-file (new-name &optional old-name check-only)
   "Return an absolute per-user Emacs-specific file name.
 If NEW-NAME exists in `user-emacs-directory', return it.
 Else if OLD-NAME is non-nil and ~/OLD-NAME exists, return ~/OLD-NAME.
 Else return NEW-NAME in `user-emacs-directory', creating the
-directory if it does not exist."
-  (convert-standard-filename
+directory if it does not exist.
+If CHECK-ONLY is non-nil, return nil if neither file exists,
+and do not create `user-emacs-directory'."
    (let* ((home (concat "~" (or init-file-user "")))
   (at-home (and old-name (expand-file-name old-name home)))
           (bestname (abbreviate-file-name
                      (expand-file-name new-name user-emacs-directory))))
      (if (and at-home (not (file-readable-p bestname))
               (file-readable-p at-home))
-       at-home
+        (convert-standard-filename at-home)
        ;; Make sure `user-emacs-directory' exists,
        ;; unless we're in batch mode or dumping Emacs.
        (or noninteractive
            purify-flag
+           check-only
    (let (errtype)
      (if (file-directory-p user-emacs-directory)
  (or (file-accessible-directory-p user-emacs-directory)
@@ -2579,7 +2581,9 @@
 If you never want to see this message again,
 customize the variable `user-emacs-directory-warning'."
  errtype user-emacs-directory)))))
-       bestname))))
+       (if (or (file-readable-p bestname) (not check-only))
+           (convert-standard-filename bestname)
+         nil))))

 ;;;; Misc. useful functions.



On one hand, seems like a bit overengineered; on the other hand, a
function called *locate*-user-emacs-file should be able to tell
whether it did, in fact, locate it without causing side effects...



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

* Re: A couple of locate-user-emacs-file questions
  2013-06-20  2:09 A couple of locate-user-emacs-file questions Juanma Barranquero
@ 2013-06-20 20:14 ` Stefan Monnier
  2013-06-20 22:35   ` Juanma Barranquero
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Monnier @ 2013-06-20 20:14 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Emacs developers

> is mildly incompatible, in the sense that some external tool *could*
> potentially depend on the session file being in $HOME; but that seems
> unlikely. Does anyone see a problem with it?

I don't.

> And speaking of `locate-user-emacs-file', there are a couple of cases
> (in cmuscheme.el and shell.el, both related to passing a filename to
> comint only if the file does really exist) that could benefit from it,
> if there was a way to tell it to check for OLDNAME and NEWNAME, but
> return nil (and not create `user-emacs-directory') if neither file
> exists. Something like this (diff -b to ignore irrelevant indentation
> changes):

I think it should still not return nil but the "preferred name".

> On one hand, seems like a bit overengineered; on the other hand, a
> function called *locate*-user-emacs-file should be able to tell
> whether it did, in fact, locate it without causing side effects...

I think the problem is that the function should have come with
a `and-create-directory' argument instead, so the directory is only
created when explicitly requested.


        Stefan



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

* Re: A couple of locate-user-emacs-file questions
  2013-06-20 20:14 ` Stefan Monnier
@ 2013-06-20 22:35   ` Juanma Barranquero
  2013-06-21  1:46     ` Stefan Monnier
  0 siblings, 1 reply; 4+ messages in thread
From: Juanma Barranquero @ 2013-06-20 22:35 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: Emacs developers

On Thu, Jun 20, 2013 at 10:14 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:

> I don't.

Good. Committed as revno:113103.

> I think it should still not return nil but the "preferred name".

Then, it isn't really worth changing the interface. My "existing file
vs. nil" proposal is for cases like cmuscheme and shell, where the
resulting file is going to be passed to make-comint

      (apply 'make-comint-in-buffer "shell" buffer prog
             (if (file-exists-p startfile) startfile)

where the check for existence is repeated (because
locate-user-emacs-file already does it, but "discards" that info when
it returns ~/.emacs.d/newname unconditionally).

> I think the problem is that the function should have come with
> a `and-create-directory' argument instead, so the directory is only
> created when explicitly requested.

It's funny, because back when we were designing l-u-e-f, my original
proposal didn't create the dir. Tom Tromey said:

  IMO, if ~/.emacs.d does not exist, and it is what we prefer for the
  future, we should create it here.

I argued timidly against:

  I'm not sure. I think the user should be responsible of creating
  ~/.emacs.d/ if he wants it. Otherwise, if he doesn't want it, the only
  way to have the config files in ~/ would be to customize every *-file
  or *-directory option...

and you kind of agreed with Tom:

  I'm pretty sure I didn't create my ~/.emacs.d.  So the above doesn't seem to
  be what Emacs currently aims for.  It looks like this directory is created
  usually by the code which creates the ~/.emacs.d/auto-save-list directory.

and so did Eli:

  We already create that directory in recover-session, so Tom's
  suggestion makes a lot of sense to me.

Which I'm not bringing up to say "I told you so" (I really didn't ;-)
just to remember that we had some sort of consensus that automatic
creation was the better idea.

All in all, I think the and-create-directory arg idea wouldn't have
worked anyway, because most current packages that use l-u-e-f  assume
that the data file exists or can be created without error. So, to
avoid trouble, it would've been either to pass and-create-directory=t
to all such calls (defeating its very purpose) or change all these
packages to check for the directory's existence and/or create it. Not
a worth gain IMO.

   J



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

* Re: A couple of locate-user-emacs-file questions
  2013-06-20 22:35   ` Juanma Barranquero
@ 2013-06-21  1:46     ` Stefan Monnier
  0 siblings, 0 replies; 4+ messages in thread
From: Stefan Monnier @ 2013-06-21  1:46 UTC (permalink / raw)
  To: Juanma Barranquero; +Cc: Emacs developers

>> I think it should still not return nil but the "preferred name".
> Then, it isn't really worth changing the interface.

I think I agree.


        Stefan



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

end of thread, other threads:[~2013-06-21  1:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-20  2:09 A couple of locate-user-emacs-file questions Juanma Barranquero
2013-06-20 20:14 ` Stefan Monnier
2013-06-20 22:35   ` Juanma Barranquero
2013-06-21  1:46     ` Stefan Monnier

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.