all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* how to make next-error work on non-grep non-compilation
@ 2011-05-20 11:41 jimka
  2011-05-20 11:47 ` Jim Newton
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: jimka @ 2011-05-20 11:41 UTC (permalink / raw)
  To: help-gnu-emacs

Hi elisp experts,  I have a file which contains grep/compilation style
output.
I'd like to insert that into an emacs buffer and provide the next-
error capability to the user.
I can't seem to make it work, but I feel like I'm almost there.

Any suggestions?  I cannot use the normal compile nor grep interface,
because the information in the mini-buffer is precious and cannot be
changed.  the compile-interface prints something like "compilation
finished" in the mini-buffer.

Here is what I have so far, which displays the file in the perspecitve
buffer, and colorizes it but next-error doesn't do anything useful.

(defun skill-vlint-present (file-name)
  (let ((interesting-output nil)
        (buf (get-buffer-create " vlint")))
    (with-current-buffer buf
      (let ((inhibit-read-only t))
        (erase-buffer)
        (compilation-shell-minor-mode t)
        (setq compilation-auto-jump-to-first-error t)
        (setq next-error-function `(lambda (n &optional reset)
                                     (set-buffer ,buf)
                                     (setq next-error-last-
buffer ,buf)
                                     (compilation-next-error n
reset)))
        (insert "-*- mode: " "grep-mode"
                "; default-directory: " (prin1-to-string default-
directory)
                " -*-\n\n")
        (let ((pos (point-max)))
          (insert-file-contents-literally file-name)
          (setq interesting-output (not (equal pos (point-max)))))

        (font-lock-fontify-buffer)
        (goto-char 0)
        (compilation-compat-parse-errors (point-max))))
    (when interesting-output
      (display-buffer buf))))


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

* Re: how to make next-error work on non-grep non-compilation
  2011-05-20 11:41 how to make next-error work on non-grep non-compilation jimka
@ 2011-05-20 11:47 ` Jim Newton
  2011-05-20 12:53 ` Stefan Monnier
  2011-05-20 15:39 ` Ted Zlatanov
  2 siblings, 0 replies; 10+ messages in thread
From: Jim Newton @ 2011-05-20 11:47 UTC (permalink / raw)
  To: help-gnu-emacs

here is the stacktrace I get from next-error.
It appears there is no 'message text property on the lines, but isn't this what the function compilation-compat-parse-errors does?

Debugger entered--Lisp error: (error "Moved past last grep hit")
  signal(error ("Moved past last grep hit"))
  error("Moved past last %s" "grep hit")
  (or (setq msg (get-text-property pt ...)) (if (setq pt ...) (setq msg ...)) (error (if ... "No more %ss yet" "Moved past last %s") compilation-error))
  (while (> n 0) (setq opt pt) (or (setq pt ...) (if ... ... ...)) (or (setq msg ...) (if ... ...) (error ... compilation-error)) (or (< ... compilation-skip-threshold) (if different-file ...) (if compilation-skip-visited ...) (if compilation-skip-to-next-location ...) (setq n ...)))
  (let (opt) (while (> n 0) (setq opt pt) (or ... ...) (or ... ... ...) (or ... ... ... ... ...)))
  (compilation-loop > next-single-property-change 1- (if (get-buffer-process ...) "No more %ss yet" "Moved past last %s") (point-max))
  (if (>= n 0) (compilation-loop > next-single-property-change 1- (if ... "No more %ss yet" "Moved past last %s") (point-max)) (setq pt (previous-single-property-change pt ... nil ...)) (compilation-loop < previous-single-property-change 1+ "Moved back before first %s" (point-min)))
  (if (zerop n) (unless (or msg ...) (setq pt ...) (unless ... ... ...)) (setq last (nth 2 ...)) (if (>= n 0) (compilation-loop > next-single-property-change 1- ... ...) (setq pt ...) (compilation-loop < previous-single-property-change 1+ "Moved back before first %s" ...)))
  (let* ((msg ...) (loc ...) last) (if (zerop n) (unless ... ... ...) (setq last ...) (if ... ... ... ...)) (goto-char pt) (or msg (error "No %s here" compilation-error)))
  compilation-next-error(1 nil #<marker at 343 in *grep*>)
  compilation-next-error-function(1 nil)
  funcall(compilation-next-error-function 1 nil)
  (save-current-buffer (set-buffer next-error-last-buffer) (funcall next-error-function (prefix-numeric-value arg) reset) (when next-error-recenter (recenter next-error-recenter)) (run-hooks (quote next-error-hook)))
  (with-current-buffer next-error-last-buffer (funcall next-error-function (prefix-numeric-value arg) reset) (when next-error-recenter (recenter next-error-recenter)) (run-hooks (quote next-error-hook)))
  (progn (with-current-buffer next-error-last-buffer (funcall next-error-function ... reset) (when next-error-recenter ...) (run-hooks ...)))
  (if (setq next-error-last-buffer (next-error-find-buffer)) (progn (with-current-buffer next-error-last-buffer ... ... ...)))
  (when (setq next-error-last-buffer (next-error-find-buffer)) (with-current-buffer next-error-last-buffer (funcall next-error-function ... reset) (when next-error-recenter ...) (run-hooks ...)))
  next-error(nil)
  call-interactively(next-error nil nil)


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

* Re: how to make next-error work on non-grep non-compilation
  2011-05-20 11:41 how to make next-error work on non-grep non-compilation jimka
  2011-05-20 11:47 ` Jim Newton
