GNU bug report logs - #77797
31.0.50; Visit an empty file on creating it

Previous Next

Package: emacs;

Reported by: Stephen Berman <stephen.berman <at> gmx.net>

Date: Mon, 14 Apr 2025 11:59:02 UTC

Severity: normal

Found in version 31.0.50

Full log


Message #17 received at 77797 <at> debbugs.gnu.org (full text, mbox):

From: Eshel Yaron <me <at> eshelyaron.com>
To: Eli Zaretskii <eliz <at> gnu.org>
Cc: Stephen Berman <stephen.berman <at> gmx.net>, 77797 <at> debbugs.gnu.org
Subject: Re: bug#77797: 31.0.50; Visit an empty file on creating it
Date: Mon, 14 Apr 2025 18:59:11 +0200
Hi,

Eli Zaretskii <eliz <at> gnu.org> writes:

>> From: Stephen Berman <stephen.berman <at> gmx.net>
>> Cc: 77797 <at> debbugs.gnu.org
>> Date: Mon, 14 Apr 2025 17:14:03 +0200
>> 
>> Since you don't necessarily object, what's the next step?
>
> I'd like to hear more opinions about this, since I think it takes that
> command in directions we didn't intend it to go.

FWIW, I use C-x C-f to create new files all the time, also in
non-existing directories.  Then I save the buffer as usual, and that
prompts me to create the directory if needed, which I find to be fine.
So I probably wouldn't find much use for this addition.  I wouldn't mind
if it was added nonetheless, of course.

BTW if you want to suppress the prompt for creating a new directory and
always just create it when needed, you can (ab)use write-file-functions
for that:

--8<---------------cut here---------------start------------->8---
(defun my-ensure-dir ()
  (let ((dir (file-name-directory (buffer-file-name))))
    (unless (file-directory-p dir)
      (make-directory dir t)))
  nil)

(add-hook 'write-file-functions #'my-ensure-dir)
--8<---------------cut here---------------end--------------->8---


Best regards,

Eshel




This bug report was last modified 62 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.