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, 23 Jun 2015 01:37:53 +0300 Organization: LINKOV.NET Message-ID: <874mlzweri.fsf@mail.linkov.net> References: <527474961.10107734.1432245870451.JavaMail.zimbra@comcast.net> <87twv51raf.fsf@mail.linkov.net> <87fv5s4pm0.fsf@mail.linkov.net> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1435012885 24588 80.91.229.3 (22 Jun 2015 22:41:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 22 Jun 2015 22:41:25 +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 Tue Jun 23 00:41:14 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 1Z7AOv-00045q-Kx for geb-bug-gnu-emacs@m.gmane.org; Tue, 23 Jun 2015 00:41:13 +0200 Original-Received: from localhost ([::1]:42300 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7AOv-0003VU-2O for geb-bug-gnu-emacs@m.gmane.org; Mon, 22 Jun 2015 18:41:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:46692) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7AOr-0003VL-49 for bug-gnu-emacs@gnu.org; Mon, 22 Jun 2015 18:41:10 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Z7AOl-0000Fk-UB for bug-gnu-emacs@gnu.org; Mon, 22 Jun 2015 18:41:09 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:53308) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Z7AOl-0000Fg-QP for bug-gnu-emacs@gnu.org; Mon, 22 Jun 2015 18:41:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1Z7AOl-0000xB-FE for bug-gnu-emacs@gnu.org; Mon, 22 Jun 2015 18:41: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, 22 Jun 2015 22:41:03 +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.14350128133595 (code B ref 20626); Mon, 22 Jun 2015 22:41:03 +0000 Original-Received: (at 20626) by debbugs.gnu.org; 22 Jun 2015 22:40:13 +0000 Original-Received: from localhost ([127.0.0.1]:54754 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z7ANw-0000vu-05 for submit@debbugs.gnu.org; Mon, 22 Jun 2015 18:40:12 -0400 Original-Received: from sub3.mail.dreamhost.com ([69.163.253.7]:35472 helo=homiemail-a19.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1Z7ANg-0000v0-TZ for 20626@debbugs.gnu.org; Mon, 22 Jun 2015 18:39:57 -0400 Original-Received: from homiemail-a19.g.dreamhost.com (localhost [127.0.0.1]) by homiemail-a19.g.dreamhost.com (Postfix) with ESMTP id 5F273604089; Mon, 22 Jun 2015 15:39:56 -0700 (PDT) Original-Received: from localhost.linkov.net (m213-102-70-120.cust.tele2.ee [213.102.70.120]) (Authenticated sender: jurta@jurta.org) by homiemail-a19.g.dreamhost.com (Postfix) with ESMTPA id 6A4AE60405D; Mon, 22 Jun 2015 15:39:55 -0700 (PDT) In-Reply-To: <87fv5s4pm0.fsf@mail.linkov.net> (Juri Linkov's message of "Tue, 16 Jun 2015 00:45:27 +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:104242 Archived-At: > 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 demonstrat= es > 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 necess= ary, > and I have no idea how to avoid `(if (and (boundp 'rectangle-mark-mode) > rectangle-mark-mode))' For example, the command =E2=80=98kill-ring-save=E2=80=99 has the signatu= re kill-ring-save (beg end &optional region) with an additional boolean arg for the region. And =E2=80=98rectangle--extract-region=E2=80=99 contains a condition that checks for =E2=80=98rectangle-mark-mode=E2=80=99. Combining these two prerequisites we could do a similar thing in =E2=80=98shell-command-on-region=E2=80=99 by adding a new arg and using i= t in the function body: diff --git a/lisp/simple.el b/lisp/simple.el index 1868077..d022504 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -3274,7 +3278,8 @@ =20 (defun shell-command-on-region (start end command &optional output-buffer replace - error-buffer display-error-buffer) + error-buffer display-error-buffer + region) "Execute string COMMAND in inferior shell with region as input. Normally display output (if any) in temp buffer `*Shell Command Output*'= ; Prefix arg means replace the region with it. Return the exit code of @@ -3337,7 +3342,8 @@ (defun shell-command-on-region (start end command current-prefix-arg current-prefix-arg shell-command-default-error-buffer - t))) + t + rectangle-mark-mode))) (let ((error-file (if error-buffer (make-temp-file @@ -3346,6 +3352,18 @@ (defun shell-command-on-region (start end command temporary-file-directory))) nil)) exit-status) + (if region + (let ((input (mapconcat 'identity (delete-extract-rectangle star= t 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)) (if (or replace (and output-buffer (not (or (bufferp output-buffer) (stringp output-buffer))))) @@ -3435,7 +3453,7 @@ (defun shell-command-on-region (start end command exit-status output)))) ;; Don't kill: there might be useful info in the undo-log. ;; (kill-buffer buffer) - )))) + ))))) =20 (when (and error-file (file-exists-p error-file)) (if (< 0 (nth 7 (file-attributes error-file)))