chiark / gitweb /
el/dot-emacs.el: Initial, rather sketchy, Flymake hacking.
authorMark Wooding <mdw@distorted.org.uk>
Thu, 3 Aug 2017 11:03:49 +0000 (12:03 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 3 Aug 2017 11:03:49 +0000 (12:03 +0100)
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.

el/dot-emacs.el

index bd7541a0d1c811febc0db0ea105b5c3bf7cff916..04eb3c048952b96e9a076ae3a3d28776c659a860 100644 (file)
@@ -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.