GNU bug report logs - #60929
30.0.50; [FR] `file-name-extension' and backup suffixes

Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.

Package: emacs; Reported by: Ihor Radchenko <yantar92@HIDDEN>; dated Wed, 18 Jan 2023 10:50:01 UTC; Maintainer for emacs is bug-gnu-emacs@HIDDEN.

Message received at 60929 <at> debbugs.gnu.org:


Received: (at 60929) by debbugs.gnu.org; 18 Jan 2023 11:14:51 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 18 06:14:51 2023
Received: from localhost ([127.0.0.1]:39463 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pI6P4-0008S5-Vj
	for submit <at> debbugs.gnu.org; Wed, 18 Jan 2023 06:14:51 -0500
Received: from netyu.xyz ([152.44.41.246]:49304 helo=mail.netyu.xyz)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <ruijie@HIDDEN>) id 1pI6P2-0008Rw-KB
 for 60929 <at> debbugs.gnu.org; Wed, 18 Jan 2023 06:14:49 -0500
Received: from fw.net.yu.netyu.xyz (<unknown> [222.248.4.98])
 by netyu.xyz (OpenSMTPD) with ESMTPSA id cb23116c
 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); 
 Wed, 18 Jan 2023 11:14:47 +0000 (UTC)
References: <87o7qw6rrz.fsf@localhost>
User-agent: mu4e 1.8.13; emacs 29.0.60
From: Ruijie Yu <ruijie@HIDDEN>
To: Ihor Radchenko <yantar92@HIDDEN>
Subject: Re: bug#60929: 30.0.50; [FR] `file-name-extension' and backup suffixes
Date: Wed, 18 Jan 2023 19:08:36 +0800
In-reply-to: <87o7qw6rrz.fsf@localhost>
Message-ID: <sdvilh4ccwy.fsf@HIDDEN>
MIME-Version: 1.0
Content-Type: text/plain
X-Spam-Score: 0.0 (/)
X-Debbugs-Envelope-To: 60929
Cc: 60929 <at> debbugs.gnu.org
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: 0.0 (/)


Ihor Radchenko <yantar92@HIDDEN> writes:

> Hi,
>
> Would it be possible to make `file-name-sans-extension' strip extension
> upon removing backup suffixes (optionally)?
>
> Currently, Emacs' handling of backup extensions is a bit inconsistent:
>
> auto-mode-alist recognizes
>
>  ("\\.~?[0-9]+\\.[0-9][-.0-9]*~?\\'" nil t)
>  ("\\.\\(?:orig\\|in\\|[bB][aA][kK]\\)\\'" nil t)
>
> as backup extension and thus opens files like foo.org.bak with Org mode.
>
> [...]
>
> It would be useful if functions like `file-name-extension',
> `file-name-sans-extension', and similar could optionally strip backup
> suffixes that contain ".".
> [...]

Note that since the backup extensions can be stripped recursively in
`auto-mode-alist' (that is, "test.c.bak.Bak.BAK.baK" is opened in c-mode
because of the recursive extension stripping), if this FR is to be
accepted, we would need to ensure that the above scenario is covered.

Best,


RY




Information forwarded to bug-gnu-emacs@HIDDEN:
bug#60929; Package emacs. Full text available.

Message received at submit <at> debbugs.gnu.org:


Received: (at submit) by debbugs.gnu.org; 18 Jan 2023 10:49:51 +0000
From debbugs-submit-bounces <at> debbugs.gnu.org Wed Jan 18 05:49:51 2023
Received: from localhost ([127.0.0.1]:39397 helo=debbugs.gnu.org)
	by debbugs.gnu.org with esmtp (Exim 4.84_2)
	(envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>)
	id 1pI60t-0005Sr-0d
	for submit <at> debbugs.gnu.org; Wed, 18 Jan 2023 05:49:51 -0500
Received: from lists.gnu.org ([209.51.188.17]:51454)
 by debbugs.gnu.org with esmtp (Exim 4.84_2)
 (envelope-from <yantar92@HIDDEN>) id 1pI60o-0005Sf-Vl
 for submit <at> debbugs.gnu.org; Wed, 18 Jan 2023 05:49:49 -0500
Received: from eggs.gnu.org ([2001:470:142:3::10])
 by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <yantar92@HIDDEN>)
 id 1pI60o-0002pn-ML
 for bug-gnu-emacs@HIDDEN; Wed, 18 Jan 2023 05:49:46 -0500
Received: from mout01.posteo.de ([185.67.36.65])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <yantar92@HIDDEN>)
 id 1pI60l-0002Ey-8O
 for bug-gnu-emacs@HIDDEN; Wed, 18 Jan 2023 05:49:46 -0500
