Klimi's new dotfiles with stow.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.0 KiB

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