all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Ihor Radchenko <yantar92@posteo.net>
To: 60929@debbugs.gnu.org
Subject: bug#60929: 30.0.50; [FR] `file-name-extension' and backup suffixes
Date: Wed, 18 Jan 2023 10:50:08 +0000	[thread overview]
Message-ID: <87o7qw6rrz.fsf@localhost> (raw)


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>





             reply	other threads:[~2023-01-18 10:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-18 10:50 Ihor Radchenko [this message]
2023-01-18 11:08 ` bug#60929: 30.0.50; [FR] `file-name-extension' and backup suffixes 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

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=87o7qw6rrz.fsf@localhost \
    --to=yantar92@posteo.net \
    --cc=60929@debbugs.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.