From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Lars Ingebrigtsen Newsgroups: gmane.emacs.bugs Subject: bug#10239: compilation-auto-jump-to-first-error vs. giant binary executables Date: Sun, 29 Sep 2019 19:08:40 +0200 Message-ID: <87tv8vav3b.fsf@gnus.org> References: <87y5upfg2m.fsf@jidanni.org> Mime-Version: 1.0 Content-Type: text/plain Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="41905"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: 10239@debbugs.gnu.org, 25329@debbugs.gnu.org To: jidanni@jidanni.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Sep 29 19:09:22 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iEchG-000An8-7E for geb-bug-gnu-emacs@m.gmane.org; Sun, 29 Sep 2019 19:09:22 +0200 Original-Received: from localhost ([::1]:41232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iEchE-0007N3-Gj for geb-bug-gnu-emacs@m.gmane.org; Sun, 29 Sep 2019 13:09:20 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:60439) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iEcgx-0007Mk-NO for bug-gnu-emacs@gnu.org; Sun, 29 Sep 2019 13:09:05 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iEcgw-0005gL-CL for bug-gnu-emacs@gnu.org; Sun, 29 Sep 2019 13:09:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46935) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iEcgw-0005f7-7i for bug-gnu-emacs@gnu.org; Sun, 29 Sep 2019 13:09:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iEcgw-0002Ax-1i for bug-gnu-emacs@gnu.org; Sun, 29 Sep 2019 13:09:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Lars Ingebrigtsen Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 29 Sep 2019 17:09:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10239 X-GNU-PR-Package: emacs Original-Received: via spool by 10239-submit@debbugs.gnu.org id=B10239.15697769288323 (code B ref 10239); Sun, 29 Sep 2019 17:09:01 +0000 Original-Received: (at 10239) by debbugs.gnu.org; 29 Sep 2019 17:08:48 +0000 Original-Received: from localhost ([127.0.0.1]:55753 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iEcgh-0002A5-QK for submit@debbugs.gnu.org; Sun, 29 Sep 2019 13:08:48 -0400 Original-Received: from quimby.gnus.org ([80.91.231.51]:59176) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iEcgf-00029r-Kp; Sun, 29 Sep 2019 13:08:46 -0400 Original-Received: from cm-84.212.202.86.getinternet.no ([84.212.202.86] helo=marnie) by quimby.gnus.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iEcgb-0003ff-30; Sun, 29 Sep 2019 19:08:43 +0200 In-Reply-To: <87y5upfg2m.fsf@jidanni.org> (jidanni@jidanni.org's message of "Wed, 07 Dec 2011 07:14:41 +0800") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.51.188.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" Xref: news.gmane.org gmane.emacs.bugs:167730 Archived-At: jidanni@jidanni.org writes: > $ cat Makefile > a:;set -Y > $ emacs -Q -eval '(setq compilation-auto-jump-to-first-error t)' -f compile > RET > /bin/sh: line 0: set: -Y: invalid option > Wham pow! We are looking at a whole megabyte of binary ELF /bin/sh executable. > I didn't try it on lager files or with ones with strings the colorizer > would try to color etc. The problem is that compilation mode interprets this /bin/sh: 1: test: -gt: unexpected operator as an error (which is right), but believes that this error originates in /bin/sh, so when you jump to the first error in the buffer, you're presented with /bin/sh in a buffer, which isn't very helpful. In addition, it identifies this line: make: *** [Makefile:1: a] Error 2 as another error, which is even more right, but it thinks that the file name is "*** [Makefile", which is wrong. So I took a whack at fixing both these things with a new mechanism that allows transformation of detected file names (and ignoring them in the case of /bin/sh). Patch included below. Does this seems like a good mechanism for doing this stuff? diff --git a/lisp/progmodes/compile.el b/lisp/progmodes/compile.el index d80fef3103..a29dc5cc47 100644 --- a/lisp/progmodes/compile.el +++ b/lisp/progmodes/compile.el @@ -58,6 +58,16 @@ compilation-window-height :type '(choice (const :tag "Default" nil) integer)) +(defcustom compilation-transform-file-match-alist + '(("/bin/[a-z]*sh\\'" nil) + ("\\*+ \\[\\(Makefile\\)" "\\1")) + "Alist of regexp/replacements to alter file names in compilation errors. +If the replacement is nil, the file will not be considered an +error after all. If not nil, it should be a regexp replacement +string." + :type '(repeat (list regexp string)) + :version "27.1") + (defvar compilation-filter-hook nil "Hook run after `compilation-filter' has inserted a string into the buffer. It is called with the variable `compilation-filter-start' bound @@ -1155,19 +1165,36 @@ compilation-error-properties (setq end-col (match-string-no-properties end-col)) (- (string-to-number end-col) -1))) (and end-line -1))) - (if (consp type) ; not a static type, check what it is. + (if (consp type) ; not a static type, check what it is. (setq type (or (and (car type) (match-end (car type)) 1) (and (cdr type) (match-end (cdr type)) 0) 2))) - - (when (and compilation-auto-jump-to-next - (>= type compilation-skip-threshold)) - (kill-local-variable 'compilation-auto-jump-to-next) - (run-with-timer 0 nil 'compilation-auto-jump - (current-buffer) (match-beginning 0))) - - (compilation-internal-error-properties - file line end-line col end-col type fmt))) + ;; Remove matches like /bin/sh and do other file name transforms. + (save-match-data + (let ((transformed nil)) + (dolist (f file) + (let ((match + (cl-loop for (regexp replacement) + in compilation-transform-file-match-alist + when (string-match regexp f) + return (or replacement t)))) + (cond ((not match) + (push f transformed)) + ((stringp match) + (push (replace-match match nil nil f) transformed))))) + (setq file (nreverse transformed)))) + (if (not file) + ;; If we ignored all the files with errors on this line, then + ;; return nil. + nil + (when (and compilation-auto-jump-to-next + (>= type compilation-skip-threshold)) + (kill-local-variable 'compilation-auto-jump-to-next) + (run-with-timer 0 nil 'compilation-auto-jump + (current-buffer) (match-beginning 0))) + + (compilation-internal-error-properties + file line end-line col end-col type fmt)))) (defun compilation-beginning-of-line (&optional n) "Like `beginning-of-line', but accounts for lines hidden by `selective-display'." -- (domestic pets only, the antidote for overdose, milk.) bloggy blog: http://lars.ingebrigtsen.no