unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Eli Zaretskii <eliz@gnu.org>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: 60929@debbugs.gnu.org
Subject: bug#60929: 30.0.50; [FR] `file-name-extension' and backup suffixes
Date: Wed, 18 Jan 2023 14:47:14 +0200	[thread overview]
Message-ID: <83y1q01031.fsf@gnu.org> (raw)
In-Reply-To: <87o7qw6rrz.fsf@localhost> (message from Ihor Radchenko on Wed, 18 Jan 2023 10:50:08 +0000)

> From: Ihor Radchenko <yantar92@posteo.net>
> Date: Wed, 18 Jan 2023 10:50:08 +0000
> 
> 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:

file-name-sans-extension isn't supposed to remove backup suffixes,
it's supposed to remove file _versions_.

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

And this is wrong because...?

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

This documentation is slightly inaccurate, and thus misleading.  It
should be fixed.  The truth is evident if you look at the code: this
function is the opposite of file-name-sans-extension, whose doc string
doesn't say anything about backup suffixes.

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

Can't you do this by binding file-name-version-regexp to something
that gets the job done.

> Context: https://orgmode.org/list/25543.50706.554658.6937@gargle.gargle.HOWL

FWIW, I don't understand this context: is it wrong for some reason
that foo.org.bak is visited in Org mode?  If it's wrong, then why?
And what does that have to do with the main issue you are raising
here?  I feel there's some logical gap here.





  parent reply	other threads:[~2023-01-18 12:47 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=83y1q01031.fsf@gnu.org \
    --to=eliz@gnu.org \
    --cc=60929@debbugs.gnu.org \
    --cc=yantar92@posteo.net \
    /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 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).