From: Mark Wooding Date: Thu, 3 Aug 2017 11:03:49 +0000 (+0100) Subject: el/dot-emacs.el: Initial, rather sketchy, Flymake hacking. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/50d3dd032afd25cc6a777984d254e77a3a28371c?ds=inline el/dot-emacs.el: Initial, rather sketchy, Flymake hacking. Flymake seems useful, but its defaults are woeful. See if we can kick it into shape without having to rewrite too much of it. Currently there's C support, which seems to work; C header support, which isn't even slightly written; and Perl copied from upstream. --- diff --git a/el/dot-emacs.el b/el/dot-emacs.el index bd7541a..04eb3c0 100644 --- a/el/dot-emacs.el +++ b/el/dot-emacs.el @@ -567,6 +567,55 @@ (defun mdw-compile (command &optional directory comint) (let ((default-directory (or directory default-directory))) (compile command comint))) +;; Flymake support. + +(defun mdw-find-build-dir (build-file) + (catch 'found + (let* ((src-dir (file-name-as-directory (expand-file-name "."))) + (dir src-dir)) + (loop + (when (file-exists-p (concat dir build-file)) + (throw 'found dir)) + (let ((sub (expand-file-name (file-relative-name src-dir dir) + (concat dir "build/")))) + (catch 'give-up + (loop + (when (file-exists-p (concat sub build-file)) + (throw 'found sub)) + (when (string= sub dir) (throw 'give-up nil)) + (setq sub (file-name-directory (directory-file-name sub)))))) + (when (string= dir + (setq dir (file-name-directory + (directory-file-name dir)))) + (throw 'found nil)))))) + +(defun mdw-flymake-make-init () + (let ((build-dir (mdw-find-build-dir "Makefile"))) + (and build-dir + (let ((tmp-src (flymake-init-create-temp-buffer-copy + #'flymake-create-temp-inplace))) + (flymake-get-syntax-check-program-args + tmp-src build-dir t t + #'flymake-get-make-cmdline))))) + +(setq flymake-allowed-file-name-masks + '(("\\.\\(?:c\\|C\\|cc\\|cpp\\|cxx\\|c\\+\\+\\)\\'" + mdw-flymake-make-init) + ("\\.\\(?:h\\|H\\|hh\\|hpp\\|hxx\\|h\\+\\+\\)\\'" + mdw-flymake-master-make-init) + ("\\.p[lm]" flymake-perl-init))) + +(setq flymake-mode-map + (let ((map (if (boundp 'flymake-mode-map) + flymake-mode-map + (make-sparse-keymap)))) + (define-key map [?\C-c ?\C-f ?\C-p] 'flymake-goto-prev-error) + (define-key map [?\C-c ?\C-f ?\C-n] 'flymake-goto-next-error) + (define-key map [?\C-c ?\C-f ?\C-c] 'flymake-compile) + (define-key map [?\C-c ?\C-f ?\C-k] 'flymake-stop-all-syntax-checks) + (define-key map [?\C-c ?\C-f ?\C-e] 'flymake-popup-current-error-menu) + map)) + ;;;-------------------------------------------------------------------------- ;;; Mail and news hacking.