From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#20626: Wishlist: M-x shell-command-on-rectangle-region Date: Tue, 16 Jun 2015 00:45:27 +0300 Organization: LINKOV.NET Message-ID: <87fv5s4pm0.fsf@mail.linkov.net> References: <527474961.10107734.1432245870451.JavaMail.zimbra@comcast.net> <87twv51raf.fsf@mail.linkov.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1434404851 23335 80.91.229.3 (15 Jun 2015 21:47:31 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 15 Jun 2015 21:47:31 +0000 (UTC) Cc: 20626@debbugs.gnu.org To: asparagus@comcast.net Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jun 15 23:47:20 2015 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Z4cDs-0006nJ-H8 for geb-bug-gnu-emacs@m.gmane.org; Mon, 15 Jun 2015 23:47:16 +0200 Original-Received: from localhost ([::1]:36589 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4cDr-0000Yf-RT for geb-bug-gnu-emacs@m.gmane.org; Mon, 15 Jun 2015 17:47:15 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46144) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4cDn-0000YV-7r for bug-gnu-emacs@gnu.org; Mon, 15 Jun 2015 17:47:12 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z4cDf-00044q-D6 for bug-gnu-emacs@gnu.org; Mon, 15 Jun 2015 17:47:11 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:40564) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z4cDf-00044j-98 for bug-gnu-emacs@gnu.org; Mon, 15 Jun 2015 17:47:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Z4cDf-0008Jl-4m for bug-gnu-emacs@gnu.org; Mon, 15 Jun 2015 17:47:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 15 Jun 2015 21:47:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 20626 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 20626-submit@debbugs.gnu.org id=B20626.143440477231903 (code B ref 20626); Mon, 15 Jun 2015 21:47:02 +0000 Original-Received: (at 20626) by debbugs.gnu.org; 15 Jun 2015 21:46:12 +0000 Original-Received: from localhost ([127.0.0.1]:55023 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z4cCo-0008IU-K3 for submit@debbugs.gnu.org; Mon, 15 Jun 2015 17:46:11 -0400 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:32836 helo=homiemail-a101.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z4cCk-0008IA-5V for 20626@debbugs.gnu.org; Mon, 15 Jun 2015 17:46:07 -0400 Original-Received: from homiemail-a101.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a101.g.dreamhost.com (Postfix) with ESMTP id 75907117E06C; Mon, 15 Jun 2015 14:46:04 -0700 (PDT) Original-Received: from localhost.linkov.net (m213-102-82-211.cust.tele2.ee [213.102.82.211]) (Authenticated sender: jurta@jurta.org) by homiemail-a101.g.dreamhost.com (Postfix) with ESMTPA id 683D1117E06A; Mon, 15 Jun 2015 14:46:02 -0700 (PDT) In-Reply-To: <87twv51raf.fsf@mail.linkov.net> (Juri Linkov's message of "Fri, 22 May 2015 01:47:52 +0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.0.50 (x86_64-pc-linux-gnu) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:103973 Archived-At: >> Wishlist: >> M-x shell-command-on-rectangle-region > > As you can see in bug#20070, the effort to make commands rectangleable > had stalled some time ago due to the need to decide how to handle > backward-compatibility of the existing region arguments, e.g. in > > (shell-command-on-region START END COMMAND &optional OUTPUT-BUFFER REPLACE > ERROR-BUFFER DISPLAY-ERROR-BUFFER) > > how to send the boundaries of the rectangular region in START and END. > > One idea is to handle it like recently we handled backward-compatibility > for saving dired positions in saveplace.el where we used a new format like > > ("~" (dired-filename . "~/.emacs.d/places")) > > Using something like this means sending the rectangular bounds > either in START or END in the new format like > > (rect (1 . 2) (3 . 4)) Sorry, I was wrong. I realized now that query-replace has quite a different requirement. query-replace needs rectangular boundaries to limit the search for replacements, whereas shell-command-on-region should extract the rectangular region as strings and replace it with the result of the command. Here is a working prototype that demonstrates its possible implementation: (define-advice shell-command-on-region (:around (orig-fun start end command &optional output-buffer replace error-buffer display-error-buffer)) (if (and (boundp 'rectangle-mark-mode) rectangle-mark-mode) (let ((input (mapconcat 'identity (delete-extract-rectangle start end) "\n")) output) (with-temp-buffer (insert input) (call-process-region (point-min) (point-max) shell-file-name t t nil shell-command-switch command) (setq output (split-string (buffer-string) "\n"))) (goto-char start) (insert-rectangle output)) (funcall orig-fun start end command output-buffer replace error-buffer display-error-buffer))) This is another case to take into account when designing the interface, i.e. in this case the list of boundaries in the arg START is not necessary, and I have no idea how to avoid `(if (and (boundp 'rectangle-mark-mode) rectangle-mark-mode))'