all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Juanma Barranquero <lekktu@gmail.com>
To: Emacs developers <emacs-devel@gnu.org>
Subject: A couple of locate-user-emacs-file questions
Date: Thu, 20 Jun 2013 04:09:37 +0200	[thread overview]
Message-ID: <CAAeL0SQZ9aVk=+-VyFAC+WKST5muDN4Z5n0b7mhzCDZBDv8+FQ@mail.gmail.com> (raw)

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



             reply	other threads:[~2013-06-20  2:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-20  2:09 Juanma Barranquero [this message]
2013-06-20 20:14 ` A couple of locate-user-emacs-file questions Stefan Monnier
2013-06-20 22:35   ` Juanma Barranquero
2013-06-21  1:46     ` Stefan Monnier

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

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

  git send-email \
    --in-reply-to='CAAeL0SQZ9aVk=+-VyFAC+WKST5muDN4Z5n0b7mhzCDZBDv8+FQ@mail.gmail.com' \
    --to=lekktu@gmail.com \
    --cc=emacs-devel@gnu.org \
    /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 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.