From: Lars Ingebrigtsen <larsi@gnus.org>
To: jidanni@jidanni.org
Cc: 10239@debbugs.gnu.org, 25329@debbugs.gnu.org
Subject: bug#10239: compilation-auto-jump-to-first-error vs. giant binary executables
Date: Sun, 29 Sep 2019 19:08:40 +0200 [thread overview]
Message-ID: <87tv8vav3b.fsf@gnus.org> (raw)
In-Reply-To: <87y5upfg2m.fsf@jidanni.org> (jidanni@jidanni.org's message of "Wed, 07 Dec 2011 07:14:41 +0800")
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
next prev parent reply other threads:[~2019-09-29 17:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-06 23:14 bug#10239: compilation-auto-jump-to-first-error vs. giant binary executables jidanni
2019-09-29 17:08 ` Lars Ingebrigtsen [this message]
2019-09-29 17:30 ` 積丹尼 Dan Jacobson
2019-09-29 17:43 ` Andreas Schwab
2019-09-29 18:48 ` bug#25329: " Lars Ingebrigtsen
2019-10-09 23:20 ` bug#10239: " Lars Ingebrigtsen
2019-10-10 8:32 ` bug#25329: " Andreas Schwab
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87tv8vav3b.fsf@gnus.org \
--to=larsi@gnus.org \
--cc=10239@debbugs.gnu.org \
--cc=25329@debbugs.gnu.org \
--cc=jidanni@jidanni.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).