all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Gareth Rees <gdr@garethrees.org>
To: 14362@debbugs.gnu.org
Subject: bug#14362: 24.3; Make it possible to modify compilation-find-file
Date: Tue, 7 May 2013 20:19:04 +0100	[thread overview]
Message-ID: <1D196226-AB6A-49B4-A156-83EDFE9C6905@garethrees.org> (raw)

BACKGROUND

I'm working on the Perforce/Emacs integration
<https://github.com/gareth-rees/p4.el>, and I recently added support for
the "p4 grep" command. This command is just like "grep" except that it
searches current or past revisions of files stored on the Perforce
server. Typical output from the command looks like this:

# find occurrences of FIXME in *.c as of 1st January 2013. 
$ p4 grep -e FIXME '*.c@2013/01/01'
//info.ravenbrook.com/project/mps/master/code/eventcnv.c#17:        /* FIXME: This attempted to print the event stats on a row that
//info.ravenbrook.com/project/mps/master/code/mps.c#14:#include "span.c"       /* generic stack probe FIXME: Is this correct? */

The filename on the left of each hit is expressed in Perforce server
format: thus the first hit is for revision number 17 of eventcnv.c.

An Emacs interface to this command is easy to implement, using the
grep function and setting compilation-error-regexp-alist accordingly.
Except for one problem.

If the user runs the p4 grep command via my interface, and then clicks
on one of the hits, I want Emacs to jump to the corresponding line in
that revision of the file. But the filename is given in Perforce
server syntax, and compilation-next-error-function does not know how
to visit that file. There seems to be no way to customize the
behaviour of compilation-find-file.


SUGGESTION

The simplest way to support my use case would be to add a new variable
compilation-find-file-function. If this is non-NIL, then call it
instead of compilation-find-file. Suggested patch against 24.3 below.


WORKAROUND

I've set next-error-function to this function, which overrides
compilation-find-file during the call to
compilation-next-error-function.

(defun p4-grep-next-error-function (n &optional reset)
  "Advance to the next error message and visit the file where the error was.
This is the value of `next-error-function' in P4 Grep buffers."
  (interactive "p")
  (let ((cff (symbol-function 'compilation-find-file)))
    (unwind-protect
        (progn (fset 'compilation-find-file 'p4-grep-find-file)
               (compilation-next-error-function n reset))
      (fset 'compilation-find-file cff))))


PATCH

--- compile.el-24.3	2013-05-07 20:07:58.000000000 +0100
+++ compile.el	2013-05-07 20:15:17.000000000 +0100
@@ -83,6 +83,15 @@
 that value, otherwise it uses the value in the *compilation*
 buffer.  This enables a major-mode to specify its own value.")
 
+(defvar compilation-find-file-function nil
+  "Function to call to visit a file found by `next-error' and
+similar commands. It takes three arguments: MARKER FILENAME
+DIRECTORY, where FILENAME is the name of the file to visit, MARKER
+is the location in the compilation output where the file was
+mentioned, and DIRECTORY is the \"current\" directory. If
+DIRECTORY is relative, it is combined with `default-directory'.
+If DIRECTORY is nil, that means use `default-directory'.")
+
 (defvar compilation-parse-errors-filename-function nil
   "Function to call to post-process filenames while parsing error messages.
 It takes one arg FILENAME which is the name of a file as found
@@ -1972,6 +1981,7 @@
 		   compilation-first-column
 		   compilation-mode-font-lock-keywords
 		   compilation-page-delimiter
+		   compilation-find-file-function
 		   compilation-parse-errors-filename-function
 		   compilation-process-setup-function
 		   compilation-scroll-output
@@ -2370,7 +2380,7 @@
                  ;;            (setq timestamp compilation-buffer-modtime)))
                  )
       (with-current-buffer
-          (compilation-find-file
+          (funcall (or compilation-find-file-function 'compilation-find-file)
            marker
            (caar (compilation--loc->file-struct loc))
            (cadr (car (compilation--loc->file-struct loc))))

-- 
Gareth Rees




             reply	other threads:[~2013-05-07 19:19 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-07 19:19 Gareth Rees [this message]
2013-05-07 19:28 ` bug#14362: 24.3; Make it possible to modify compilation-find-file Eli Zaretskii
2013-05-07 19:38   ` Gareth Rees

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1D196226-AB6A-49B4-A156-83EDFE9C6905@garethrees.org \
    --to=gdr@garethrees.org \
    --cc=14362@debbugs.gnu.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 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.