unofficial mirror of emacs-devel@gnu.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

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