From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 65059429E26 for ; Wed, 21 Dec 2011 06:39:06 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: -0.7 X-Spam-Level: X-Spam-Status: No, score=-0.7 tagged_above=-999 required=5 tests=[RCVD_IN_DNSWL_LOW=-0.7] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vFl1hgJZa1Yg for ; Wed, 21 Dec 2011 06:39:05 -0800 (PST) Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU [18.7.68.34]) by olra.theworths.org (Postfix) with ESMTP id A9170431FB6 for ; Wed, 21 Dec 2011 06:39:05 -0800 (PST) X-AuditID: 12074422-b7fd66d0000008f9-f0-4ef1ef861430 Received: from mailhub-auth-1.mit.edu ( [18.9.21.35]) by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP id 34.2E.02297.68FE1FE4; Wed, 21 Dec 2011 09:39:02 -0500 (EST) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-1.mit.edu (8.13.8/8.9.2) with ESMTP id pBLEd1fO031639; Wed, 21 Dec 2011 09:39:02 -0500 Received: from awakening.csail.mit.edu (awakening.csail.mit.edu [18.26.4.91]) (authenticated bits=0) (User authenticated as amdragon@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id pBLEcxpg024899 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NOT); Wed, 21 Dec 2011 09:39:00 -0500 (EST) Received: from amthrax by awakening.csail.mit.edu with local (Exim 4.77) (envelope-from ) id 1RdNKy-0006Wi-9A; Wed, 21 Dec 2011 09:40:08 -0500 Date: Wed, 21 Dec 2011 09:40:08 -0500 From: Austin Clements To: David Edmondson Subject: Re: [PATCH] emacs: create patch filename from subject for inline patch fake parts Message-ID: <20111221144008.GG10376@mit.edu> References: <1321657368-13872-1-git-send-email-jani@nikula.org> <87aa6nxb3o.fsf@nikula.org> <20111220215229.GF10376@mit.edu> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplleLIzCtJLcpLzFFi42IR4hRV1m17/9HPYNN9I4t9d7YwWTRNd7a4 fnMmswOzx67nf5k8bt1/ze7xbNUt5gDmKC6blNSczLLUIn27BK6MCR8mMRbsEKx4/YirgXE/ bxcjJ4eEgInE6SW7WSBsMYkL99azdTFycQgJ7GOUuLF2NjOEs4FR4t6h44wQzkkmiZst35kg nCWMEs2L17GC9LMIqEq8+rOcDcRmE9CQ2LZ/OSOILSKgKPH/2wp2EJtZwEqiYcsHsLiwQIzE 03+TwHbzCuhIXL74EWr3JkaJr4cnQCUEJU7OfMIC0awlcePfS6DNHEC2tMTyfxwgYU4BG4nj K46D3SAqoCIx5eQ2tgmMQrOQdM9C0j0LoXsBI/MqRtmU3Crd3MTMnOLUZN3i5MS8vNQiXVO9 3MwSvdSU0k2MoFBnd1HawfjzoNIhRgEORiUeXqH9H/yEWBPLiitzDzFKcjApifLOePvRT4gv KT+lMiOxOCO+qDQntfgQowQHs5II78fXQDnelMTKqtSifJiUNAeLkjivutY7PyGB9MSS1OzU 1ILUIpisDAeHkgTvuXdAjYJFqempFWmZOSUIaSYOTpDhPEDDv4PU8BYXJOYWZ6ZD5E8xKkqJ 834GSQiAJDJK8+B6YanoFaM40CvCvG9AqniAaQyu+xXQYCagwducP4AMLklESEk1ME4Ku3iu c9/qIv4auy2Sq5/d/75RX23Gq4Ipvzd48KyXdgu2/Gjj+46R7dvENb3rc1l8Yn0O7rvOmK0z ZWHPfS/GBQdWNr4+6mHysDVP69bRz4EySzX4O7+tdtuR2ZXU4b1rlfwt1myO+mf5r9N5Lm0W 1sxZbtR1OU7R+c5OrXv/XBqM9XmV/yixFGckGmoxFxUnAgC3ieu9IAMAAA== Cc: notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 21 Dec 2011 14:39:06 -0000 I would definitely go with the latter. It might feel less unwieldy with a shorter variable name than "filename", since that has to be repeated so many times. (It's also not really a filename in the middle of the replace process.) This is splitting hairs, but in my original suggestion, I was thinking something like (let* ((s subject) (s (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" s)) (s (replace-regexp-in-string "[. ]*$" "" s)) (s (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" s)) (s (replace-regexp-in-string "\\.+" "." s)) (s (substring s 0 (min (length s) 50)))) (concat s ".patch")) Out of curiosity, where'd the regexps come from? They all seem reasonable, but some of them seem somewhat arbitrary. Quoth David Edmondson on Dec 21 at 9:21 am: > On Tue, 20 Dec 2011 16:52:52 -0500, Austin Clements wrote: > > Seems like a definite improvement, but perhaps a let* instead of all > > of the setq's? > > What would be a lispy approach? I tried: > > (defun notmuch-subject-to-patch-filename (subject) > "Convert a typical patch mail subject line into a suitable filename." > (concat > (let ((filename subject) > (transforms > '(("^ *\\(\\[[^]]*\\]\\)? *" . "") > ("[. ]*$" . "") > ("[^A-Za-z0-9._-]+" . "-") > ("\\.+" . ".")))) > (mapc (lambda (transform) > (setq filename (replace-regexp-in-string (car transform) (cdr transform) filename))) > transforms) > (substring filename 0 (min (length filename) 50))) > ".patch")) > > ...but that seems a bit unwieldy. `let*' looks best, but still feels a > bit odd: > > (defun notmuch-subject-to-patch-filename (subject) > "Convert a typical patch mail subject line into a suitable filename." > (concat > (let* ((filename (replace-regexp-in-string "^ *\\(\\[[^]]*\\]\\)? *" "" subject)) > (filename (replace-regexp-in-string "[. ]*$" "" filename)) > (filename (replace-regexp-in-string "[^A-Za-z0-9._-]+" "-" filename)) > (filename (replace-regexp-in-string "\\.+" "." filename))) > (substring filename 0 (min (length filename) 50))) > ".patch")) > > dme.