Received: from submission (posteo.de [185.67.36.169]) 
 by mout01.posteo.de (Postfix) with ESMTPS id 3D09F240323
 for <bug-gnu-emacs@HIDDEN>; Wed, 18 Jan 2023 11:49:39 +0100 (CET)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017;
 t=1674038979; bh=3/Bg2V8mCuyttnQcBdiRxYKE83R/MuOPy0zJ0O2WhBk=;
 h=From:To:Subject:Date:From;
 b=aUF3csAEcEvHWaIq61Wh7Ju497F4Yc2u6W5YVwrurAebCm6EJO/EtoDxJCdiGcfFs
 PTuzwp7AhliaozLgN3S8eXDPVMDrGbzH3vCg+n5W7yqnjoDQMtOjx+hkIxigoxxk7+
 4UtVotNXHQq/EfwoRWwmHYqEzOv/zekY4rBITl9NkCmd9EootO9qi5BV3B+EWfc6NQ
 8tDFI7tcNCnr89ydr3/trFJkVoylGs0+Jwqge1q2BEO9djEa5YK8BC2DCp1rDhmbrm
 F1JoVPu80wNXQZMxWCA2//GlaC2B/p29GzNgGL7zVL8AvWGmfjN5k1kGgnF5TzY5YK
 rPSBYntcl60Mw==
Received: from customer (localhost [127.0.0.1])
 by submission (posteo.de) with ESMTPSA id 4NxjFF1MRGz9rxX
 for <bug-gnu-emacs@HIDDEN>; Wed, 18 Jan 2023 11:49:36 +0100 (CET)
From: Ihor Radchenko <yantar92@HIDDEN>
To: bug-gnu-emacs@HIDDEN
Subject: 30.0.50; [FR] `file-name-extension' and backup suffixes
Date: Wed, 18 Jan 2023 10:50:08 +0000
Message-ID: <87o7qw6rrz.fsf@localhost>
MIME-Version: 1.0
Content-Type: text/plain
Received-SPF: pass client-ip=185.67.36.65; envelope-from=yantar92@HIDDEN;
 helo=mout01.posteo.de
X-Spam_score_int: -43
X-Spam_score: -4.4
X-Spam_bar: ----
X-Spam_report: (-4.4 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1,
 DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1,
 RCVD_IN_DNSWL_MED=-2.3, SPF_HELO_NONE=0.001,
 SPF_PASS=-0.001 autolearn=ham autolearn_force=no
X-Spam_action: no action
X-Spam-Score: -1.3 (-)
X-Debbugs-Envelope-To: submit
X-BeenThere: debbugs-submit <at> debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
List-Id: <debbugs-submit.debbugs.gnu.org>
List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe>
List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/>
List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org>
List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help>
List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, 
 <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe>
Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org
Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org>
X-Spam-Score: -2.3 (--)


Hi,

Would it be possible to make `file-name-sans-extension' strip extension
upon removing backup suffixes (optionally)?

Currently, Emacs' handling of backup extensions is a bit inconsistent:

auto-mode-alist recognizes

 ("\\.~?[0-9]+\\.[0-9][-.0-9]*~?\\'" nil t)
 ("\\.\\(?:orig\\|in\\|[bB][aA][kK]\\)\\'" nil t)

as backup extension and thus opens files like foo.org.bak with Org mode.

Further, `file-name-extension' returns:

    The extension, in a file name, is the part that begins with the last .,
    excluding version numbers and backup suffixes, except that a leading .
    of the file name, if there is one, doesn't count.

But it only works for the native Emacs "~" style of backups (on Linux,
at least). If one tries (file-name-extension "foo.org.bak") ; => "bak",
we do not see backup extension stripped, which is correct wrt the
docstring, but problematic when we need to handle backup files on
Windows.

If one needs to strip backup extension/suffix for .bak and similar
files, there is a need to re-use
"\\.\\(?:orig\\|in\\|[bB][aA][kK]\\)\\'" regexp, which is not ideal
because auto-mode-alist may include other backup suffixes in future.

It would be useful if functions like `file-name-extension',
`file-name-sans-extension', and similar could optionally strip backup
suffixes that contain ".".

Context: https://orgmode.org/list/25543.50706.554658.6937@HIDDEN

In GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu, cairo version
 1.17.6) of 2023-01-16 built on localhost
Repository revision: bb679244152dddd9949ca065aa6617457f7a7144
Repository branch: master
Windowing system distributor 'The X.Org Foundation', version 11.0.12101006
System Description: Gentoo Linux

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at <https://orgmode.org/>.
Support Org development at <https://liberapay.com/org-mode>,
or support my work at <https://liberapay.com/yantar92>




Acknowledgement sent to Ihor Radchenko <yantar92@HIDDEN>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs@HIDDEN. Full text available.
Report forwarded to bug-gnu-emacs@HIDDEN:
bug#60929; Package emacs. Full text available.
Please note: This is a static page, with minimal formatting, updated once a day.
Click here to see this page with the latest information and nicer formatting.
Last modified: Wed, 18 Jan 2023 11:30:02 UTC

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