I updated the code that was supposed to add run to the Makefile . I also added an extension to C:
(defvar cpp-generate-compiler "g++ -g -O2 -std=c++0x") (defun cpp-generate-makefile () (interactive) (let* ((n-buffer (buffer-file-name)) (n-file (file-name-nondirectory n-buffer)) (n-target (file-name-sans-extension n-file)) (n-makefile (concat (file-name-directory n-buffer) "Makefile"))) (if (file-exists-p n-makefile) (when (called-interactively-p 'any) (message "Makefile already exists")) (with-current-buffer (find-file-noselect n-makefile) (insert (concat n-target ": " n-file (format "\n\t%s -o $@ $^" cpp-generate-compiler) "\n\nclean: \n\trm -f " n-target "\n\nrun: " n-target "\n\t ./" n-target "\n\n.PHONY: clean run\n")) (save-buffer))))) (defun cpp-run () (interactive) (save-buffer) (cpp-generate-makefile) (compile "make run")) (defun c-run () (interactive) (let ((cpp-generate-compiler "gcc -g -O2 -std=c99")) (cpp-run))) (add-hook 'c++-mode-hook (lambda() ;; ... (define-key c++-mode-map [f5] 'cpp-run))) (add-hook 'c-mode-hook (lambda() ;; ... (define-key c-mode-map [f5] 'c-run))) (setq compilation-ask-about-save nil) (setq compilation-finish-functions (list (lambda(buffer str) (unless (string= str "finished\n") (push-mark) (next-error)))))
With (setq compilation-ask-about-save nil) there is no longer a save warning ( cpp-run automatically saved).
And I just have to remember that Mg n and Mg p go to the bugs.
Now my process is close to optimal: one key from the source will lead to the fact that there are no errors.
In case of errors there is an additional Mg n . Now, if only there was a compile way to call (push-mark)(next-error) ...
UPD:
Thanks to @ juanleon's suggestion, this is solved using
(setq compilation-finish-functions (list (lambda(buffer str) (unless (string= str "finished\n") (push-mark) (next-error)))))
But for some reason, push-mark does not work properly in this case.
source share