diff options
| author | Simeon Simeonov | 2022-10-12 23:21:07 +0200 |
|---|---|---|
| committer | Simeon Simeonov | 2022-10-12 23:21:07 +0200 |
| commit | 3ba23d3758e06d95b14ed4e89607e258d15ddbf7 (patch) | |
| tree | f41ec9ee69791270c8e75e87d7893ad90dd3189b /.emacs.d/lisp/rust-compile.el | |
| parent | 4efa8ef4d3617973b2883605461ffa514675e5b2 (diff) | |
Add Rust mode and update lua-mode, markdown-mode and yaml-mode
Diffstat (limited to '.emacs.d/lisp/rust-compile.el')
| -rw-r--r-- | .emacs.d/lisp/rust-compile.el | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/.emacs.d/lisp/rust-compile.el b/.emacs.d/lisp/rust-compile.el new file mode 100644 index 0000000..1bb3103 --- /dev/null +++ b/.emacs.d/lisp/rust-compile.el | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | ;;; rust-compile.el --- Compile facilities -*-lexical-binding: t-*- | ||
| 2 | ;;; Commentary: | ||
| 3 | |||
| 4 | ;; This library teaches `compilation-mode' about "rustc" output. | ||
| 5 | |||
| 6 | ;;; Code: | ||
| 7 | |||
| 8 | (require 'compile) | ||
| 9 | |||
| 10 | ;;; _ | ||
| 11 | |||
| 12 | (defvar rustc-compilation-location | ||
| 13 | (let ((file "\\([^\n]+\\)") | ||
| 14 | (start-line "\\([0-9]+\\)") | ||
| 15 | (start-col "\\([0-9]+\\)")) | ||
| 16 | (concat "\\(" file ":" start-line ":" start-col "\\)"))) | ||
| 17 | |||
| 18 | (defvar rustc-compilation-regexps | ||
| 19 | (let ((re (concat "^\\(?:error\\|\\(warning\\)\\|\\(note\\)\\)[^\0]+?--> " | ||
| 20 | rustc-compilation-location))) | ||
| 21 | (cons re '(4 5 6 (1 . 2) 3))) | ||
| 22 | "Specifications for matching errors in rustc invocations. | ||
| 23 | See `compilation-error-regexp-alist' for help on their format.") | ||
| 24 | |||
| 25 | (defvar rustc-colon-compilation-regexps | ||
| 26 | (let ((re (concat "^ *::: " rustc-compilation-location))) | ||
| 27 | (cons re '(2 3 4 0 1))) | ||
| 28 | "Specifications for matching `:::` hints in rustc invocations. | ||
| 29 | See `compilation-error-regexp-alist' for help on their format.") | ||
| 30 | |||
| 31 | (defvar rustc-refs-compilation-regexps | ||
| 32 | (let ((re "^\\([0-9]+\\)[[:space:]]*|")) | ||
| 33 | (cons re '(nil 1 nil 0 1))) | ||
| 34 | "Specifications for matching code references in rustc invocations. | ||
| 35 | See `compilation-error-regexp-alist' for help on their format.") | ||
| 36 | |||
| 37 | ;; Match test run failures and panics during compilation as | ||
| 38 | ;; compilation warnings | ||
| 39 | (defvar cargo-compilation-regexps | ||
| 40 | '("', \\(\\([^:]+\\):\\([0-9]+\\)\\)" | ||
| 41 | 2 3 nil nil 1) | ||
| 42 | "Specifications for matching panics in cargo test invocations. | ||
| 43 | See `compilation-error-regexp-alist' for help on their format.") | ||
| 44 | |||
| 45 | (defun rustc-scroll-down-after-next-error () | ||
| 46 | "In the new style error messages, the regular expression | ||
| 47 | matches on the file name (which appears after `-->`), but the | ||
| 48 | start of the error appears a few lines earlier. This hook runs | ||
| 49 | after `next-error' (\\[next-error]); it simply scrolls down a few lines in | ||
| 50 | the compilation window until the top of the error is visible." | ||
| 51 | (save-selected-window | ||
| 52 | (when (eq major-mode 'rust-mode) | ||
| 53 | (select-window (get-buffer-window next-error-last-buffer 'visible)) | ||
| 54 | (when (save-excursion | ||
| 55 | (beginning-of-line) | ||
| 56 | (looking-at " *-->")) | ||
| 57 | (let ((start-of-error | ||
| 58 | (save-excursion | ||
| 59 | (beginning-of-line) | ||
| 60 | (while (not (looking-at "^[a-z]+:\\|^[a-z]+\\[E[0-9]+\\]:")) | ||
| 61 | (forward-line -1)) | ||
| 62 | (point)))) | ||
| 63 | (set-window-start (selected-window) start-of-error)))))) | ||
| 64 | |||
| 65 | (eval-after-load 'compile | ||
| 66 | '(progn | ||
| 67 | (add-to-list 'compilation-error-regexp-alist-alist | ||
| 68 | (cons 'rustc-refs rustc-refs-compilation-regexps)) | ||
| 69 | (add-to-list 'compilation-error-regexp-alist 'rustc-refs) | ||
| 70 | (add-to-list 'compilation-error-regexp-alist-alist | ||
| 71 | (cons 'rustc rustc-compilation-regexps)) | ||
| 72 | (add-to-list 'compilation-error-regexp-alist 'rustc) | ||
| 73 | (add-to-list 'compilation-error-regexp-alist-alist | ||
| 74 | (cons 'rustc-colon rustc-colon-compilation-regexps)) | ||
| 75 | (add-to-list 'compilation-error-regexp-alist 'rustc-colon) | ||
| 76 | (add-to-list 'compilation-error-regexp-alist-alist | ||
| 77 | (cons 'cargo cargo-compilation-regexps)) | ||
| 78 | (add-to-list 'compilation-error-regexp-alist 'cargo) | ||
| 79 | (add-hook 'next-error-hook #'rustc-scroll-down-after-next-error))) | ||
| 80 | |||
| 81 | ;;; _ | ||
| 82 | (provide 'rust-compile) | ||
| 83 | ;;; rust-compile.el ends here | ||
