all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#49978: 28.0.50; grep-highlight-matches auto-detection broken on macOS [PATCH]
@ 2021-08-10 12:54 Mattias Engdegård
  2021-08-10 13:23 ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Mattias Engdegård @ 2021-08-10 12:54 UTC (permalink / raw)
  To: 49978

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

The auto-detection of colourised grep fails on macOS (and presumably BSD in general) because grep --help exits with a nonzero status (while still printing a useful option summary).

We should just ignore the exit status. Anyone against the attached patch?


[-- Attachment #2: grep-highlight-matches-autodetect.diff --]
[-- Type: application/octet-stream, Size: 896 bytes --]

diff --git a/lisp/progmodes/grep.el b/lisp/progmodes/grep.el
index 8f0a5acf70..a33a247d9b 100644
--- a/lisp/progmodes/grep.el
+++ b/lisp/progmodes/grep.el
@@ -696,11 +696,11 @@ grep-compute-defaults
     (when (eq grep-highlight-matches 'auto-detect)
       (setq grep-highlight-matches
 	    (with-temp-buffer
-	      (and (grep-probe grep-program '(nil t nil "--help"))
-		   (progn
-		     (goto-char (point-min))
-		     (search-forward "--color" nil t))
-		   ;; Windows and DOS pipes fail `isatty' detection in Grep.
+              ;; The "grep --help" exit status varies; pay no attention to it.
+              (grep-probe grep-program '(nil t nil "--help"))
+	      (goto-char (point-min))
+	      (and (search-forward "--color" nil t)
+	           ;; Windows and DOS pipes fail `isatty' detection in Grep.
 		   (if (memq system-type '(windows-nt ms-dos))
 		       'always 'auto)))))
 

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

* bug#49978: 28.0.50; grep-highlight-matches auto-detection broken on macOS [PATCH]
  2021-08-10 12:54 bug#49978: 28.0.50; grep-highlight-matches auto-detection broken on macOS [PATCH] Mattias Engdegård
@ 2021-08-10 13:23 ` Eli Zaretskii
  2021-08-10 13:39   ` Mattias Engdegård
  0 siblings, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2021-08-10 13:23 UTC (permalink / raw)
  To: Mattias Engdegård; +Cc: 49978

> From: Mattias Engdegård <mattiase@acm.org>
> Date: Tue, 10 Aug 2021 14:54:43 +0200
> 
> The auto-detection of colourised grep fails on macOS (and presumably BSD in general) because grep --help exits with a nonzero status (while still printing a useful option summary).
> 
> We should just ignore the exit status. Anyone against the attached patch?

Not me (this time ;-).  Although perhaps we should strengthen the
search string to be sure we don't hit some false positive: "--color"
sounds a bit too general, no?  Or do you think it's good enough even
if "--help" causes a non-zero exit code?





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

* bug#49978: 28.0.50; grep-highlight-matches auto-detection broken on macOS [PATCH]
  2021-08-10 13:23 ` Eli Zaretskii
@ 2021-08-10 13:39   ` Mattias Engdegård
  2021-08-10 13:57     ` Eli Zaretskii
  0 siblings, 1 reply; 6+ messages in thread
From: Mattias Engdegård @ 2021-08-10 13:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 49978

10 aug. 2021 kl. 15.23 skrev Eli Zaretskii <eliz@gnu.org>:

> Although perhaps we should strengthen the
> search string to be sure we don't hit some false positive: "--color"
> sounds a bit too general, no?  Or do you think it's good enough even
> if "--help" causes a non-zero exit code?

I honestly don't know. The patch works here (obviously) but strengthening it using a regexp to avoid matching "--colorise", say, probably won't hurt. Not that it's very likely that this would ever make a difference, but if you think that it's better safe then sorry then I'll do that.

For the record, on this Mac I get:

$ grep --help
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
	[-e pattern] [-f file] [--binary-files=value] [--color=when]
	[--context[=num]] [--directories=action] [--label] [--line-buffered]
	[--null] [pattern] [file ...]
$ grep --version
grep (BSD grep) 2.5.1-FreeBSD

The exit status is probably a red herring; we do not seem to gain any useful information from it.






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

* bug#49978: 28.0.50; grep-highlight-matches auto-detection broken on macOS [PATCH]
  2021-08-10 13:39   ` Mattias Engdegård
@ 2021-08-10 13:57     ` Eli Zaretskii
  2021-08-10 14:03       ` Lars Ingebrigtsen
  2021-08-10 15:11       ` Mattias Engdegård
  0 siblings, 2 replies; 6+ messages in thread
From: Eli Zaretskii @ 2021-08-10 13:57 UTC (permalink / raw)
  To: Mattias Engdegård, Lars Ingebrigtsen; +Cc: 49978

> From: Mattias Engdegård <mattiase@acm.org>
> Date: Tue, 10 Aug 2021 15:39:04 +0200
> Cc: 49978@debbugs.gnu.org
> 
> 10 aug. 2021 kl. 15.23 skrev Eli Zaretskii <eliz@gnu.org>:
> 
> > Although perhaps we should strengthen the
> > search string to be sure we don't hit some false positive: "--color"
> > sounds a bit too general, no?  Or do you think it's good enough even
> > if "--help" causes a non-zero exit code?
> 
> I honestly don't know. The patch works here (obviously) but strengthening it using a regexp to avoid matching "--colorise", say, probably won't hurt. Not that it's very likely that this would ever make a difference, but if you think that it's better safe then sorry then I'll do that.

I think just looking for "--color[[]?=" should go a long way towards
avoiding false positives.  WDYT?

Lars, any comments?

Btw, is this usage message translatable?  If so, perhaps we should
inject LC_ALL=C when running the probe?





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

* bug#49978: 28.0.50; grep-highlight-matches auto-detection broken on macOS [PATCH]
  2021-08-10 13:57     ` Eli Zaretskii
@ 2021-08-10 14:03       ` Lars Ingebrigtsen
  2021-08-10 15:11       ` Mattias Engdegård
  1 sibling, 0 replies; 6+ messages in thread
From: Lars Ingebrigtsen @ 2021-08-10 14:03 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 49978, Mattias Engdegård

Eli Zaretskii <eliz@gnu.org> writes:

> I think just looking for "--color[[]?=" should go a long way towards
> avoiding false positives.  WDYT?
>
> Lars, any comments?

No, I'm not really that familiar with this code.  

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





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

* bug#49978: 28.0.50; grep-highlight-matches auto-detection broken on macOS [PATCH]
  2021-08-10 13:57     ` Eli Zaretskii
  2021-08-10 14:03       ` Lars Ingebrigtsen
@ 2021-08-10 15:11       ` Mattias Engdegård
  1 sibling, 0 replies; 6+ messages in thread
From: Mattias Engdegård @ 2021-08-10 15:11 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 49978-done, Lars Ingebrigtsen

10 aug. 2021 kl. 15.57 skrev Eli Zaretskii <eliz@gnu.org>:

> I think just looking for "--color[[]?=" should go a long way towards
> avoiding false positives.

Right, pushed something like that. Thank you!

> Btw, is this usage message translatable?  If so, perhaps we should
> inject LC_ALL=C when running the probe?

I don't think we need to bother -- even if the message is translated the options themselves are not.






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

end of thread, other threads:[~2021-08-10 15:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-08-10 12:54 bug#49978: 28.0.50; grep-highlight-matches auto-detection broken on macOS [PATCH] Mattias Engdegård
2021-08-10 13:23 ` Eli Zaretskii
2021-08-10 13:39   ` Mattias Engdegård
2021-08-10 13:57     ` Eli Zaretskii
2021-08-10 14:03       ` Lars Ingebrigtsen
2021-08-10 15:11       ` Mattias Engdegård

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.