I am getting an elisp error that fails at
compilation-next-error function that reads
"Not in a compilation buffer". The elisp function I am writing attempts to automatically jump to the first error within the compilation buffer, then copies the error and writes it to file. Here is the function. I've tried a few things so I've left the tried stuff commented while the function itself will produce the error. Perhaps the error is an obvious one for trained eyes.
(defun write-first-error-to-file() "function copies first error in compilation buffer and writes it to specified file" (interactive) ;;; (select-window (previous-window)) ;;; (switch-to-buffer "*compilation*") ;;; (goto-char (compilation-next-error)) (let ((display-buffer-overriding-action '(display-buffer-same-window))) (compilation-next-error)) ;;; (set-mark-command nil) ;;; (goto-char (compilation-next-error)) ;;; (setq deactivate-mark nil) (kill-ring-save (region-beginning) (region-end)) (write-region (region-beginning) (region-end) "~/copybuffer.txt"))
The function attempts to do the following:
- Declares the function as an interactive form
- Display the compilation buffer and within it go to the next error within compilation buffer. Note, it should be the first error if this is the first command executed. This is where I am getting the aforementioned error.
- Commented, set mark to select region
- Commented, Advance cursor to next compilation-next-error
- Commented, deactivate mark. At this point, the region should have been selected programmatically perhaps??
- Save region to kill-ring
- Write region to file! :D
As you can see there are quite a few issues with this function, perhaps someone can see what I am missing. Thanks for any help anyone can provide.
For reference, the above function produces the following error with strange error output. You can see the "Not in compilation buffer" within the error output.
×H^N%W\204s^A^N&\203þ^A^M× ÌH^K>\204ô^AÈÍÎÏ#\210 ÐH8\211^U=\204s^A^N'\203^Y^BÞ ÌH^K>\204^R^BÈÍÎÏ#\210 ÐH\233\204s^A^N(\2034^B ÌH^K>\204,^BÈÍÎÏ#\210 ÐH^L=\204s^A^N\"T\211^V\"\202u^A) b\210 \206J^BÈá^N$\"+\207" [buffer pt msg cl-struct-compilation--message-tags loc last local-variable-p compilation-locs error "Not in a compila\ tion buffer" ...] 7 ("/usr/share/emacs/24.5/lisp/progmodes/compile.elc" . 69981) "p"], 0