Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6078145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:48:01+00:00 2026-05-23T10:48:01+00:00

So I have a tool lints python changes I’ve made and produces errors and

  • 0

So I have a tool lints python changes I’ve made and produces errors and warnings. I would like this to be usable in compile mode with Emacs, but I have an issue. The file name is output only once at the beginning, and then only line numbers appear with the errors and warnings. Here’s an example:

Linting file.py
E0602: 37: Undefined variable 'foo'
C6003: 42: Unnecessary parens after 'print' keyword
2 new errors, 2 total errors in file.py.

It’s very similar to pylint, but there’s no output-format=parseable option. I checked the documentation for compilation-error-regexp-alist, and found something promising:

If FILE, LINE or COLUMN are nil or that index didn’t match, that
information is not present on the matched line. In that case the
file name is assumed to be the same as the previous one in the
buffer, line number defaults to 1 and column defaults to
beginning of line’s indentation.

So I tried writing a regexp that would optionally match the file line and pull it out in a group, and then the rest would match the other lines. I assumed that it would first match

Linting file.py
E0602: 37: Undefined variable 'foo'

and be fine. Then it would continue and match

C6003: 42: Unnecessary parens after 'print' keyword

with no file. Since there was no file, it should use the file name from the previous match right? Here’s the regexp I’m using:

(add-to-list 'compilation-error-regexp-alist 'special-lint)
(add-to-list 'compilation-error-regexp-alist-alist
         '(special-lint
           "\\(Linting \\(.*\\)\\n\\)?\\([[:upper:]][[:digit:]]+:\\s-+\\([[:digit:]]\\)+\\).*"
           2 4 nil nil 3))

I’ve checked it with re-builder and manually in the scratch buffer. It behaves as expected. the 2nd group is the file name, the 4th is the line number, and the 3rd is what I want highlighted. Whenever I try this, I get the error:

signal(error ("No match 2 in highlight (2 compilation-error-face)"))

I have a workaround for this that involves transforming the output before the compile module looks at it, but I’d prefer to get rid of that and have a “pure” solution. I would appreciate any advice or pointing out any dumb mistakes I may have made.

EDIT

Thomas’ pseudo code below worked quite well. He mentioned that doing a backwards re search could mess up the match data, and it did. But that was solved by adding the save-match-data special form before save-excursion.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T10:48:01+00:00Added an answer on May 23, 2026 at 10:48 am

    FILE can also have the form (FILE
    FORMAT…), where the FORMATs (e.g.
    “%s.c”) will be applied in turn to the
    recognized file name, until a file of
    that name is found. Or FILE can also
    be a function that returns (FILENAME)
    or (RELATIVE-FILENAME . DIRNAME). In
    the former case, FILENAME may be
    relative or absolute.

    You could try to write a regex that doesn’t match the file name at all, only the column. Then for the file, write a function that searches backwards for the file. Perhaps not as efficient, but it should have the advantage that you can move upwards through the error messages and it will still identify the correct file when you cross file boundaries.

    I don’t have the necessary stuff installed to try this out, but take the following pseudo-code as an inspiration:

    (add-to-list 'compilation-error-regexp-alist-alist
             '(special-lint
               "^\\S-+\\s-+\\([0-9]+\\):.*" ;; is .* necessary?
               'special-lint-backward-search-filename 1))
    
    (defun special-lint-backward-search-filename ()
      (save-excursion
        (when (re-search-backward "^Linting \\(.*\\)$" (point-min) t) 
          (list (match-string 1)))))
    

    (It could be that using a search function inside special-lint-backward-search-filename will screw up the sub-group matching of the compilation-error-regexp, which would suck.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a lint-like tool for C#? I've got the compiler to flag warnings-as-errors,
I have written a tool tip snippet, its throwing error like TOO MUCH RECURSION
I am writing a code generation tool that frequently will have lines like StringBuilder
We have an older C++ tool that generates some python code automatically. I tried
I have a folder with many source code files. I would like to find
I have a very annoying bug, code generation tool has generated like 20,000 lines
Is there a tool that calculates various LOC statistics? It would have to support
I have a tool that I want to install on my main development box
I have a tool strip which contains a ToolStripDropDownButton. As an alternative access method,
We have a tool that generates source files, and each generated file has several

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.