unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#48302: [PATCH] Abbreviate `find' properties in M-x rgrep on MS Windows
@ 2021-05-08 22:17 Jim Porter
  2021-05-09  6:53 ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Jim Porter @ 2021-05-08 22:17 UTC (permalink / raw)
  To: 48302

[-- Attachment #1: Type: text/plain, Size: 2267 bytes --]

MS Windows has different shell-quoting logic from POSIX shells, so the
regexp to abbreviate the `find' command's properties in rgrep fails to
match on MS Windows. The attached patch fixes this by looking for
either `\)' (POSIX) or `")"' (MS Windows) as the end of the properties
list.

Steps to reproduce:

  ;; Ensure GNU find and grep are in your path
  emacs -Q
  M-x rgrep RET foo RET RET RET
  ;; See the full, unabbreviated command instead of `find [...] -exec grep'...

To make things easier to review for people without access to MS
Windows, this is the full invocation for rgrep:

---------- Begin Block ----------

find . -type d "(" -path "*/SCCS" -o -path "*/RCS" -o -path "*/CVS" -o
-path "*/MCVS" -o -path "*/.src" -o -path "*/.svn" -o -path "*/.git"
-o -path "*/.hg" -o -path "*/.bzr" -o -path "*/_MTN" -o -path
"*/_darcs" -o -path "*/{arch}" ")" -prune -o ^"^!^" -type d "(" -name
".#*" -o -name "*.o" -o -name "*~" -o -name "*.bin" -o -name "*.bak"
-o -name "*.obj" -o -name "*.map" -o -name "*.ico" -o -name "*.pif" -o
-name "*.lnk" -o -name "*.a" -o -name "*.ln" -o -name "*.blg" -o -name
"*.bbl" -o -name "*.dll" -o -name "*.drv" -o -name "*.vxd" -o -name
"*.386" -o -name "*.elc" -o -name "*.lof" -o -name "*.glo" -o -name
"*.idx" -o -name "*.lot" -o -name "*.fmt" -o -name "*.tfm" -o -name
"*.class" -o -name "*.fas" -o -name "*.lib" -o -name "*.mem" -o -name
"*.x86f" -o -name "*.sparcf" -o -name "*.dfsl" -o -name "*.pfsl" -o
-name "*.d64fsl" -o -name "*.p64fsl" -o -name "*.lx64fsl" -o -name
"*.lx32fsl" -o -name "*.dx64fsl" -o -name "*.dx32fsl" -o -name
"*.fx64fsl" -o -name "*.fx32fsl" -o -name "*.sx64fsl" -o -name
"*.sx32fsl" -o -name "*.wx64fsl" -o -name "*.wx32fsl" -o -name
"*.fasl" -o -name "*.ufsl" -o -name "*.fsl" -o -name "*.dxl" -o -name
"*.lo" -o -name "*.la" -o -name "*.gmo" -o -name "*.mo" -o -name
"*.toc" -o -name "*.aux" -o -name "*.cp" -o -name "*.fn" -o -name
"*.ky" -o -name "*.pg" -o -name "*.tp" -o -name "*.vr" -o -name
"*.cps" -o -name "*.fns" -o -name "*.kys" -o -name "*.pgs" -o -name
"*.tps" -o -name "*.vrs" -o -name "*.pyc" -o -name "*.pyo" ")" -prune
-o  -type f "(" -iname "*" -o -iname ^".[^!.]*^" -o -iname "..?*" ")"
-exec grep --color=always -i -nH --null "foo" "{}" ";"

---------- End Block ----------

[-- Attachment #2: 0001-Abbreviate-rgrep-command-when-using-MS-Windows-style.patch --]
[-- Type: application/octet-stream, Size: 1060 bytes --]

From 6760457c78cc0bd29305f5989130012c142a108a Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Sat, 8 May 2021 14:54:20 -0700
Subject: [PATCH] Abbreviate rgrep command when using MS Windows-style
 shell-quoting

lisp/progmodes/grep.el (grep-mode-font-lock-keywords): Adapt regexp to match
MS Windows-style shell-quoting.
---
 lisp/progmodes/grep.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index e9fbcbbfcd..80c3e7840f 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -473,7 +473,7 @@ grep-mode-font-lock-keywords
       (1 (if (eq (char-after (match-beginning 1)) ?\0)
              `(face nil display ,(match-string 2)))))
      ;; Hide excessive part of rgrep command
