From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Skip Montanaro Newsgroups: gmane.emacs.help Subject: TIL about string-rectangle Date: Wed, 30 Dec 2020 14:59:25 -0600 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="26628"; mail-complaints-to="usenet@ciao.gmane.io" To: Help GNU Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Wed Dec 30 21:59:58 2020 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 1kuiZa-0006nb-Fp for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 30 Dec 2020 21:59:58 +0100 Original-Received: from localhost ([::1]:60516 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kuiZZ-00029A-In for geh-help-gnu-emacs@m.gmane-mx.org; Wed, 30 Dec 2020 15:59:57 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:58204) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kuiYp-000291-6R for help-gnu-emacs@gnu.org; Wed, 30 Dec 2020 15:59:11 -0500 Original-Received: from mail-yb1-xb31.google.com ([2607:f8b0:4864:20::b31]:39278) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kuiYn-00085J-Pm for help-gnu-emacs@gnu.org; Wed, 30 Dec 2020 15:59:10 -0500 Original-Received: by mail-yb1-xb31.google.com with SMTP id k4so15831915ybp.6 for ; Wed, 30 Dec 2020 12:59:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=LWTBz3mP2jkD1Ghaw47KN2EgqMupvL+8s8oP2qV/gEI=; b=SiqgMvlDMV8ui8aTQwu4HO4NVNXrqRH9NrKh3fUWKN2UqLa2B68UynEA4HATRgpJR/ e3LlotuISrEcy1VjOCrOdyq8u0/kLn8lT1FcbZWDlVQlJZcquwJH1MYLUiutC5JvPXmv 2F8C/d8MMit0Sporb6OPTiGmEZIctVUyRGNoXOmsFZjo6R7k0XL4Q8BmAYNA8bw1zuwe c/wJSHHxixD2g5lCHTeKCwrfpGyeomwIWWhDKCIohD7DBF7X22OreRgxg8sVCiOCi6KY ifsrrSUpyjw5RrtLREBKwV5A8VI5gnKIQ4uOtP/Lw8Y+/++nCARosZyaPxUD9ulVR3u5 f25w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=LWTBz3mP2jkD1Ghaw47KN2EgqMupvL+8s8oP2qV/gEI=; b=jlnogm4hK+XNUK0bPuZA+/HxLkFUbrjd0yCS2BYgZU2PZ73KjvtOYWIeknHcSheeNs ImhXexbmjYCjiw0nCfVOeIGtXPqHIZbZ/y/6kk1S9wSn4kFWjyoNUgH3VgYZogeUBsW6 4jsRxWk2c4VMxyGAr72JFqKKhbKYN8RVD9w7eaC8Z2Ey4l2Mt/BWvOJz1+aYeb83/3Wz saduExYTpe28v9rhW4Co9UZWaq/HG1UaXuK1LF9TzFohWO+bO9CBIQ+kMLEMryATG61M CnrJcyV9b8g5O102eiP4M5AN2Y3MqmAupzofgn2Qk3/puaDxFmnCrArZx66Z/yV+82CU ojdw== X-Gm-Message-State: AOAM531CAuLTLiqiZRmNbI4p2D8JglIJp9PkUI0NbARQ6CeI6C+r5AMm HkSRuWoBHS0KenVEcjYUOuw55MXEdMjD1PBsWPWxIED4wWudH14= X-Google-Smtp-Source: ABdhPJx0xdHOxnbUegDm14OwQDXYRDmU2JaJl5HCSaJaxwnxE6QQ2UncNrf+pQWe7G+sz0nOF/J6beyWZvrot89IOFc= X-Received: by 2002:a25:da89:: with SMTP id n131mr80796038ybf.67.1609361947929; Wed, 30 Dec 2020 12:59:07 -0800 (PST) Received-SPF: pass client-ip=2607:f8b0:4864:20::b31; envelope-from=skip.montanaro@gmail.com; helo=mail-yb1-xb31.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 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, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 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" Xref: news.gmane.io gmane.emacs.help:126923 Archived-At: I needed to replace the first comma on each line of a CSV file so I could more conveniently sort by the first field (date, arranged as MM/DD/YYYY). After a bit of fussing around, I got it squared away with query-replace-regexp, did my sort, then needed to revert the replacement text back to comma. Unfortunately, there were a few other instances of the replacement text elsewhere in the file which caused problems. (If I'd had my thinking cap on I would have checked before doing the original replace, but it seems I was wearing my dunce cap...) Poking around for help from Emacs against a future need, I discovered replace-rectangle, which turns out to be an alias for string-rectangle (bound to C-x r t). It looks to be quite handy when you need to replace text within a rectangle. It's sort of (but not quite) like narrow-to-region + query-replace(-regexp)?. It doesn't query for a string to replace. It simply replaces the rectangle's contents with the given string on each line. Kinda cool, Skip