Skip to content
Newer
Older
100644 83 lines (67 sloc) 2.72 KB
9a692fc @Baughn Remember to include ghc-core.el
Baughn authored
1 ;;; ghc-core.el --- Syntax highlighting module for GHC Core
2
3 ;; Copyright (C) 2010 Johan Tibell
4
5 ;; Author: Johan Tibell <johan.tibell@gmail.com>
6
7 ;; This file is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 3, or (at your option)
10 ;; any later version.
11
12 ;; This file is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to
19 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 ;; Boston, MA 02110-1301, USA.
21
22 ;;; Commentary:
23
24 ;; Purpose:
25 ;;
26 ;; To make it easier to read GHC Core output by providing highlighting
27 ;; and removal of commonly ignored annotations.
28
29 ;;; Code:
30
31 (require 'haskell-mode)
32 (require 'haskell-font-lock)
33
34 (defun ghc-core-clean-region (start end)
35 "Remove commonly ignored annotations and namespace
36 prefixes in the given region."
37 (interactive "r")
38 (save-restriction
39 (narrow-to-region start end)
40 (goto-char (point-min))
41 (while (search-forward-regexp "GHC\.[^\.]*\." nil t)
42 (replace-match "" nil t))
43 (goto-char (point-min))
44 (while (flush-lines "^ *GblId *$" nil))
45 (goto-char (point-min))
46 (while (flush-lines "^ *LclId *$" nil))
47 (goto-char (point-min))
48 (while (flush-lines (concat "^ *\\[\\(?:Arity [0-9]+\\|NoCafRefs\\|"
49 "Str: DmdType\\|Worker \\)"
50 "\\([^]]*\\n?\\).*\\] *$") nil))
51 (goto-char (point-min))
52 (while (search-forward "Main." nil t) (replace-match "" nil t))))
53
54 (defun ghc-core-clean-buffer ()
55 "Remove commonly ignored annotations and namespace
56 prefixes in the current buffer."
57 (interactive)
58 (ghc-core-clean-region (point-min) (point-max)))
59
60 ;;;###autoload
61 (defun ghc-core-create-core ()
62 "Compiled and load the current buffer as tidy core"
63 (interactive)
64 (save-buffer)
65 (let ((core-buffer (generate-new-buffer "ghc-core"))
66 (neh (lambda () (kill-buffer core-buffer))))
67 (add-hook 'next-error-hook neh)
68 (call-process "ghc" nil core-buffer nil "-c" "-ddump-simpl" "-O2" (buffer-file-name))
69 (display-buffer core-buffer)
70 (with-current-buffer core-buffer
71 (ghc-core-mode))
72 (remove-hook 'next-error-hook neh)))
73
74 ;;;###autoload
75 (add-to-list 'auto-mode-alist '("\\.hcr\\'" . ghc-core-mode))
76
77 ;;;###autoload
78 (define-derived-mode ghc-core-mode haskell-mode "GHC-Core"
79 "Major mode for GHC Core files.")
80
81 (provide 'ghc-core)
82 ;;; ghc-core.el ends here
Something went wrong with that request. Please try again.