commit | author | age
|
5cb5f7
|
1 |
;;; smartparens-haskell.el --- Additional configuration for Haskell based modes. -*- lexical-binding: t; -*- |
C |
2 |
|
|
3 |
;; Copyright (C) 2015 Michael Xavier |
|
4 |
|
|
5 |
;; Author: Michael Xavier <michael@michaelxavier.net> |
|
6 |
;; Maintainer: Michael Xavier <michael@michaelxavier.net> |
|
7 |
;; Created: 29 Apr 2016 |
|
8 |
;; Keywords: abbrev convenience editing |
|
9 |
;; URL: https://github.com/Fuco1/smartparens |
|
10 |
|
|
11 |
;; This file is not part of GNU Emacs. |
|
12 |
|
|
13 |
;;; License: |
|
14 |
|
|
15 |
;; This file is part of Smartparens. |
|
16 |
|
|
17 |
;; Smartparens is free software; you can redistribute it and/or modify |
|
18 |
;; it under the terms of the GNU General Public License as published by |
|
19 |
;; the Free Software Foundation, either version 3 of the License, or |
|
20 |
;; (at your option) any later version. |
|
21 |
|
|
22 |
;; Smartparens 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 Smartparens. If not, see <http://www.gnu.org/licenses/>. |
|
29 |
|
|
30 |
;;; Commentary: |
|
31 |
|
|
32 |
;; This file provides some additional configuration for Haskell based |
|
33 |
;; modes. To use it, simply add: |
|
34 |
;; |
|
35 |
;; (require 'smartparens-haskell) |
|
36 |
;; |
|
37 |
;; into your configuration. You can use this in conjunction with the |
|
38 |
;; default config or your own configuration. |
|
39 |
|
|
40 |
;; If you have good ideas about what should be added please file an |
|
41 |
;; issue on the github tracker. |
|
42 |
|
|
43 |
;; For more info, see github readme at |
|
44 |
;; https://github.com/Fuco1/smartparens |
|
45 |
|
|
46 |
;;; Code: |
|
47 |
(require 'smartparens) |
|
48 |
|
|
49 |
(defun sp-haskell-skip-apostrophe (_ms mb _me) |
|
50 |
(save-excursion |
|
51 |
;; We test the syntax class because haskell mode overrides |
|
52 |
;; the class for ' on the fly when it run the syntax pass of |
|
53 |
;; font-lock... so that if '' is a valid string (char) it |
|
54 |
;; gets an override via 'syntax-table property. In which |
|
55 |
;; case we just agree with haskell mode and let it be used as |
|
56 |
;; a pair. |
|
57 |
(not (eq (syntax-class (syntax-after mb)) 7)))) |
|
58 |
|
|
59 |
(defun sp-haskell-strict-ignore-apostrophe-after-word (_id action _context) |
|
60 |
"Ignore trailing ' when navigating. |
|
61 |
|
|
62 |
Because ' in haskell is symbol class it gets picked up as part of |
|
63 |
a words such as myFunction', and then strict mode won't allow us |
|
64 |
to delete it. Also show-smartparens-mode incorrectly highlights |
|
65 |
it as missing an opener. |
|
66 |
|
|
67 |
So we ignore that pair when at the end of word." |
|
68 |
(when (eq action 'navigate) |
|
69 |
(sp--looking-back-p (concat "\\(\\sw\\|\\s_\\)'+")))) |
|
70 |
|
|
71 |
(sp-with-modes '(haskell-mode haskell-interactive-mode) |
|
72 |
(sp-local-pair "{-" "-}") |
|
73 |
(sp-local-pair "{-#" "#-}") |
|
74 |
(sp-local-pair "{-@" "@-}") |
|
75 |
(sp-local-pair "'" nil |
|
76 |
:unless '(sp-point-after-word-p |
|
77 |
sp-haskell-strict-ignore-apostrophe-after-word) |
|
78 |
:skip-match 'sp-haskell-skip-apostrophe) |
|
79 |
(sp-local-pair "\\(" nil :actions nil)) |
|
80 |
|
|
81 |
(defun sp--inferior-haskell-mode-backward-bound-fn () |
|
82 |
"Limit the backward search to the prompt if point is on prompt." |
|
83 |
(-when-let (limit (cond ((bound-and-true-p comint-last-prompt) |
|
84 |
(marker-position (cdr comint-last-prompt))) |
|
85 |
((bound-and-true-p comint-last-prompt-overlay) |
|
86 |
(overlay-end comint-last-prompt-overlay)) |
|
87 |
(t nil))) |
|
88 |
(and (> (point) limit) limit))) |
|
89 |
|
|
90 |
(defun sp--inferior-haskell-mode-forward-bound-fn () |
|
91 |
"Limit the forward search to exclude the prompt if point is before prompt." |
|
92 |
(-when-let (limit (cond ((bound-and-true-p comint-last-prompt) |
|
93 |
(marker-position (car comint-last-prompt))) |
|
94 |
((bound-and-true-p comint-last-prompt-overlay) |
|
95 |
(overlay-start comint-last-prompt-overlay)) |
|
96 |
(t nil))) |
|
97 |
(and (< (point) limit) limit))) |
|
98 |
|
|
99 |
(defun sp--setup-inferior-haskell-mode-search-bounds () |
|
100 |
"Setup the search bound. |
|
101 |
|
|
102 |
If the point is after the last prompt, limit the backward search |
|
103 |
only for the propmt. |
|
104 |
|
|
105 |
If the point is before the last prompt, limit the forward search up until the prompt start." |
|
106 |
(setq sp-forward-bound-fn 'sp--inferior-haskell-mode-forward-bound-fn) |
|
107 |
(setq sp-backward-bound-fn 'sp--inferior-haskell-mode-backward-bound-fn)) |
|
108 |
|
|
109 |
(add-hook 'inferior-haskell-mode-hook 'sp--setup-inferior-haskell-mode-search-bounds) |
|
110 |
|
|
111 |
(provide 'smartparens-haskell) |
|
112 |
|
|
113 |
;;; smartparens-haskell.el ends here |