From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Platon Pronko Newsgroups: gmane.emacs.help Subject: Re: How to convert an arbitrary string into a filename Date: Wed, 26 Apr 2023 13:39:37 +0800 Message-ID: <1c536017-2a39-c533-de41-ccbad7033f7d@gmail.com> References: <87wn1z8fgo.fsf@mbork.pl> <4022908b-a023-3b3b-19a4-88ca90d055f3@gmail.com> <87v8hj8db7.fsf@mbork.pl> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="22713"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.1 Cc: Help Gnu Emacs mailing list To: Marcin Borkowski Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Apr 26 07:40:39 2023 Return-path: Envelope-to: geh-help-gnu-emacs@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 1prXtO-0005kt-AG for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 26 Apr 2023 07:40:38 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1prXsp-0000dU-3u; Wed, 26 Apr 2023 01:40:03 -0400 Original-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 ) id 1prXsi-0000Zs-Fk for help-gnu-emacs@gnu.org; Wed, 26 Apr 2023 01:39:56 -0400 Original-Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1prXsW-0008Am-23 for help-gnu-emacs@gnu.org; Wed, 26 Apr 2023 01:39:55 -0400 Original-Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1a52667955dso70700265ad.1 for ; Tue, 25 Apr 2023 22:39:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682487582; x=1685079582; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=oFLoqkMKgj6eu57m1hAuCDt9Ks7h/ttON4Dfb6SSNlE=; b=hOyM/Ukt/b4NjgJBsCbOBflzEvbD0tFSdiD9ytuEJqKnufFogdicxjY6y9DQAHo9MS gCUPah32qxOVxrGWoVjzheSxPyTTC47lusOoWtat2B1Q/0z00vLLYZWBnvrkhbyOziDv Nr4dPy5bg+7xYtrN6ncZocT86KfRZJWyLJgttPmCgHA6yu+bDL9jnJdCQ1xysQW+2raA g62ruKvda5HVvio8zXiCxraamApzpGi9BhvC7RRJku/ng+3QS5TQVWFHwkrs7oyR0p1W OVZLB2VZErbhBo02wwnEG9ZmozU0LSebgXY1uC4bZktC/B/UzIIpXsnzPIUMyXU9SBhS JZAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682487582; x=1685079582; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=oFLoqkMKgj6eu57m1hAuCDt9Ks7h/ttON4Dfb6SSNlE=; b=iIR3f57HFuREMXdNEJInESXk7hlEGwpprZOEIgdCMymQ2+uoFGTdiwzMtX4wLaXRaZ RR2Fod8vKOFw9A0E5ME/4Jfo/GOdC5ud0wov5x0Z7EWU2HdBp8LHH12eWjq27tFHHdcx dfiKbms7xAQk4jxch7xPDis1LNC6Ghn3hjwnq/ZP87yZ62elUIj0wcdYEQGPeSL2ZEuE pvXtykrQLxa4P7YWSpJDVVO/QrpmqB6lhcfWZFTcZDcHVtt0Nh6GGpWJndAT6eJ5/e3H D8rr49SR+6HjErw5HUBaTMu/syq57XuD0hZGgJXCZRoIorLRNjOAngPF+Nw6qlnCH6R1 Z2hQ== X-Gm-Message-State: AAQBX9cQjoHqV+Ipmm8CdbfUzZ2iD/FSsfF1dMD26ZoedSDjI441HLRd PnO0hNTI8jpPMT5YokQyyGo= X-Google-Smtp-Source: AKy350aKanURwr5f3dAES3OLzCDMZT1Ft0o5R4uz8dBmcUFKS+Dtx5vzTns9yHJcY423jFgg+uYQZA== X-Received: by 2002:a17:902:ced0:b0:19f:1f0a:97f1 with SMTP id d16-20020a170902ced000b0019f1f0a97f1mr23802050plg.30.1682487581690; Tue, 25 Apr 2023 22:39:41 -0700 (PDT) Original-Received: from [192.170.1.133] ([103.24.106.35]) by smtp.gmail.com with ESMTPSA id y9-20020a170902700900b0019c2b1c4ad4sm1045379plk.6.2023.04.25.22.39.39 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 25 Apr 2023 22:39:41 -0700 (PDT) Content-Language: en-US In-Reply-To: <87v8hj8db7.fsf@mbork.pl> Received-SPF: pass client-ip=2607:f8b0:4864:20::631; envelope-from=platon7pronko@gmail.com; helo=mail-pl1-x631.google.com X-Spam_score_int: -34 X-Spam_score: -3.5 X-Spam_bar: --- X-Spam_report: (-3.5 / 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, FREEMAIL_FROM=0.001, NICE_REPLY_A=-1.422, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.help:143388 Archived-At: On 2023-04-26 12:42, Marcin Borkowski wrote: > > On 2023-04-26, at 06:03, Platon Pronko wrote: > >> On 2023-04-26 11:55, Marcin Borkowski wrote: >>> Hi all, >>> given an arbitrary string, say "Hello, world!!!", I want to have >>> a filename with all the runs of weird characters (that is, >>> non-alphanumeric ones) converted to dashes (say, "Hello-world"). Is >>> there a function for that in Emacs already or should I write my own? >> >> Something like this? >> >> (let ((input "Hello, world!!!")) >> (replace-regexp-in-string "[^a-zA-Z0-9]+" "-" input)) >> ;; "Hello-world-" > > More or less, possibly with trimming - I know it's simple, I just didn't > want to do it if it already exists. Which I still don't know... (I > suppose not, but I'm not sure.) The term you are looking for is "slug" ("slugify"). Quick google search indicates that there's nothing built-in, but there might be some implementations inside other packages. Here's a reference to an implementation in org-roam package: https://mailb.org/pipermail/emacs-berlin/2022/000897.html Also might be of interest: https://github.com/masasam/emacs-easy-hugo/issues/64 https://melpa.org/#/unidecode