Mercurial > hg > Members > kokubo > emacs
comparison .emacs.d/haskell-mode/ghc-core.el @ 0:2764b4f45f9f
1st commit
author | Shohei KOKUBO <e105744@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 21 Apr 2014 04:30:59 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:2764b4f45f9f |
---|---|
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 not part of GNU Emacs. | |
8 | |
9 ;; This file is free software; you can redistribute it and/or modify | |
10 ;; it under the terms of the GNU General Public License as published by | |
11 ;; the Free Software Foundation; either version 3, or (at your option) | |
12 ;; any later version. | |
13 | |
14 ;; This file is distributed in the hope that it will be useful, | |
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 ;; GNU General Public License for more details. | |
18 | |
19 ;; You should have received a copy of the GNU General Public License | |
20 ;; along with GNU Emacs; see the file COPYING. If not, write to | |
21 ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
22 ;; Boston, MA 02110-1301, USA. | |
23 | |
24 ;;; Commentary: | |
25 | |
26 ;; Purpose: | |
27 ;; | |
28 ;; To make it easier to read GHC Core output by providing highlighting | |
29 ;; and removal of commonly ignored annotations. | |
30 | |
31 ;;; Code: | |
32 (require 'haskell-mode) | |
33 (require 'haskell-font-lock) | |
34 | |
35 (defgroup ghc-core nil | |
36 "Major mode for viewing pretty printed GHC Core output." | |
37 :link '(custom-manual "(haskell-mode)") | |
38 :group 'haskell | |
39 :prefix "ghc-core-") | |
40 | |
41 (defcustom ghc-core-program | |
42 "ghc" | |
43 "Name of the GHC executable (excluding any arguments)." | |
44 :type 'string | |
45 :group 'ghc-core) | |
46 | |
47 (defcustom ghc-core-program-args | |
48 '("-O2") | |
49 "Additional options to be passed to GHC when generating core output. | |
50 GHC (see variable `ghc-core-program') is invoked with the basic | |
51 command line options \"-ddump-simpl -c <source-file>\" | |
52 followed by the additional options defined here. | |
53 | |
54 The following `-ddump-simpl` options might be of interest: | |
55 | |
56 - `-dsuppress-all' | |
57 - `-dsuppress-uniques' | |
58 - `-dsuppress-idinfo' | |
59 - `-dsuppress-module-prefixes' | |
60 - `-dsuppress-type-signatures' | |
61 - `-dsuppress-type-applications' | |
62 - `-dsuppress-coercions' | |
63 | |
64 See `M-x manual-entry RET ghc' for more details." | |
65 :type '(repeat (string :tag "Argument")) | |
66 :group 'ghc-core) | |
67 | |
68 (define-obsolete-variable-alias 'ghc-core-create-options 'ghc-core-program-args | |
69 "haskell-mode 13.7") | |
70 | |
71 (defun ghc-core-clean-region (start end) | |
72 "Remove commonly ignored annotations and namespace prefixes | |
73 in the region between START and END." | |
74 (interactive "r") | |
75 (save-restriction | |
76 (narrow-to-region start end) | |
77 (goto-char (point-min)) | |
78 (while (search-forward-regexp "GHC\.[^\.]*\." nil t) | |
79 (replace-match "" nil t)) | |
80 (goto-char (point-min)) | |
81 (while (flush-lines "^ *GblId *$" nil)) | |
82 (goto-char (point-min)) | |
83 (while (flush-lines "^ *LclId *$" nil)) | |
84 (goto-char (point-min)) | |
85 (while (flush-lines (concat "^ *\\[\\(?:Arity [0-9]+\\|NoCafRefs\\|" | |
86 "Str: DmdType\\|Worker \\)" | |
87 "\\([^]]*\\n?\\).*\\] *$") nil)) | |
88 (goto-char (point-min)) | |
89 (while (search-forward "Main." nil t) (replace-match "" nil t)))) | |
90 | |
91 (defun ghc-core-clean-buffer () | |
92 "Remove commonly ignored annotations and namespace prefixes | |
93 in the current buffer." | |
94 (interactive) | |
95 (ghc-core-clean-region (point-min) (point-max))) | |
96 | |
97 ;;;###autoload | |
98 (defun ghc-core-create-core () | |
99 "Compile and load the current buffer as tidy core." | |
100 (interactive) | |
101 (save-buffer) | |
102 (let* ((core-buffer (generate-new-buffer "ghc-core")) | |
103 (neh (lambda () (kill-buffer core-buffer)))) | |
104 (add-hook 'next-error-hook neh) | |
105 (apply #'call-process ghc-core-program nil core-buffer nil | |
106 "-ddump-simpl" "-c" (buffer-file-name) ghc-core-program-args) | |
107 (display-buffer core-buffer) | |
108 (with-current-buffer core-buffer | |
109 (ghc-core-mode)) | |
110 (remove-hook 'next-error-hook neh))) | |
111 | |
112 ;;;###autoload | |
113 (add-to-list 'auto-mode-alist '("\\.hcr\\'" . ghc-core-mode)) | |
114 (add-to-list 'auto-mode-alist '("\\.dump-simpl\\'" . ghc-core-mode)) | |
115 | |
116 ;;;###autoload | |
117 (define-derived-mode ghc-core-mode haskell-mode "GHC-Core" | |
118 "Major mode for GHC Core files.") | |
119 | |
120 (provide 'ghc-core) | |
121 ;;; ghc-core.el ends here |