-     ("^find \\(\\. -type d .*\\\\)\\)"
+     ("^find \\(\\. -type d .*\\(?:\\\\)\\|\")\"\\)\\)"
       (1 (if grep-find-abbreviate grep-find-abbreviate-properties
            '(face nil abbreviated-command t))))
      ;; Hide excessive part of lgrep command
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#48302: [PATCH] Abbreviate `find' properties in M-x rgrep on MS Windows
  2021-05-08 22:17 bug#48302: [PATCH] Abbreviate `find' properties in M-x rgrep on MS Windows Jim Porter
@ 2021-05-09  6:53 ` Eli Zaretskii
  2021-05-09 20:07   ` Jim Porter
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2021-05-09  6:53 UTC (permalink / raw)
  To: Jim Porter; +Cc: 48302

> From: Jim Porter <jporterbugs@gmail.com>
> Date: Sat, 8 May 2021 15:17:14 -0700
> 
> MS Windows has different shell-quoting logic from POSIX shells, so the
> regexp to abbreviate the `find' command's properties in rgrep fails to
> match on MS Windows. The attached patch fixes this by looking for
> either `\)' (POSIX) or `")"' (MS Windows) as the end of the properties
> list.

Thanks, but could you also add a test for this issue to the test
suite?





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48302: [PATCH] Abbreviate `find' properties in M-x rgrep on MS Windows
  2021-05-09  6:53 ` Eli Zaretskii
@ 2021-05-09 20:07   ` Jim Porter
  2021-05-10  7:42     ` Michael Albinus
  0 siblings, 1 reply; 8+ messages in thread
From: Jim Porter @ 2021-05-09 20:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 48302

[-- Attachment #1: Type: text/plain, Size: 898 bytes --]

On Sat, May 8, 2021 at 11:53 PM Eli Zaretskii <eliz@gnu.org> wrote:
>
> Thanks, but could you also add a test for this issue to the test
> suite?

I see some grep-related tests in
`test/lisp/progmodes/compile-tests.el', but those only cover
`grep-regexp-alist', not `grep-mode-font-lock-keywords'. Testing
grep.el's font-lock didn't seem like it would belong in
`compile-tests.el', so I've added `test/lisp/progmodes/grep-tests.el'
and included a (very) simple test for find-abbreviation. It uses the
shell-quoting semantics of whatever the current system is; it would be
nice to test all shell-quoting styles in one test run, but I wasn't
sure how to do that. Still, if automated tests are run on multiple
platforms, this should (hopefully) catch any bugs.

My Elisp skills are fairly basic, so I may have made some mistakes
here. Just let me know what (if anything) needs improved for the
tests.

[-- Attachment #2: 0001-Abbreviate-rgrep-command-when-using-MS-Windows-style.patch --]
[-- Type: application/octet-stream, Size: 2808 bytes --]

From f038b2426edc7c7db7ecbdc896e11b4dc35d54e0 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Sun, 9 May 2021 13:05:22 -0700
Subject: [PATCH] Abbreviate rgrep command when using MS Windows-style
 shell-quoting

lisp/progmodes/grep.el (grep-mode-font-lock-keywords): Adapt regexp to match
MS Windows-style shell-quoting.
test/lisp/progmodes/grep-tests.el: New file.
---
 lisp/progmodes/grep.el            |  2 +-
 test/lisp/progmodes/grep-tests.el | 39 +++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+), 1 deletion(-)
 create mode 100644 test/lisp/progmodes/grep-tests.el

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index e9fbcbbfcd..80c3e7840f 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -473,7 +473,7 @@ grep-mode-font-lock-keywords
       (1 (if (eq (char-after (match-beginning 1)) ?\0)
              `(face nil display ,(match-string 2)))))
      ;; Hide excessive part of rgrep command
-     ("^find \\(\\. -type d .*\\\\)\\)"
+     ("^find \\(\\. -type d .*\\(?:\\\\)\\|\")\"\\)\\)"
       (1 (if grep-find-abbreviate grep-find-abbreviate-properties
            '(face nil abbreviated-command t))))
      ;; Hide excessive part of lgrep command
diff --git a/test/lisp/progmodes/grep-tests.el b/test/lisp/progmodes/grep-tests.el
new file mode 100644
index 0000000000..211b96a765
--- /dev/null
+++ b/test/lisp/progmodes/grep-tests.el
@@ -0,0 +1,39 @@
+;;; grep-tests.el --- Test suite for grep.el  -*- lexical-binding:t -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'ert)
+(require 'grep)
+
+(ert-deftest grep-tests--find-abbreviate-properties ()
+  (let ((ellipsis (if (char-displayable-p ?…) "[…]" "[...]")))
+    (with-temp-buffer
+      (grep-compute-defaults)
+      (insert (rgrep-default-command "search" "*" nil))
+      (grep-mode)
+      (font-lock-mode)
+      (font-lock-ensure)
+      (goto-char (point-min))
+      (re-search-forward "find ")
+      (should (equal (get-text-property (point) 'display) ellipsis)))))
+
+;;; grep-tests.el ends here
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#48302: [PATCH] Abbreviate `find' properties in M-x rgrep on MS Windows
  2021-05-09 20:07   ` Jim Porter
@ 2021-05-10  7:42     ` Michael Albinus
  2021-05-11  4:36       ` bug#48302: [PATCH v2] " Jim Porter
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Albinus @ 2021-05-10  7:42 UTC (permalink / raw)
  To: Jim Porter; +Cc: 48302

Jim Porter <jporterbugs@gmail.com> writes:

Hi Jim,

> It uses the shell-quoting semantics of whatever the current system is;
> it would be nice to test all shell-quoting styles in one test run, but
> I wasn't sure how to do that.

You could force this by let-binding system-type, like

--8<---------------cut here---------------start------------->8---
(let ((system-type 'gnu/linux))
  (rgrep-default-command "search" "*" nil)
  ...)

(let ((system-type 'darwin))
  (rgrep-default-command "search" "*" nil)
  ...)
--8<---------------cut here---------------end--------------->8---

In the windows-nt case, the function w32-shell-dos-semantics is called,
which does not exist on other systems. So you must mock it up to return
either t or nil:

--8<---------------cut here---------------start------------->8---
(let ((system-type 'windows-nt))
  (cl-letf (((symbol-function #'w32-shell-dos-semantics) #'always))
    (rgrep-default-command "search" "*" nil)
    ...))

(let ((system-type 'windows-nt))
  (cl-letf (((symbol-function #'w32-shell-dos-semantics) #'ignore))
    (rgrep-default-command "search" "*" nil)
    ...))
--8<---------------cut here---------------end--------------->8---

Best regards, Michael.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48302: [PATCH v2] Re: bug#48302: [PATCH] Abbreviate `find' properties in M-x rgrep on MS Windows
  2021-05-10  7:42     ` Michael Albinus
@ 2021-05-11  4:36       ` Jim Porter
  2021-05-11  7:11         ` Michael Albinus
  0 siblings, 1 reply; 8+ messages in thread
From: Jim Porter @ 2021-05-11  4:36 UTC (permalink / raw)
  To: Michael Albinus; +Cc: 48302

[-- Attachment #1: Type: text/plain, Size: 423 bytes --]

On Mon, May 10, 2021 at 12:42 AM Michael Albinus <michael.albinus@gmx.de> wrote:
> > It uses the shell-quoting semantics of whatever the current system is;
> > it would be nice to test all shell-quoting styles in one test run, but
> > I wasn't sure how to do that.
>
> You could force this by let-binding system-type, like [snip]

Thanks for the pointers. Attached is an updated patch that tests the 4
cases you described.

[-- Attachment #2: 0001-Abbreviate-rgrep-command-when-using-MS-Windows-style.patch --]
[-- Type: application/octet-stream, Size: 4092 bytes --]

From df589d6673a481a5a2185922a4727cbdeb608431 Mon Sep 17 00:00:00 2001
From: Jim Porter <jporterbugs@gmail.com>
Date: Mon, 10 May 2021 21:35:16 -0700
Subject: [PATCH] Abbreviate rgrep command when using MS Windows-style
 shell-quoting

lisp/progmodes/grep.el (grep-mode-font-lock-keywords): Adapt regexp to match
MS Windows-style shell-quoting.
test/lisp/progmodes/grep-tests.el: New file.
---
 lisp/progmodes/grep.el            |  2 +-
 test/lisp/progmodes/grep-tests.el | 69 +++++++++++++++++++++++++++++++
 2 files changed, 70 insertions(+), 1 deletion(-)
 create mode 100644 test/lisp/progmodes/grep-tests.el

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index e9fbcbbfcd..80c3e7840f 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -473,7 +473,7 @@ grep-mode-font-lock-keywords
       (1 (if (eq (char-after (match-beginning 1)) ?\0)
              `(face nil display ,(match-string 2)))))
      ;; Hide excessive part of rgrep command
-     ("^find \\(\\. -type d .*\\\\)\\)"
+     ("^find \\(\\. -type d .*\\(?:\\\\)\\|\")\"\\)\\)"
       (1 (if grep-find-abbreviate grep-find-abbreviate-properties
            '(face nil abbreviated-command t))))
      ;; Hide excessive part of lgrep command
diff --git a/test/lisp/progmodes/grep-tests.el b/test/lisp/progmodes/grep-tests.el
new file mode 100644
index 0000000000..1f478a6a93
--- /dev/null
+++ b/test/lisp/progmodes/grep-tests.el
@@ -0,0 +1,69 @@
+;;; grep-tests.el --- Test suite for grep.el  -*- lexical-binding:t -*-
+
+;; Copyright (C) 2021 Free Software Foundation, Inc.
+
+;; This file is part of GNU Emacs.
+
+;; GNU Emacs is free software: you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;;; Code:
+
+(require 'ert)
+(require 'grep)
+
+(defconst grep-tests--ellipsis (if (char-displayable-p ?…) "[…]" "[...]")
+  "The form that the ellipsis takes in `grep-find-abbreviate-properties'.")
+
+(defun grep-tests--get-rgrep-abbreviation ()
+  "Get the `display' property of the excessive part of the rgrep command."
+  (with-temp-buffer
+    (grep-compute-defaults)
+    (insert (rgrep-default-command "search" "*" nil))
+    (grep-mode)
+    (font-lock-mode)
+    (font-lock-ensure)
+    (goto-char (point-min))
+    (re-search-forward "find ")
+    (get-text-property (point) 'display)))
+
+(defun grep-tests--check-rgrep-abbreviation ()
+  "Check that the excessive part of the rgrep command is abbreviated iff
+`grep-find-abbreviate' is non-nil."
+  (let ((grep-find-abbreviate t))
+    (should (equal (grep-tests--get-rgrep-abbreviation)
+                   grep-tests--ellipsis)))
+  (let ((grep-find-abbreviate nil))
+    (should (equal (grep-tests--get-rgrep-abbreviation) nil))))
+
+(ert-deftest grep-tests--rgrep-abbreviate-properties-gnu-linux ()
+  (let ((system-type 'gnu/linux))
+    (grep-tests--check-rgrep-abbreviation)))
+
+(ert-deftest grep-tests--rgrep-abbreviate-properties-darwin ()
+  (let ((system-type 'darwin))
+    (grep-tests--check-rgrep-abbreviation)))
+
+(ert-deftest grep-tests--rgrep-abbreviate-properties-windows-nt-dos-semantics ()
+  (let ((system-type 'windows-nt))
+    (cl-letf (((symbol-function #'w32-shell-dos-semantics) #'always))
+      (grep-tests--check-rgrep-abbreviation))))
+
+(ert-deftest grep-tests--rgrep-abbreviate-properties-windows-nt-sh-semantics ()
+  (let ((system-type 'windows-nt))
+    (cl-letf (((symbol-function #'w32-shell-dos-semantics) #'ignore))
+      (grep-tests--check-rgrep-abbreviation))))
+
+;;; grep-tests.el ends here
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* bug#48302: [PATCH v2] Re: bug#48302: [PATCH] Abbreviate `find' properties in M-x rgrep on MS Windows
  2021-05-11  4:36       ` bug#48302: [PATCH v2] " Jim Porter
@ 2021-05-11  7:11         ` Michael Albinus
  2021-05-11 12:22           ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Michael Albinus @ 2021-05-11  7:11 UTC (permalink / raw)
  To: Jim Porter; +Cc: 48302

Jim Porter <jporterbugs@gmail.com> writes:

Hi Jim,

> Thanks for the pointers. Attached is an updated patch that tests the 4
> cases you described.

Thanks. LGTM. Just one nit:

> +    (should (equal (grep-tests--get-rgrep-abbreviation) nil))))

This is (should-not (grep-tests--get-rgrep-abbreviation))

Eli, do you have further comments? Otherwise, I would commit it in Jim's
name.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48302: [PATCH v2] Re: bug#48302: [PATCH] Abbreviate `find' properties in M-x rgrep on MS Windows
  2021-05-11  7:11         ` Michael Albinus
@ 2021-05-11 12:22           ` Eli Zaretskii
  2021-05-12  8:48             ` Michael Albinus
  0 siblings, 1 reply; 8+ messages in thread
From: Eli Zaretskii @ 2021-05-11 12:22 UTC (permalink / raw)
  To: Michael Albinus; +Cc: jporterbugs, 48302

> From: Michael Albinus <michael.albinus@gmx.de>
> Cc: Eli Zaretskii <eliz@gnu.org>,  48302@debbugs.gnu.org
> Date: Tue, 11 May 2021 09:11:01 +0200
> 
> Eli, do you have further comments? Otherwise, I would commit it in Jim's
> name.

No further comments, but please be sure to mention the bug number in
the commit log message.

Thanks.





^ permalink raw reply	[flat|nested] 8+ messages in thread

* bug#48302: [PATCH v2] Re: bug#48302: [PATCH] Abbreviate `find' properties in M-x rgrep on MS Windows
  2021-05-11 12:22           ` Eli Zaretskii
@ 2021-05-12  8:48             ` Michael Albinus
  0 siblings, 0 replies; 8+ messages in thread
From: Michael Albinus @ 2021-05-12  8:48 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: jporterbugs, 48302-done

Eli Zaretskii <eliz@gnu.org> writes:

>> Eli, do you have further comments? Otherwise, I would commit it in Jim's
>> name.
>
> No further comments, but please be sure to mention the bug number in
> the commit log message.

Done, closing the bug.

> Thanks.

Best regards, Michael.





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2021-05-12  8:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-08 22:17 bug#48302: [PATCH] Abbreviate `find' properties in M-x rgrep on MS Windows Jim Porter
2021-05-09  6:53 ` Eli Zaretskii
2021-05-09 20:07   ` Jim Porter
2021-05-10  7:42     ` Michael Albinus
2021-05-11  4:36       ` bug#48302: [PATCH v2] " Jim Porter
2021-05-11  7:11         ` Michael Albinus
2021-05-11 12:22           ` Eli Zaretskii
2021-05-12  8:48             ` Michael Albinus

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).