From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juanma Barranquero Newsgroups: gmane.emacs.devel Subject: A couple of locate-user-emacs-file questions Date: Thu, 20 Jun 2013 04:09:37 +0200 Message-ID: NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1371694223 1874 80.91.229.3 (20 Jun 2013 02:10:23 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 20 Jun 2013 02:10:23 +0000 (UTC) To: Emacs developers Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Thu Jun 20 04:10:24 2013 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1UpUKO-0001Jj-0d for ged-emacs-devel@m.gmane.org; Thu, 20 Jun 2013 04:10:24 +0200 Original-Received: from localhost ([::1]:51561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpUKN-0007tF-IM for ged-emacs-devel@m.gmane.org; Wed, 19 Jun 2013 22:10:23 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:41878) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpUKJ-0007sz-PX for emacs-devel@gnu.org; Wed, 19 Jun 2013 22:10:20 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UpUKI-0005Wb-MP for emacs-devel@gnu.org; Wed, 19 Jun 2013 22:10:19 -0400 Original-Received: from mail-ee0-x235.google.com ([2a00:1450:4013:c00::235]:33189) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UpUKI-0005WW-Fj for emacs-devel@gnu.org; Wed, 19 Jun 2013 22:10:18 -0400 Original-Received: by mail-ee0-f53.google.com with SMTP id c41so3612079eek.12 for ; Wed, 19 Jun 2013 19:10:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=HFM5y0woQLjKXoB8cw81w2CYI2zXk0INyPZa/kDYsWQ=; b=FnaLBcrct/Kp2O5mypHEb1ZOc57O/sG+LEIcAKpLIGhVQzYzaS9sBqhlKZWxOktIOe BReXc6i9IKY6zwmSbk59Qvnk2YDJJSh3iKmxKWF77JCqSGaYbw0semfsD1y37DlEyNPC cBB2fPpahBPOL5QDmOPYobUBfNg880OyrO/gnmhTTCgxs4ZOUKeXj+hAOELwVUfEKzsi h7EG24elperVUSZSRku+yxmsXkSTueXUpACx4w49gGTECqWLHzjVurSsqEH5BAGMN6yn el+wkEX3mafOvzdHOTfrxYeTmj/ufZ77LUhXeuDK4Wq/B90Me4cxLqo2nt1SuOF/XaFL LkQw== X-Received: by 10.14.218.8 with SMTP id j8mr5044466eep.129.1371694217491; Wed, 19 Jun 2013 19:10:17 -0700 (PDT) Original-Received: by 10.14.142.4 with HTTP; Wed, 19 Jun 2013 19:09:37 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4013:c00::235 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:160718 Archived-At: 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...