From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: [PATCH] lisp/files.el: Add `file-name-set-extension` Date: Tue, 25 May 2021 16:25:38 -0400 Message-ID: References: <6ff4b7d7-03ac-48d1-8d49-de66431d4e5b@www.fastmail.com> <87lf82y9pv.fsf@tcd.ie> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="6222"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) Cc: "Basil L. Contovounesios" , emacs-devel@gnu.org To: "Colin Woodbury" Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Tue May 25 22:27:16 2021 Return-path: Envelope-to: ged-emacs-devel@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1llddz-0001S9-TG for ged-emacs-devel@m.gmane-mx.org; Tue, 25 May 2021 22:27:15 +0200 Original-Received: from localhost ([::1]:46156 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1llddy-0007Hl-TM for ged-emacs-devel@m.gmane-mx.org; Tue, 25 May 2021 16:27:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:47910) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lldcb-0005ki-8S for emacs-devel@gnu.org; Tue, 25 May 2021 16:25:49 -0400 Original-Received: from mailscanner.iro.umontreal.ca ([132.204.25.50]:20756) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lldcV-0005Vu-9R for emacs-devel@gnu.org; Tue, 25 May 2021 16:25:48 -0400 Original-Received: from pmg2.iro.umontreal.ca (localhost.localdomain [127.0.0.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id C340F80169; Tue, 25 May 2021 16:25:41 -0400 (EDT) Original-Received: from mail01.iro.umontreal.ca (unknown [172.31.2.1]) by pmg2.iro.umontreal.ca (Proxmox) with ESMTP id 7FA98803C3; Tue, 25 May 2021 16:25:40 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=iro.umontreal.ca; s=mail; t=1621974340; bh=BxCaSiZ3lDN//w68lmqhe8Amzn2a7XZlKeK5IHvBRzI=; h=From:To:Cc:Subject:References:Date:In-Reply-To:From; b=WO6pXhHhPWq1egOaHXrFJ9K0kssHGjqW/LDKTHAsF2bFPC+3OtB8I0utXMduHNKPl aLRY8xylVJWsBRNdbW1Hs4zjqDzkNfsmp5stOJfK4mhdmzmm+NmGQUy8BExVKwnMFY yQVJUBrllJvDLDLdCwcoYeswtE2TXpd2KHq0Z2ZxFCh56bpjXVyBH+4YYQmKUAwjlw x098SBaHdX3wKP+Ch0u5jSivw1vUfDCEEfwf2GtOh3OCkQRB+r/r2NzTfqCXoS7+1G HVBuBsCMG5mVJCVnfyq/XV8wpPCJ+hQ1+iGiaSx2c6hltVRlZlM4Tqt7vnp4uOVcDn M9uZERyr39p5A== Original-Received: from alfajor (69-196-163-239.dsl.teksavvy.com [69.196.163.239]) by mail01.iro.umontreal.ca (Postfix) with ESMTPSA id 3EB5B120B45; Tue, 25 May 2021 16:25:40 -0400 (EDT) In-Reply-To: (Colin Woodbury's message of "Tue, 25 May 2021 12:45:58 -0700") Received-SPF: pass client-ip=132.204.25.50; envelope-from=monnier@iro.umontreal.ca; helo=mailscanner.iro.umontreal.ca X-Spam_score_int: -42 X-Spam_score: -4.3 X-Spam_bar: ---- X-Spam_report: (-4.3 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-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-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane-mx.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.io gmane.emacs.devel:269893 Archived-At: > + (when (and filename extension) > + (let* ((patt "[ \t\n\r.]+") ; Inspired by `string-trim'. > + (filename (string-trim-right filename patt)) > + (extension (string-trim-left extension patt))) > + (unless (or (string-empty-p filename) > + (string-empty-p extension)) > + (concat (file-name-sans-extension filename) "." extension))))) Why do you trim [ \t\n\r.]+ from the end of the filename and the beginning of the extension? I can see why you'd want to remove a single "." at the beginning of `extension`, so as to allow extension to come with or without a leading ".", but the rest seems rather surprising because such characters in my experience almost never show up in such a circumstance (which means that if they do, it's either on purpose and we should preserve it, or it's an error "upstream" and we should try and help expose the error rather than silently try to cover it). Stefan