Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 852 lines (757 sloc) 32.972 kb
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
1 ;;; haskell-mode.el --- A Haskell editing mode -*-coding: iso-8859-1;-*-
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
2
be73dda (literate-haskell-mode): Fix up mode line.
monnier authored
3 ;; Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
4 ;; Copyright (C) 1992, 1997-1998 Simon Marlow, Graeme E Moss, and Tommy Thorn
5
59d99e5 updates that were in 1.42 that didn't get committed
simonmar authored
6 ;; Authors: 1992 Simon Marlow
7 ;; 1997-1998 Graeme E Moss <gem@cs.york.ac.uk> and
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
8 ;; Tommy Thorn <thorn@irisa.fr>,
59d99e5 updates that were in 1.42 that didn't get committed
simonmar authored
9 ;; 2001-2002 Reuben Thomas (>=v1.4)
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
10 ;; 2003 Dave Love <fx@gnu.org>
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
11 ;; Keywords: faces files Haskell
ac56db0 (haskell-version): Keep it up-to-date.
monnier authored
12 ;; Version: $Name: $
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
13 ;; URL: http://www.haskell.org/haskell-mode/
14
abda13e (haskell-mode-menu): New menu.
monnier authored
15 ;; This file is not part of GNU Emacs.
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
16
17 ;; This file is free software; you can redistribute it and/or modify
18 ;; it under the terms of the GNU General Public License as published by
30d658f (displayed-month): Remove declaration since it's not used here.
monnier authored
19 ;; the Free Software Foundation; either version 3, or (at your option)
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
20 ;; any later version.
21
22 ;; This file is distributed in the hope that it will be useful,
23 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ;; GNU General Public License for more details.
26
27 ;; You should have received a copy of the GNU General Public License
28 ;; along with GNU Emacs; see the file COPYING. If not, write to the
29 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30 ;; Boston, MA 02111-1307, USA.
31
32
33 ;;; Commentary:
34
35 ;; Purpose:
36 ;;
37 ;; To provide a pleasant mode to browse and edit Haskell files, linking
38 ;; into the following supported modules:
39 ;;
40 ;; `haskell-font-lock', Graeme E Moss and Tommy Thorn
41 ;; Fontifies standard Haskell keywords, symbols, functions, etc.
42 ;;
43 ;; `haskell-decl-scan', Graeme E Moss
44 ;; Scans top-level declarations, and places them in a menu.
45 ;;
46 ;; `haskell-doc', Hans-Wolfgang Loidl
47 ;; Echoes types of functions or syntax of keywords when the cursor is idle.
48 ;;
a482423 @Baughn Updated documentation and autoloads for haskell-indentation
Baughn authored
49 ;; `haskell-indentation', Kristof Bastiaensen
50 ;; Intelligent semi-automatic indentation, mark two.
51 ;;
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
52 ;; `haskell-indent', Guy Lapalme
53 ;; Intelligent semi-automatic indentation.
54 ;;
55 ;; `haskell-simple-indent', Graeme E Moss and Heribert Schuetz
56 ;; Simple indentation.
57 ;;
084629b (haskell-mode-map): Add bindings for the inferior-haskell commands.
monnier authored
58 ;; `inf-haskell'
59 ;; Interaction with an inferior Haskell process.
60 ;; It replaces the previous two modules:
61 ;; `haskell-hugs', Guy Lapalme
62 ;; `haskell-ghci', Chris Web
59d99e5 updates that were in 1.42 that didn't get committed
simonmar authored
63 ;;
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
64 ;;
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
65 ;; This mode supports full Haskell 1.4 including literate scripts.
66 ;; In some versions of (X)Emacs it may only support Latin-1, not Unicode.
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
67 ;;
68 ;; History:
69 ;;
70 ;; This mode is based on an editing mode by Simon Marlow 11/1/92
71 ;; and heavily modified by Graeme E Moss and Tommy Thorn 7/11/98.
72 ;;
73 ;; If you have any problems or suggestions specific to a supported
74 ;; module, consult that module for a list of known bugs, and an
75 ;; author to contact via email. For general problems or suggestions,
76 ;; consult the list below, then email gem@cs.york.ac.uk and
77 ;; thorn@irisa.fr quoting the version of the mode you are using, the
ac6feec Set things up so that mode-hook functions are not
monnier authored
78 ;; version of Emacs you are using, and a small example of the problem
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
79 ;; or suggestion.
80 ;;
a482423 @Baughn Updated documentation and autoloads for haskell-indentation
Baughn authored
81 ;; Version 1.5
82 ;; Added autoload for haskell-indentation
83 ;;
3a44527 Add note about version 1.43
simonmar authored
84 ;; Version 1.43:
85 ;; Various tweaks to doc strings and customization support from
a542c63 Patches from Ville Skytt? <scop@xemacs.org>, the XEmacs maintainer of
simonmar authored
86 ;; Ville Skyttä <scop@xemacs.org>.
3a44527 Add note about version 1.43
simonmar authored
87 ;;
59d99e5 updates that were in 1.42 that didn't get committed
simonmar authored
88 ;; Version 1.42:
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
89 ;; Added autoload for GHCi inferior mode (thanks to Scott
59d99e5 updates that were in 1.42 that didn't get committed
simonmar authored
90 ;; Williams for the bug report and fix).
91 ;;
92 ;; Version 1.41:
93 ;; Improved packaging, and made a couple more variables
ba6faa1 Update history and version number
rrt authored
94 ;; interactively settable.
95 ;;
96 ;; Version 1.4:
59d99e5 updates that were in 1.42 that didn't get committed
simonmar authored
97 ;; Added GHCi mode from Chris Webb, and tidied up a little.
ba6faa1 Update history and version number
rrt authored
98 ;;
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
99 ;; Version 1.3:
100 ;; The literate or non-literate style of a buffer is now indicated
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
101 ;; by just the variable haskell-literate: nil, `bird', or `tex'.
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
102 ;; For literate buffers with ambiguous style, the value of
103 ;; haskell-literate-default is used.
104 ;;
105 ;; Version 1.2:
106 ;; Separated off font locking, declaration scanning and simple
107 ;; indentation, and made them separate modules. Modules can be
108 ;; added easily now. Support for modules haskell-doc,
109 ;; haskell-indent, and haskell-hugs. Literate and non-literate
110 ;; modes integrated into one mode, and literate buffer indicated by
111 ;; value of haskell-literate(-bird-style).
112 ;;
113 ;; Version 1.1:
114 ;; Added support for declaration scanning under XEmacs via
115 ;; func-menu. Moved operators to level two fontification.
116 ;;
117 ;; Version 1.0:
118 ;; Added a nice indention support from Heribert Schuetz
119 ;; <Heribert.Schuetz@informatik.uni-muenchen.de>:
120 ;;
121 ;; I have just hacked an Emacs Lisp function which you might prefer
122 ;; to `indent-relative' in haskell-mode.el. See below. It is not
123 ;; really Haskell-specific because it does not take into account
124 ;; keywords like `do', `of', and `let' (where the layout rule
125 ;; applies), but I already find it useful.
126 ;;
127 ;; Cleaned up the imenu support. Added support for literate scripts.
128 ;;
129 ;; Version 0.103 [HWL]:
130 ;; From Hans Wolfgang Loidl <hwloidl@dcs.gla.ac.uk>:
131 ;;
132 ;; I (HWL) added imenu support by copying the appropriate functions
133 ;; from hugs-mode. A menu-bar item "Declarations" is now added in
134 ;; haskell mode. The new code, however, needs some clean-up.
135 ;;
136 ;; Version 0.102:
137 ;;
138 ;; Moved C-c C-c key binding to comment-region. Leave M-g M-g to do
139 ;; the work. comment-start-skip is changed to comply with comment-start.
140 ;;
141 ;; Version 0.101:
142 ;;
143 ;; Altered indent-line-function to indent-relative.
144 ;;
145 ;; Version 0.100:
146 ;;
147 ;; First official release.
148
149 ;; Present Limitations/Future Work (contributions are most welcome!):
150 ;;
151 ;; . Would like RET in Bird-style literate mode to add a ">" at the
152 ;; start of a line when previous line starts with ">". Or would
153 ;; "> " be better?
154 ;;
e98b0d8 green-card => greencard
panne authored
155 ;; . Support for GreenCard?
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
156 ;;
157
ac6feec Set things up so that mode-hook functions are not
monnier authored
158 ;;; Code:
159
160 (eval-when-compile (require 'cl))
161
162 ;; All functions/variables start with `(literate-)haskell-'.
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
163
164 ;; Version of mode.
ac56db0 (haskell-version): Keep it up-to-date.
monnier authored
165 (defconst haskell-version "$Name: $"
eb13e33 Tweaks to the doc strings and support for customization, from
simonmar authored
166 "`haskell-mode' version number.")
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
167 (defun haskell-version ()
eb13e33 Tweaks to the doc strings and support for customization, from
simonmar authored
168 "Echo the current version of `haskell-mode' in the minibuffer."
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
169 (interactive)
170 (message "Using haskell-mode version %s" haskell-version))
171
eb13e33 Tweaks to the doc strings and support for customization, from
simonmar authored
172 (defgroup haskell nil
173 "Major mode for editing Haskell programs."
174 :group 'languages
175 :prefix "haskell-")
176
02ac722 @Baughn Make sure the load-path is set right
Baughn authored
177 ;; Set load-path
178 ;;;###autoload
179 (add-to-list 'load-path
296a216 @chrisdone Code indentation fix.
chrisdone authored
180 (or (file-name-directory load-file-name) (car load-path)))
02ac722 @Baughn Make sure the load-path is set right
Baughn authored
181
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
182 ;; Set up autoloads for the modules we supply
183 (autoload 'turn-on-haskell-decl-scan "haskell-decl-scan"
184 "Turn on Haskell declaration scanning." t)
185 (autoload 'turn-on-haskell-doc-mode "haskell-doc"
186 "Turn on Haskell Doc minor mode." t)
a482423 @Baughn Updated documentation and autoloads for haskell-indentation
Baughn authored
187 (autoload 'turn-on-haskell-indentation "haskell-indentation"
188 "Turn on advanced Haskell indentation." t)
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
189 (autoload 'turn-on-haskell-indent "haskell-indent"
190 "Turn on Haskell indentation." t)
191 (autoload 'turn-on-haskell-simple-indent "haskell-simple-indent"
192 "Turn on simple Haskell indentation." t)
193
ac6feec Set things up so that mode-hook functions are not
monnier authored
194 ;; Functionality provided in other files.
195 (autoload 'haskell-ds-create-imenu-index "haskell-decl-scan")
196 (autoload 'haskell-font-lock-choose-keywords "haskell-font-lock")
197 (autoload 'haskell-doc-current-info "haskell-doc")
198
199 ;; Obsolete functions.
200 (defun turn-on-haskell-font-lock ()
201 (turn-on-font-lock)
202 (message "turn-on-haskell-font-lock is obsolete. Use turn-on-font-lock instead."))
ce945dc (turn-on-haskell-hugs, turn-on-haskell-ghci):
monnier authored
203 (defun turn-on-haskell-hugs () (message "haskell-hugs is obsolete."))
204 (defun turn-on-haskell-ghci () (message "haskell-ghci is obsolete."))
084629b (haskell-mode-map): Add bindings for the inferior-haskell commands.
monnier authored
205
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
206
207 ;; Are we looking at a literate script?
208 (defvar haskell-literate nil
209 "*If not nil, the current buffer contains a literate Haskell script.
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
210 Possible values are: `bird' and `tex', for Bird-style and LaTeX-style
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
211 literate scripts respectively. Set by `haskell-mode' and
2b067d9 @loveshack Comment/doc/message fixes.
loveshack authored
212 `literate-haskell-mode'. For an ambiguous literate buffer -- i.e. does
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
213 not contain either \"\\begin{code}\" or \"\\end{code}\" on a line on
214 its own, nor does it contain \">\" at the start of a line -- the value
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
215 of `haskell-literate-default' is used.")
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
216 (make-variable-buffer-local 'haskell-literate)
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
217 (put 'haskell-literate 'safe-local-variable 'symbolp)
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
218 ;; Default literate style for ambiguous literate buffers.
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
219 (defcustom haskell-literate-default 'bird
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
220 "Default value for `haskell-literate'.
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
221 Used if the style of a literate buffer is ambiguous. This variable should
7293228 (haskell-literate-default): Fix custom type.
monnier authored
222 be set to the preferred literate style."
68daaf2 @loveshack Add missing `:group's to defcustoms.
loveshack authored
223 :group 'haskell
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
224 :type '(choice (const bird) (const tex) (const nil)))
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
225
226 ;; Mode maps.
084629b (haskell-mode-map): Add bindings for the inferior-haskell commands.
monnier authored
227 (defvar haskell-mode-map
846c8b1 (haskell-mode-map): Typo.
monnier authored
228 (let ((map (make-sparse-keymap)))
c77266d @chrisdone Sessions, background process communication and new interactive mode.
chrisdone authored
229 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
230 ;; For inferior haskell mode, use the below bindings
084629b (haskell-mode-map): Add bindings for the inferior-haskell commands.
monnier authored
231 ;; (define-key map [?\M-C-x] 'inferior-haskell-send-defun)
232 ;; (define-key map [?\C-x ?\C-e] 'inferior-haskell-send-last-sexp)
233 ;; (define-key map [?\C-c ?\C-r] 'inferior-haskell-send-region)
7aac27a @apsk Initial support for send declaration'.
apsk authored
234 (define-key map [?\C-x ?\C-d] 'inferior-haskell-send-decl)
084629b (haskell-mode-map): Add bindings for the inferior-haskell commands.
monnier authored
235 (define-key map [?\C-c ?\C-z] 'switch-to-haskell)
236 (define-key map [?\C-c ?\C-l] 'inferior-haskell-load-file)
f818e57 Removed support for :reload (e.g. removed the C-c C-r binding).
monnier authored
237 ;; I think it makes sense to bind inferior-haskell-load-and-run to C-c
2b067d9 @loveshack Comment/doc/message fixes.
loveshack authored
238 ;; C-r, but since it used to be bound to `reload' until June 2007, I'm
f818e57 Removed support for :reload (e.g. removed the C-c C-r binding).
monnier authored
239 ;; going to leave it out for now.
240 ;; (define-key map [?\C-c ?\C-r] 'inferior-haskell-load-and-run)
084629b (haskell-mode-map): Add bindings for the inferior-haskell commands.
monnier authored
241 (define-key map [?\C-c ?\C-b] 'switch-to-haskell)
242 ;; (define-key map [?\C-c ?\C-s] 'inferior-haskell-start-process)
243 ;; That's what M-; is for.
846c8b1 (haskell-mode-map): Typo.
monnier authored
244 ;; (define-key map "\C-c\C-c" 'comment-region)
9e99279 (haskell-ident-at-point): New fun. Copy of haskell-doc-get-current-word...
monnier authored
245 (define-key map (kbd "C-c C-t") 'inferior-haskell-type)
246 (define-key map (kbd "C-c C-i") 'inferior-haskell-info)
247 (define-key map (kbd "C-c M-.") 'inferior-haskell-find-definition)
51876d5 (haskell-mode-map): Add binding to the new inferior-haskell-find-haddock...
monnier authored
248 (define-key map (kbd "C-c C-d") 'inferior-haskell-find-haddock)
7296c2d @loveshack Add `haskell-check' and flymake support.
loveshack authored
249 (define-key map [?\C-c ?\C-v] 'haskell-check)
250
c77266d @chrisdone Sessions, background process communication and new interactive mode.
chrisdone authored
251 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
252 ;; Editing-specific commands
253 (define-key map (kbd "C-c C-.") 'haskell-mode-format-imports)
ce8b8e5 (haskell-mode-map): Fix last change.
monnier authored
254 (define-key map [remap delete-indentation] 'haskell-delete-indentation)
c642d7c @chrisdone Unindent support.
chrisdone authored
255 (define-key map [backtab] 'unindent-for-tab-command)
c77266d @chrisdone Sessions, background process communication and new interactive mode.
chrisdone authored
256
846c8b1 (haskell-mode-map): Typo.
monnier authored
257 map)
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
258 "Keymap used in Haskell mode.")
259
abda13e (haskell-mode-menu): New menu.
monnier authored
260 (easy-menu-define haskell-mode-menu haskell-mode-map
261 "Menu for the Haskell major mode."
262 ;; Suggestions from Pupeno <pupeno@pupeno.com>:
263 ;; - choose the underlying interpreter
264 ;; - look up docs
265 `("Haskell"
266 ["Indent line" indent-according-to-mode]
267 ["Indent region" indent-region mark-active]
268 ["(Un)Comment region" comment-region mark-active]
269 "---"
270 ["Start interpreter" switch-to-haskell]
271 ["Load file" inferior-haskell-load-file]
272 "---"
1da6412 @Baughn New major mode: GHC-core
Baughn authored
273 ["Load tidy core" ghc-core-create-core]
274 "---"
abda13e (haskell-mode-menu): New menu.
monnier authored
275 ,(if (default-boundp 'eldoc-documentation-function)
276 ["Doc mode" eldoc-mode
1cb1626 (haskell-mode-menu): Fix typo.
monnier authored
277 :style toggle :selected (bound-and-true-p eldoc-mode)]
abda13e (haskell-mode-menu): New menu.
monnier authored
278 ["Doc mode" haskell-doc-mode
279 :style toggle :selected (and (boundp 'haskell-doc-mode) haskell-doc-mode)])
280 ["Customize" (customize-group 'haskell)]
281 ))
282
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
283 ;; Syntax table.
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
284 (defvar haskell-mode-syntax-table
285 (let ((table (make-syntax-table)))
286 (modify-syntax-entry ?\ " " table)
287 (modify-syntax-entry ?\t " " table)
288 (modify-syntax-entry ?\" "\"" table)
289 (modify-syntax-entry ?\' "\'" table)
290 (modify-syntax-entry ?_ "w" table)
291 (modify-syntax-entry ?\( "()" table)
292 (modify-syntax-entry ?\) ")(" table)
293 (modify-syntax-entry ?\[ "(]" table)
294 (modify-syntax-entry ?\] ")[" table)
295
296 (cond ((featurep 'xemacs)
297 ;; I don't know whether this is equivalent to the below
298 ;; (modulo nesting). -- fx
ac6feec Set things up so that mode-hook functions are not
monnier authored
299 (modify-syntax-entry ?{ "(}5" table)
300 (modify-syntax-entry ?} "){8" table)
301 (modify-syntax-entry ?- "_ 1267" table))
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
302 (t
ac6feec Set things up so that mode-hook functions are not
monnier authored
303 ;; In Emacs 21, the `n' indicates that they nest.
304 ;; The `b' annotation is actually ignored because it's only
305 ;; meaningful on the second char of a comment-starter, so
306 ;; on Emacs 20 and before we get wrong results. --Stef
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
307 (modify-syntax-entry ?\{ "(}1nb" table)
308 (modify-syntax-entry ?\} "){4nb" table)
ac6feec Set things up so that mode-hook functions are not
monnier authored
309 (modify-syntax-entry ?- "_ 123" table)))
310 (modify-syntax-entry ?\n ">" table)
311
312 (let (i lim)
313 (map-char-table
314 (lambda (k v)
315 (when (equal v '(1))
316 ;; The current Emacs 22 codebase can pass either a char
317 ;; or a char range.
318 (if (consp k)
319 (setq i (car k)
320 lim (cdr k))
2b067d9 @loveshack Comment/doc/message fixes.
loveshack authored
321 (setq i k
ac6feec Set things up so that mode-hook functions are not
monnier authored
322 lim k))
323 (while (<= i lim)
324 (when (> i 127)
325 (modify-syntax-entry i "_" table))
326 (setq i (1+ i)))))
327 (standard-syntax-table)))
328
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
329 (modify-syntax-entry ?\` "$`" table)
330 (modify-syntax-entry ?\\ "\\" table)
dd52afb *** empty log message ***
monnier authored
331 (mapc (lambda (x)
332 (modify-syntax-entry x "_" table))
333 ;; Some of these are actually OK by default.
334 "!#$%&*+./:<=>?@^|~")
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
335 (unless (featurep 'mule)
336 ;; Non-ASCII syntax should be OK, at least in Emacs.
dd52afb *** empty log message ***
monnier authored
337 (mapc (lambda (x)
338 (modify-syntax-entry x "_" table))
339 (concat "¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿"
340 "×÷"))
341 (mapc (lambda (x)
342 (modify-syntax-entry x "w" table))
343 (concat "ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ"
344 "ØÙÚÛÜÝÞß"
345 "àáâãäåæçèéêëìíîïðñòóôõö"
346 "øùúûüýþÿ")))
935c856 Patches from Dave Love <fx@gnu.org>. He says:
simonmar authored
347 table)
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
348 "Syntax table used in Haskell mode.")
349
9e99279 (haskell-ident-at-point): New fun. Copy of haskell-doc-get-current-word...
monnier authored
350 (defun haskell-ident-at-point ()
30d658f (displayed-month): Remove declaration since it's not used here.
monnier authored
351 "Return the identifier under point, or nil if none found.
352 May return a qualified name."
9e99279 (haskell-ident-at-point): New fun. Copy of haskell-doc-get-current-word...
monnier authored
353 (save-excursion
8eaba6c @jwiegley Make haskell-ident-at-point less sensitive to WS
jwiegley authored
354 ;; Skip whitespace if we're on it. That way, if we're at "map ", we'll
355 ;; see the word "map".
356 (if (eq ? (char-syntax (char-after)))
357 (skip-chars-backward " \t"))
30d658f (displayed-month): Remove declaration since it's not used here.
monnier authored
358 (let ((case-fold-search nil))
359 (multiple-value-bind (start end)
360 (if (looking-at "\\s_")
deb2ce5 @chrisdone Use LIST instead of VALUES.
chrisdone authored
361 (list (progn (skip-syntax-backward "_") (point))
362 (progn (skip-syntax-forward "_") (point)))
363 (list
30d658f (displayed-month): Remove declaration since it's not used here.
monnier authored
364 (progn (skip-syntax-backward "w'")
365 (skip-syntax-forward "'") (point))
366 (progn (skip-syntax-forward "w'") (point))))
367 ;; If we're looking at a module ID that qualifies further IDs, add
368 ;; those IDs.
369 (goto-char start)
370 (while (and (looking-at "[[:upper:]]") (eq (char-after end) ?.)
371 ;; It's a module ID that qualifies further IDs.
372 (goto-char (1+ end))
373 (save-excursion
374 (when (not (zerop (skip-syntax-forward
375 (if (looking-at "\\s_") "_" "w'"))))
376 (setq end (point))))))
377 ;; If we're looking at an ID that's itself qualified by previous
378 ;; module IDs, add those too.
379 (goto-char start)
380 (if (eq (char-after) ?.) (forward-char 1)) ;Special case for "."
381 (while (and (eq (char-before) ?.)
382 (progn (forward-char -1)
383 (not (zerop (skip-syntax-backward "w'"))))
384 (skip-syntax-forward "'")
385 (looking-at "[[:upper:]]"))
386 (setq start (point)))
387 ;; This is it.
388 (buffer-substring-no-properties start end)))))
9e99279 (haskell-ident-at-point): New fun. Copy of haskell-doc-get-current-word...
monnier authored
389
cc18412 (haskell-delete-indentation): New command.
monnier authored
390 (defun haskell-delete-indentation (&optional arg)
2b067d9 @loveshack Comment/doc/message fixes.
loveshack authored
391 "Like `delete-indentation' but ignoring Bird-style \">\"."
cc18412 (haskell-delete-indentation): New command.
monnier authored
392 (interactive "*P")
393 (let ((fill-prefix (or fill-prefix (if (eq haskell-literate 'bird) ">"))))
394 (delete-indentation arg)))
395
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
396 ;; Various mode variables.
ac6feec Set things up so that mode-hook functions are not
monnier authored
397
407740a (haskell-vars, haskell-mode-generic): Remove.
monnier authored
398 (defcustom haskell-mode-hook nil
4025275 @chrisdone If no indentation mode selected, show some helpful message.
chrisdone authored
399 "
400 Hook run after entering Haskell mode.
401
402 --------------------------------------------------------------------------------
403
404 CONFIGURING INDENTATION
405
406 Using this you can configure the Haskell indentation mode. There
407 are three major Haskell indentation modes:
408
409 `haskell-indentation', Kristof Bastiaensen
410 Intelligent semi-automatic indentation, mark two. How to enable:
411 (custom-set-variables
412 '(haskell-mode-hook '(turn-on-haskell-indentation)))
413
414 `haskell-indent', Guy Lapalme
415 Intelligent semi-automatic indentation. How to enable:
416 (custom-set-variables
417 '(haskell-mode-hook '(turn-on-haskell-indentation)))
418
419 `haskell-simple-indent', Graeme E Moss and Heribert Schuetz
420 Simple indentation. How to enable:
421 (custom-set-variables
422 '(haskell-mode-hook '(turn-on-haskell-simple-indent)))
423
424 You can either:
425
426 1) Use the code above if you're more Elisp savvy, and put it
427 in your .emacs or similar file (type C-M-x to run each
428 one), or
429
430 2) customize the variable by ``M-x customize-group'' (see the
431 link below), or
432
433 3) some people prefer to add custom hooks like the below:
434
435 (add-hook 'haskell-mode-hook 'turn-on-haskell-indentation)
436
437 In order to test each one after enabling you can re-run M-x
438 haskell-mode in the same buffer.
439
440 Do not select more than one of the three indentation modes.
441
442 --------------------------------------------------------------------------------"
ac6feec Set things up so that mode-hook functions are not
monnier authored
443 :type 'hook
748ee94 @loveshack Various fixes for Emacs 21.
loveshack authored
444 :group 'haskell
445 :options `(turn-on-haskell-indent turn-on-haskell-indentation
296a216 @chrisdone Code indentation fix.
chrisdone authored
446 turn-on-font-lock
447 ,(if (boundp 'eldoc-documentation-function)
448 'turn-on-eldoc-mode
449 'turn-on-haskell-doc-mode) ; Emacs 21
450 ,@(if (fboundp 'capitalized-words-mode)
451 '(capitalized-words-mode))
452 turn-on-simple-indent turn-on-haskell-doc-mode
453 turn-on-haskell-decl-scan imenu-add-menubar-index))
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
454
f649623 (haskell-mode): Fix typo.
monnier authored
455 (defvar eldoc-print-current-symbol-info-function)
456
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
457 ;; The main mode functions
eb13e33 Tweaks to the doc strings and support for customization, from
simonmar authored
458 ;;;###autoload
407740a (haskell-vars, haskell-mode-generic): Remove.
monnier authored
459 (define-derived-mode haskell-mode fundamental-mode "Haskell"
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
460 "Major mode for editing Haskell programs.
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
461 Blank lines separate paragraphs, comments start with `-- '.
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
462 \\<haskell-mode-map>
463 Literate scripts are supported via `literate-haskell-mode'.
464 The variable `haskell-literate' indicates the style of the script in the
465 current buffer. See the documentation on this variable for more details.
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
466
467 Modules can hook in via `haskell-mode-hook'. The following modules
468 are supported with an `autoload' command:
469
470 `haskell-decl-scan', Graeme E Moss
471 Scans top-level declarations, and places them in a menu.
472
473 `haskell-doc', Hans-Wolfgang Loidl
474 Echoes types of functions or syntax of keywords when the cursor is idle.
475
72d395f @Baughn Clarify the documentation, remove the haskell-indent-mode autoload
Baughn authored
476 `haskell-indentation', Kristof Bastiaensen
477 Intelligent semi-automatic indentation Mk2
478
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
479 `haskell-indent', Guy Lapalme
480 Intelligent semi-automatic indentation.
481
482 `haskell-simple-indent', Graeme E Moss and Heribert Schuetz
483 Simple indentation.
484
485 Module X is activated using the command `turn-on-X'. For example,
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
486 `haskell-indent' is activated using `turn-on-haskell-indent'.
487 For more information on a module, see the help for its `X-mode'
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
488 function. Some modules can be deactivated using `turn-off-X'. (Note
489 that `haskell-doc' is irregular in using `turn-(on/off)-haskell-doc-mode'.)
490
491 Use `haskell-version' to find out what version this is.
492
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
493 Invokes `haskell-mode-hook'."
407740a (haskell-vars, haskell-mode-generic): Remove.
monnier authored
494 (set (make-local-variable 'paragraph-start) (concat "^$\\|" page-delimiter))
495 (set (make-local-variable 'paragraph-separate) paragraph-start)
96c8bbf @Baughn Turn off adaptive fill, until it's fixed
Baughn authored
496 (set (make-local-variable 'fill-paragraph-function) 'haskell-fill-paragraph)
497 ;; (set (make-local-variable 'adaptive-fill-function) 'haskell-adaptive-fill)
498 (set (make-local-variable 'adaptive-fill-mode) nil)
407740a (haskell-vars, haskell-mode-generic): Remove.
monnier authored
499 (set (make-local-variable 'comment-start) "-- ")
500 (set (make-local-variable 'comment-padding) 0)
501 (set (make-local-variable 'comment-start-skip) "[-{]-[ \t]*")
502 (set (make-local-variable 'comment-end) "")
503 (set (make-local-variable 'comment-end-skip) "[ \t]*\\(-}\\|\\s>\\)")
46d792f @Baughn Turn off parse-sexp-ignore-comments (?)
Baughn authored
504 (set (make-local-variable 'parse-sexp-ignore-comments) nil)
4025275 @chrisdone If no indentation mode selected, show some helpful message.
chrisdone authored
505 (set (make-local-variable 'indent-line-function) 'haskell-mode-suggest-indent-choice)
407740a (haskell-vars, haskell-mode-generic): Remove.
monnier authored
506 ;; Set things up for eldoc-mode.
abda13e (haskell-mode-menu): New menu.
monnier authored
507 (set (make-local-variable 'eldoc-documentation-function)
407740a (haskell-vars, haskell-mode-generic): Remove.
monnier authored
508 'haskell-doc-current-info)
509 ;; Set things up for imenu.
510 (set (make-local-variable 'imenu-create-index-function)
511 'haskell-ds-create-imenu-index)
512 ;; Set things up for font-lock.
513 (set (make-local-variable 'font-lock-defaults)
514 '(haskell-font-lock-choose-keywords
515 nil nil ((?\' . "w") (?_ . "w")) nil
516 (font-lock-syntactic-keywords
517 . haskell-font-lock-choose-syntactic-keywords)
518 (font-lock-syntactic-face-function
519 . haskell-syntactic-face-function)
520 ;; Get help from font-lock-syntactic-keywords.
521 (parse-sexp-lookup-properties . t)))
522 ;; Haskell's layout rules mean that TABs have to be handled with extra care.
523 ;; The safer option is to avoid TABs. The second best is to make sure
524 ;; TABs stops are 8 chars apart, as mandated by the Haskell Report. --Stef
525 (set (make-local-variable 'indent-tabs-mode) nil)
f649623 (haskell-mode): Fix typo.
monnier authored
526 (set (make-local-variable 'tab-width) 8)
75777f2 @gracjan Added dabbrev defaults: Haskell is case sensitive language and . is a pa...
gracjan authored
527 ;; dynamic abbrev support: recognize Haskell identifiers
528 ;; Haskell is case-sensitive language
529 (set (make-local-variable 'dabbrev-case-fold-search) nil)
530 (set (make-local-variable 'dabbrev-case-distinction) nil)
531 (set (make-local-variable 'dabbrev-case-replace) nil)
532 (set (make-local-variable 'dabbrev-abbrev-char-regexp) "\\sw\\|[.]")
407740a (haskell-vars, haskell-mode-generic): Remove.
monnier authored
533 (setq haskell-literate nil))
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
534
96c8bbf @Baughn Turn off adaptive fill, until it's fixed
Baughn authored
535 (defun haskell-fill-paragraph (justify)
536 (save-excursion
0a79ab8 @gracjan fill-paragraph works somewhat with {- -} style comments
gracjan authored
537 ;; Fill paragraph should only work in comments.
538 ;; The -- comments are handled properly by default
539 ;; The {- -} comments need some extra love.
540 (let* ((syntax-values (syntax-ppss))
541 (comment-num (nth 4 syntax-values)))
542 (cond
543 ((eq t comment-num)
544 ;; standard fill works wonders inside a non-nested comment
545 (fill-comment-paragraph justify))
546
547 ((integerp comment-num)
548 ;; we are in a nested comment. lets narrow to comment content
549 ;; and use plain paragraph fill for that
550 (let* ((comment-start-point (nth 8 syntax-values))
551 (comment-end-point
552 (save-excursion
553 (re-search-forward "-}" (point-max) t comment-num)
554 (point)))
555 (fill-paragraph-handle-comment nil))
556 (save-restriction
557 (narrow-to-region (+ 2 comment-start-point) (- comment-end-point 2))
558 (fill-paragraph justify))))
559 ((eolp)
560 ;; do nothing outside of a comment
561 t)
562 (t
563 ;; go to end of line and try again
564 (end-of-line)
565 (haskell-fill-paragraph justify))))))
566
96c8bbf @Baughn Turn off adaptive fill, until it's fixed
Baughn authored
567
568 ;; (defun haskell-adaptive-fill ()
569 ;; ;; We want to use "-- " as the prefix of "-- |", etc.
570 ;; (let* ((line-end (save-excursion (end-of-line) (point)))
571 ;; (line-start (point)))
572 ;; (save-excursion
573 ;; (unless (in-comment)
574 ;; ;; Try to find the start of a comment. We only fill comments.
575 ;; (search-forward-regexp comment-start-skip line-end t))
576 ;; (when (in-comment)
577 ;; (let ();(prefix-start (point)))
578 ;; (skip-syntax-forward "^w")
579 ;; (make-string (- (point) line-start) ?\s))))))
59580c6 @chrisdone Current dir support and handling errors/warnings/loading messages discre...
chrisdone authored
580
96c8bbf @Baughn Turn off adaptive fill, until it's fixed
Baughn authored
581
582
eb13e33 Tweaks to the doc strings and support for customization, from
simonmar authored
583 ;;;###autoload
407740a (haskell-vars, haskell-mode-generic): Remove.
monnier authored
584 (define-derived-mode literate-haskell-mode haskell-mode "LitHaskell"
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
585 "As `haskell-mode' but for literate scripts."
407740a (haskell-vars, haskell-mode-generic): Remove.
monnier authored
586 (setq haskell-literate
587 (save-excursion
588 (goto-char (point-min))
589 (cond
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
590 ((re-search-forward "^\\\\\\(begin\\|end\\){code}$" nil t) 'tex)
407740a (haskell-vars, haskell-mode-generic): Remove.
monnier authored
591 ((re-search-forward "^>" nil t) 'bird)
c9b3a7e (haskell-literate): Use `tex' rather than `latex'. Declare as safe.
monnier authored
592 (t haskell-literate-default))))
be73dda (literate-haskell-mode): Fix up mode line.
monnier authored
593 (if (eq haskell-literate 'bird)
594 ;; fill-comment-paragraph isn't much use there, and even gets confused
595 ;; by the syntax-table text-properties we add to mark the first char
596 ;; of each line as a comment-starter.
597 (set (make-local-variable 'fill-paragraph-handle-comment) nil))
598 (set (make-local-variable 'mode-line-process)
599 '("/" (:eval (symbol-name haskell-literate)))))
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
600
76f8816 @DanielSchuessler Add interpreter-mode-alist entries (this autolaunches haskell-mode for f...
DanielSchuessler authored
601 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.\\(?:[gh]s\\|hi\\)\\'" . haskell-mode))
602 ;;;###autoload(add-to-list 'auto-mode-alist '("\\.l[gh]s\\'" . literate-haskell-mode))
603 ;;;###autoload(add-to-list 'interpreter-mode-alist '("runghc" . haskell-mode))
604 ;;;###autoload(add-to-list 'interpreter-mode-alist '("runhaskell" . haskell-mode))
eb13e33 Tweaks to the doc strings and support for customization, from
simonmar authored
605
8b93c1d (haskell-hoogle-command, haskell-hoogle): New var and command.
monnier authored
606 (defcustom haskell-hoogle-command
607 (if (executable-find "hoogle") "hoogle")
608 "Name of the command to use to query Hoogle.
609 If nil, use the Hoogle web-site."
68daaf2 @loveshack Add missing `:group's to defcustoms.
loveshack authored
610 :group 'haskell
8b93c1d (haskell-hoogle-command, haskell-hoogle): New var and command.
monnier authored
611 :type '(choice (const :tag "Use Web-site" nil)
612 string))
613
614 ;;;###autoload
33dc17e @Baughn Alias haskell-hayoo and haskell-hoogle, removing haskell-
Baughn authored
615 (defun haskell-hoogle (query)
8b93c1d (haskell-hoogle-command, haskell-hoogle): New var and command.
monnier authored
616 "Do a Hoogle search for QUERY."
617 (interactive
618 (let ((def (haskell-ident-at-point)))
619 (if (and def (symbolp def)) (setq def (symbol-name def)))
620 (list (read-string (if def
621 (format "Hoogle query (default %s): " def)
622 "Hoogle query: ")
623 nil nil def))))
624 (if (null haskell-hoogle-command)
625 (browse-url (format "http://haskell.org/hoogle/?q=%s" query))
49a575a @craigcitro Improve printing of hoogle output.
craigcitro authored
626 (lexical-let ((temp-buffer (if (fboundp 'help-buffer) (help-buffer) "*Help*")))
627 (with-output-to-temp-buffer temp-buffer
628 (with-current-buffer standard-output
629 (let ((hoogle-process
630 (start-process "hoogle" (current-buffer) haskell-hoogle-command query))
631 (scroll-to-top
632 (lambda (process event)
633 (set-window-start (get-buffer-window temp-buffer t) 1))))
634 (set-process-sentinel hoogle-process scroll-to-top)))))))
8b93c1d (haskell-hoogle-command, haskell-hoogle): New var and command.
monnier authored
635
f846b94 @Baughn Patch courtesy of Alex Ott
Baughn authored
636 ;;;###autoload
33dc17e @Baughn Alias haskell-hayoo and haskell-hoogle, removing haskell-
Baughn authored
637 (defalias 'hoogle 'haskell-hoogle)
638
639 ;;;###autoload
640 (defun haskell-hayoo (query)
f846b94 @Baughn Patch courtesy of Alex Ott
Baughn authored
641 "Do a Hayoo search for QUERY."
642 (interactive
643 (let ((def (haskell-ident-at-point)))
644 (if (and def (symbolp def)) (setq def (symbol-name def)))
645 (list (read-string (if def
646 (format "Hayoo query (default %s): " def)
647 "Hayoo query: ")
648 nil nil def))))
649 (browse-url (format "http://holumbus.fh-wedel.de/hayoo/hayoo.html?query=%s" query)))
650
33dc17e @Baughn Alias haskell-hayoo and haskell-hoogle, removing haskell-
Baughn authored
651 ;;;###autoload
652 (defalias 'hayoo 'haskell-hayoo)
7296c2d @loveshack Add `haskell-check' and flymake support.
loveshack authored
653
654 (defcustom haskell-check-command "hlint"
655 "*Command used to check a Haskell file."
7979a4d @loveshack Add :group to haskell-check-command.
loveshack authored
656 :group 'haskell
7296c2d @loveshack Add `haskell-check' and flymake support.
loveshack authored
657 :type '(choice (const "hlint")
658 (const "ghc -fno-code")
659 (string :tag "Other command")))
660
7b88577 @chrisdone Add stylish-haskell support.
chrisdone authored
661 (defcustom haskell-stylish-on-save nil
662 "Whether to run stylish-haskell on the buffer before
663 saving. Needs 'haskell-mode-save-buffer to be bound for C-x C-s."
664 :group 'haskell
665 :type 'boolean)
666
0af28f6 @chrisdone haskell-tags-on-save: BREAKING CHANGE: Read this commit.
chrisdone authored
667 (defcustom haskell-tags-on-save nil
668 "Generate tags via hasktags on save. Needs
669 'haskell-mode-save-buffer to be bound for C-x C-s."
670 :group 'haskell
671 :type 'boolean)
672
7296c2d @loveshack Add `haskell-check' and flymake support.
loveshack authored
673 (defvar haskell-saved-check-command nil
674 "Internal use.")
675
676 ;; Like Python. Should be abstracted, sigh.
677 (defun haskell-check (command)
678 "Check a Haskell file (default current buffer's file).
679 Runs COMMAND, a shell command, as if by `compile'.
680 See `haskell-check-command' for the default."
681 (interactive
682 (list (read-string "Checker command: "
683 (or haskell-saved-check-command
684 (concat haskell-check-command " "
685 (let ((name (buffer-file-name)))
686 (if name
687 (file-name-nondirectory name))))))))
688 (setq haskell-saved-check-command command)
689 (require 'compile)
690 (save-some-buffers (not compilation-ask-about-save) nil)
691 (if (fboundp 'compilation-start)
692 (compilation-start command)
693 (compile-internal command "No more errors")))
694
695 (autoload 'flymake-init-create-temp-buffer-copy "flymake")
696
697 (defun haskell-flymake-init ()
698 "Flymake init function for Haskell.
699 To be added to `flymake-init-create-temp-buffer-copy'."
82099df @leoliu Avoid raising an error in haskell-flymake-init
leoliu authored
700 (let ((checker-elts (and haskell-saved-check-command
701 (split-string haskell-saved-check-command))))
7296c2d @loveshack Add `haskell-check' and flymake support.
loveshack authored
702 (list (car checker-elts)
703 (append (cdr checker-elts)
704 (list (flymake-init-create-temp-buffer-copy
705 'flymake-create-temp-inplace))))))
706
4025275 @chrisdone If no indentation mode selected, show some helpful message.
chrisdone authored
707 (defun haskell-mode-suggest-indent-choice ()
708 "Ran when the user tries to indent in the buffer but no indentation mode has been selected.
709 Brings up the documentation for haskell-mode-hook."
710 (describe-variable 'haskell-mode-hook))
711
c642d7c @chrisdone Unindent support.
chrisdone authored
712 (defvar unindent-line-function nil
713 "Function to unindent the current line.
714 This function will be called with no arguments.")
715
716 (defun unindent-for-tab-command ()
717 "Un-indent the current line according to the mode's unindenting function (if any)."
718 (interactive)
719 (when unindent-line-function
720 (funcall unindent-line-function)))
721
5dbe501 @chrisdone Import formatting utilities.
chrisdone authored
722 (defun haskell-mode-format-imports ()
723 "Format the imports by aligning and sorting them."
724 (interactive)
725 (let ((col (current-column)))
885dd10 @chrisdone Fix sort/align imports.
chrisdone authored
726 (haskell-sort-imports)
727 (haskell-align-imports)
5dbe501 @chrisdone Import formatting utilities.
chrisdone authored
728 (goto-char (+ (line-beginning-position)
729 col))))
730
59580c6 @chrisdone Current dir support and handling errors/warnings/loading messages discre...
chrisdone authored
731 (defun haskell-mode-message-line (str)
732 "Message only one line, multiple lines just disturbs the programmer."
733 (let ((lines (split-string str "\n" t)))
734 (when (and (car lines) (stringp (car lines)))
735 (message "%s"
736 (concat (car lines)
737 (if (and (cdr lines) (stringp (cadr lines)))
738 (format " [ %s .. ]" (haskell-string-take (haskell-trim (cadr lines)) 10))
739 ""))))))
740
0783cca @chrisdone Contextual space key; provides import completion and :info on symbol at ...
chrisdone authored
741 (defun haskell-mode-contextual-space ()
742 "Contextually do clever stuff when hitting space."
743 (interactive)
744 (cond ((save-excursion (forward-word -1)
33fb572 @chrisdone Fix contextual import.
chrisdone authored
745 (looking-at "^import$"))
bd42a37 @chrisdone Make module inserting C-g'able.
chrisdone authored
746 (insert " ")
0783cca @chrisdone Contextual space key; provides import completion and :info on symbol at ...
chrisdone authored
747 (let ((module (ido-completing-read "Module: " (haskell-session-all-modules))))
7db6fab @chrisdone Sort imports after entering a completed import.
chrisdone authored
748 (insert module)
749 (haskell-mode-format-imports)))
c1e3f7d @chrisdone Fix up space info, support for operators.
chrisdone authored
750 ((not (string= "" (save-excursion (forward-char -1) (haskell-ident-at-point))))
751 (let ((ident (save-excursion (forward-char -1) (haskell-ident-at-point))))
0783cca @chrisdone Contextual space key; provides import completion and :info on symbol at ...
chrisdone authored
752 (insert " ")
c1e3f7d @chrisdone Fix up space info, support for operators.
chrisdone authored
753 (haskell-process-do-try-info ident)))
0783cca @chrisdone Contextual space key; provides import completion and :info on symbol at ...
chrisdone authored
754 (t (insert " "))))
755
7b88577 @chrisdone Add stylish-haskell support.
chrisdone authored
756 (defun haskell-mode-save-buffer ()
757 "Save the current buffer."
0af28f6 @chrisdone haskell-tags-on-save: BREAKING CHANGE: Read this commit.
chrisdone authored
758 (interactive)
759 (let ((modified (buffer-modified-p)))
5d2ee74 @chrisdone Maybe support config file.
chrisdone authored
760 (save-buffer)
0af28f6 @chrisdone haskell-tags-on-save: BREAKING CHANGE: Read this commit.
chrisdone authored
761 (when haskell-stylish-on-save
762 (haskell-mode-stylish-buffer))
763 (save-buffer)
764 (when modified
765 (when haskell-tags-on-save
766 (haskell-process-generate-tags)))))
7b88577 @chrisdone Add stylish-haskell support.
chrisdone authored
767
344c0e1 @mstrlu Don't replace buffer when stylish-haskell fails.
mstrlu authored
768 (defun haskell-mode-buffer-apply-command (cmd)
769 "Execute shell command CMD with current buffer as input and
770 replace the whole buffer with the output. If CMD fails the
4bd22d0 @chrisdone Use a temporary buffer for stylish (refs #54).
chrisdone authored
771 buffer remains unchanged."
ccabffc @chrisdone Fix haskell-mode-buffer-apply-command to not mess with the windows.
chrisdone authored
772 (let* ((file (buffer-file-name (current-buffer)))
773 (output (with-temp-buffer
73ef95a @chrisdone Fix checking the haskell-session is bound in stylish-buffer (fixes #66).
chrisdone authored
774 (let ((default-directory (if (and (boundp 'haskell-session)
775 haskell-session)
5d2ee74 @chrisdone Maybe support config file.
chrisdone authored
776 (haskell-session-cabal-dir haskell-session)
777 default-directory)))
778 (call-process cmd
779 file
780 (list t nil)
781 nil))
ccabffc @chrisdone Fix haskell-mode-buffer-apply-command to not mess with the windows.
chrisdone authored
782 (buffer-substring-no-properties (point-min) (point-max)))))
783 (unless (string= "" output)
784 (erase-buffer)
785 (insert output))))
344c0e1 @mstrlu Don't replace buffer when stylish-haskell fails.
mstrlu authored
786
7b88577 @chrisdone Add stylish-haskell support.
chrisdone authored
787 (defun haskell-mode-stylish-buffer ()
788 "Apply stylish-haskell to the current buffer."
789 (interactive)
790 (let ((column (current-column))
791 (line (line-number-at-pos)))
344c0e1 @mstrlu Don't replace buffer when stylish-haskell fails.
mstrlu authored
792 (haskell-mode-buffer-apply-command "stylish-haskell")
7b88577 @chrisdone Add stylish-haskell support.
chrisdone authored
793 (goto-line line)
794 (goto-char (+ column (point)))))
795
eff2b35 @chrisdone Project-specific etags (M-. jump-to-definition) support.
chrisdone authored
796 (defun haskell-mode-tag-find (&optional next-p)
797 "The tag find function, specific for the particular session."
798 (interactive "P")
d28b754 @chrisdone Update the tag table without prompting.
chrisdone authored
799 (let ((tags-file-name (haskell-session-tags-filename (haskell-session)))
6979620 @chrisdone Fix haskell-ident at point for no symbol.
chrisdone authored
800 (tags-revert-without-query t)
801 (ident (haskell-ident-at-point)))
802 (when (not (string= "" (haskell-trim ident)))
803 (cond ((file-exists-p tags-file-name)
804 (find-tag ident next-p))
805 (t (haskell-process-generate-tags ident))))))
eff2b35 @chrisdone Project-specific etags (M-. jump-to-definition) support.
chrisdone authored
806
e959577 @chrisdone Added SCC pragma insert/delete commands.
chrisdone authored
807 ;; From Bryan O'Sullivan's blog:
808 ;; http://www.serpentine.com/blog/2007/10/09/using-emacs-to-insert-scc-annotations-in-haskell-code/
809 (defun haskell-mode-insert-scc-at-point ()
810 "Insert an SCC annotation at point."
811 (interactive)
812 (if (or (looking-at "\\b\\|[ \t]\\|$") (and (not (bolp))
813 (save-excursion
814 (forward-char -1)
815 (looking-at "\\b\\|[ \t]"))))
816 (let ((space-at-point (looking-at "[ \t]")))
817 (unless (and (not (bolp)) (save-excursion
818 (forward-char -1)
819 (looking-at "[ \t]")))
820 (insert " "))
821 (insert "{-# SCC \"\" #-}")
822 (unless space-at-point
823 (insert " "))
824 (forward-char (if space-at-point -5 -6)))
825 (error "Not over an area of whitespace")))
826
827 ;; Also Bryan O'Sullivan's.
828 (defun haskell-mode-kill-scc-at-point ()
829 "Kill the SCC annotation at point."
830 (interactive)
831 (save-excursion
832 (let ((old-point (point))
833 (scc "\\({-#[ \t]*SCC \"[^\"]*\"[ \t]*#-}\\)[ \t]*"))
834 (while (not (or (looking-at scc) (bolp)))
835 (forward-char -1))
836 (if (and (looking-at scc)
837 (<= (match-beginning 1) old-point)
838 (> (match-end 1) old-point))
839 (kill-region (match-beginning 0) (match-end 0))
840 (error "No SCC at point")))))
841
7296c2d @loveshack Add `haskell-check' and flymake support.
loveshack authored
842 (eval-after-load "flymake"
843 '(add-to-list 'flymake-allowed-file-name-masks
844 '("\\.l?hs\\'" haskell-flymake-init)))
845
ac6feec Set things up so that mode-hook functions are not
monnier authored
846 ;; Provide ourselves:
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
847
848 (provide 'haskell-mode)
849
407740a (haskell-vars, haskell-mode-generic): Remove.
monnier authored
850 ;; arch-tag: b2237ec0-ddb0-4c86-9339-52d410264980
b91f455 Add the current version of the Moss/Thorn/Marlow Emacs mode, along with ...
rrt authored
851 ;;; haskell-mode.el ends here
Something went wrong with that request. Please try again.