@ 2011-05-20 12:53 ` Stefan Monnier
  2011-05-20 13:48   ` Jim Newton
  2011-05-20 14:06   ` Jim Newton
  2011-05-20 15:39 ` Ted Zlatanov
  2 siblings, 2 replies; 10+ messages in thread
From: Stefan Monnier @ 2011-05-20 12:53 UTC (permalink / raw)
  To: help-gnu-emacs

> Hi elisp experts,  I have a file which contains grep/compilation style
> output.

Does its name have something specific to its format (e.g. it uses
a particular extension)?

> I'd like to insert that into an Emacs buffer and provide the next-
> error capability to the user.

Do you also want it to be editable at the same time?

> I can't seem to make it work, but I feel like I'm almost there.

Maybe you need to set compilation-error-regexp-alist.

> Any suggestions?  I cannot use the normal compile nor grep interface,
> because the information in the mini-buffer is precious and cannot be
> changed.

Your code seems to add a "-*- grep -*-".  If it can be added to the file
rather than to the buffer, it can reduce the needed code even further.

> (defun skill-vlint-present (file-name)
>   (let ((interesting-output nil)
>         (buf (get-buffer-create " vlint")))
>     (with-current-buffer buf
>       (let ((inhibit-read-only t))
>         (erase-buffer)
>         (compilation-shell-minor-mode t)
>         (setq compilation-auto-jump-to-first-error t)
>         (setq next-error-function `(lambda (n &optional reset)
>                                      (set-buffer ,buf)
>                                      (setq next-error-last-
> buffer ,buf)
>                                      (compilation-next-error n
> reset)))
>         (insert "-*- mode: " "grep-mode"
>                 "; default-directory: " (prin1-to-string default-
> directory)
>                 " -*-\n\n")
>         (let ((pos (point-max)))
>           (insert-file-contents-literally file-name)
>           (setq interesting-output (not (equal pos (point-max)))))

>         (font-lock-fontify-buffer)
>         (goto-char 0)
>         (compilation-compat-parse-errors (point-max))))

Calling `compilation-compat-parse-errors' is a bad idea: just remove the
call, it should not make any difference.
I'd recommend you try something simpler based around something like:

 (let ((buf (find-file-noselect file-name)))
   (grep-mode))


-- Stefan


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

* Re: how to make next-error work on non-grep non-compilation
  2011-05-20 12:53 ` Stefan Monnier
@ 2011-05-20 13:48   ` Jim Newton
  2011-05-20 14:11     ` Stefan Monnier
  2011-05-20 14:06   ` Jim Newton
  1 sibling, 1 reply; 10+ messages in thread
From: Jim Newton @ 2011-05-20 13:48 UTC (permalink / raw)
  To: help-gnu-emacs

Hi Stefan, thanks for the suggestion,
but unfortunately the code you gave me coverts the current bugger to grep mode :-(



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

* Re: how to make next-error work on non-grep non-compilation
  2011-05-20 12:53 ` Stefan Monnier
  2011-05-20 13:48   ` Jim Newton
@ 2011-05-20 14:06   ` Jim Newton
  2011-05-20 14:54     ` Jim Newton
  1 sibling, 1 reply; 10+ messages in thread
From: Jim Newton @ 2011-05-20 14:06 UTC (permalink / raw)
  To: help-gnu-emacs



> Does its name have something specific to its format (e.g. it uses
> a particular extension)?

No the file has no particular extension, but i can give it whatever extension it needs if that makes the job easier.

> Do you also want it to be editable at the same time?

It should not be editable.

> Maybe you need to set compilation-error-regexp-alist.

what should I set it to?  I'm trying to make the format of the file already compatible with grep.  I'm assuming that only the grep match lines are important and not the header lines which show the grep command line.  


> Calling `compilation-compat-parse-errors' is a bad idea: just remove the
> call, it should not make any difference.

okeydokey

> I'd recommend you try something simpler based around something like:
>
> (let ((buf (find-file-noselect file-name)))
>   (grep-mode))


Well I would like the buffer to have a more generic name so that if i run my function many times, it reuses the same buffer, thus destroying its old content.  So I'd rather not make the buffer simple a file-visiting buffer.

-jim


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

* Re: how to make next-error work on non-grep non-compilation
  2011-05-20 13:48   ` Jim Newton
@ 2011-05-20 14:11     ` Stefan Monnier
  2011-05-20 14:18       ` Jim Newton
  0 siblings, 1 reply; 10+ messages in thread
From: Stefan Monnier @ 2011-05-20 14:11 UTC (permalink / raw)
  To: help-gnu-emacs

> but unfortunately the code you gave me coverts the current bugger to
> grep mode :-(

Why do you say "unfortunately"?


        Stefan


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

* Re: how to make next-error work on non-grep non-compilation
  2011-05-20 14:11     ` Stefan Monnier
@ 2011-05-20 14:18       ` Jim Newton
  0 siblings, 0 replies; 10+ messages in thread
From: Jim Newton @ 2011-05-20 14:18 UTC (permalink / raw)
  To: help-gnu-emacs

unfortunately because i want it to change the buffer which contains grep style output to grep-mode.  I don't want it to change the mode of my source code buffer.


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

* Re: how to make next-error work on non-grep non-compilation
  2011-05-20 14:06   ` Jim Newton
@ 2011-05-20 14:54     ` Jim Newton
  2011-05-20 16:20       ` Stefan Monnier
  0 siblings, 1 reply; 10+ messages in thread
From: Jim Newton @ 2011-05-20 14:54 UTC (permalink / raw)
  To: help-gnu-emacs

Here is what I settled on.  It seems to work.

(defun skill-vlint-present (file-name)
  (let (size
        (vlint (get-buffer-create "vlint")))
    (with-current-buffer vlint
      (let ((inhibit-read-only t))
        (erase-buffer)
        (insert-file-contents-literally file-name)
        (when (setq size (- (point-max) (point-min)))
          (grep-mode))))
    (when (plusp size)
      (switch-to-buffer-other-window vlint))))


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

* Re: how to make next-error work on non-grep non-compilation
  2011-05-20 11:41 how to make next-error work on non-grep non-compilation jimka
  2011-05-20 11:47 ` Jim Newton
  2011-05-20 12:53 ` Stefan Monnier
@ 2011-05-20 15:39 ` Ted Zlatanov
  2 siblings, 0 replies; 10+ messages in thread
From: Ted Zlatanov @ 2011-05-20 15:39 UTC (permalink / raw)
  To: help-gnu-emacs

On Fri, 20 May 2011 04:41:54 -0700 (PDT) jimka <jimka.velizy@googlemail.com> wrote: 

j> Hi elisp experts, I have a file which contains grep/compilation style
j> output.  I'd like to insert that into an emacs buffer and provide the
j> next- error capability to the user.  I can't seem to make it work,
j> but I feel like I'm almost there.

You can make any buffer support `next-error' by binding
`next-error-function'.  See simple.el:

(defvar next-error-function nil
  "Function to use to find the next error in the current buffer.
The function is called with 2 parameters:
ARG is an integer specifying by how many errors to move.
RESET is a boolean which, if non-nil, says to go back to the beginning
of the errors before moving.
Major modes providing compile-like functionality should set this variable
to indicate to `next-error' that this is a candidate buffer and how
to navigate in it.")
(make-variable-buffer-local 'next-error-function)

The buffer doesn't have to be in any particular mode.

Ted


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

* Re: how to make next-error work on non-grep non-compilation
  2011-05-20 14:54     ` Jim Newton
@ 2011-05-20 16:20       ` Stefan Monnier
  0 siblings, 0 replies; 10+ messages in thread
From: Stefan Monnier @ 2011-05-20 16:20 UTC (permalink / raw)
  To: help-gnu-emacs

> (defun skill-vlint-present (file-name)
>   (let (size
>         (vlint (get-buffer-create "vlint")))
>     (with-current-buffer vlint
>       (let ((inhibit-read-only t))
>         (erase-buffer)
>         (insert-file-contents-literally file-name)
>         (when (setq size (- (point-max) (point-min)))
>           (grep-mode))))
>     (when (plusp size)
>       (switch-to-buffer-other-window vlint))))

Looks much better than the code you sent before.  Note that 0 when
interpreted as a boolean in Elisp is the same as true, so the
"(when (setq size (- (point-max) (point-min)))" will always call the
`grep-mode'.  And you can use (buffer-size) instead of (- (point-max)
(point-min)).  Oh, and I'd use (unless (zerop size)...) since `plusp' is
not standard Elisp but only provided by the CL library.


        Stefan


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

end of thread, other threads:[~2011-05-20 16:20 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-05-20 11:41 how to make next-error work on non-grep non-compilation jimka
2011-05-20 11:47 ` Jim Newton
2011-05-20 12:53 ` Stefan Monnier
2011-05-20 13:48   ` Jim Newton
2011-05-20 14:11     ` Stefan Monnier
2011-05-20 14:18       ` Jim Newton
2011-05-20 14:06   ` Jim Newton
2011-05-20 14:54     ` Jim Newton
2011-05-20 16:20       ` Stefan Monnier
2011-05-20 15:39 ` Ted Zlatanov

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.