unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#60929: 30.0.50; [FR] `file-name-extension' and backup suffixes
@ 2023-01-18 10:50 Ihor Radchenko
  2023-01-18 11:08 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
  2023-01-18 12:47 ` Eli Zaretskii
  0 siblings, 2 replies; 15+ messages in thread
From: Ihor Radchenko @ 2023-01-18 10:50 UTC (permalink / raw)
  To: 60929


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@gargle.gargle.HOWL

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>





^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2023-01-25 13:43 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-18 10:50 bug#60929: 30.0.50; [FR] `file-name-extension' and backup suffixes Ihor Radchenko
2023-01-18 11:08 ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-18 12:47 ` Eli Zaretskii
2023-01-18 13:01   ` Ihor Radchenko
2023-01-18 14:47     ` Eli Zaretskii
2023-01-23 10:05       ` Ihor Radchenko
2023-01-23 13:34         ` Eli Zaretskii
2023-01-24 11:12           ` Ihor Radchenko
2023-01-24 12:37             ` Eli Zaretskii
2023-01-25 13:18               ` Ihor Radchenko
2023-01-25 13:26                 ` Eli Zaretskii
2023-01-25 13:33                   ` Ruijie Yu via Bug reports for GNU Emacs, the Swiss army knife of text editors
2023-01-25 13:43                     ` Ihor Radchenko
2023-01-25 13:37                   ` Ihor Radchenko
2023-01-18 14:20   ` Eli Zaretskii

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