summaryrefslogtreecommitdiff
path: root/.stack-work/install/x86_64-linux/lts-13.22/8.6.5/share/x86_64-linux-ghc-8.6.5/intero-0.1.40/elisp/haskell-simple-indent.el
diff options
context:
space:
mode:
Diffstat (limited to '.stack-work/install/x86_64-linux/lts-13.22/8.6.5/share/x86_64-linux-ghc-8.6.5/intero-0.1.40/elisp/haskell-simple-indent.el')
-rw-r--r--.stack-work/install/x86_64-linux/lts-13.22/8.6.5/share/x86_64-linux-ghc-8.6.5/intero-0.1.40/elisp/haskell-simple-indent.el273
1 files changed, 0 insertions, 273 deletions
diff --git a/.stack-work/install/x86_64-linux/lts-13.22/8.6.5/share/x86_64-linux-ghc-8.6.5/intero-0.1.40/elisp/haskell-simple-indent.el b/.stack-work/install/x86_64-linux/lts-13.22/8.6.5/share/x86_64-linux-ghc-8.6.5/intero-0.1.40/elisp/haskell-simple-indent.el
deleted file mode 100644
index 1d43d23..0000000
--- a/.stack-work/install/x86_64-linux/lts-13.22/8.6.5/share/x86_64-linux-ghc-8.6.5/intero-0.1.40/elisp/haskell-simple-indent.el
+++ /dev/null
@@ -1,273 +0,0 @@
1;;; haskell-simple-indent.el --- Simple indentation module for Haskell Mode -*- lexical-binding: t -*-
2
3;; Copyright (C) 1998 Heribert Schuetz, Graeme E Moss
4
5;; Author: Heribert Schuetz <Heribert.Schuetz@informatik.uni-muenchen.de>
6;; Graeme E Moss <gem@cs.york.ac.uk>
7;; Keywords: indentation files Haskell
8
9;; This file is not part of GNU Emacs.
10
11;; This file is free software; you can redistribute it and/or modify
12;; it under the terms of the GNU General Public License as published by
13;; the Free Software Foundation; either version 3, or (at your option)
14;; any later version.
15
16;; This file is distributed in the hope that it will be useful,
17;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19;; GNU General Public License for more details.
20
21;; You should have received a copy of the GNU General Public License
22;; along with this program. If not, see <http://www.gnu.org/licenses/>.
23
24;;; Commentary:
25
26;; Purpose:
27;;
28;; To support simple indentation of Haskell scripts.
29;;
30;;
31;; Installation:
32;;
33;; To bind TAB to the indentation command for all Haskell buffers, add
34;; this to .emacs:
35;;
36;; (add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent)
37;;
38;; Otherwise, call `turn-on-haskell-simple-indent'.
39;;
40;;
41;; Customisation:
42;;
43;; None supported.
44;;
45;;
46;; History:
47;;
48;; If you have any problems or suggestions, after consulting the list
49;; below, email gem@cs.york.ac.uk quoting the version of you are
50;; using, the version of Emacs you are using, and a small example of
51;; the problem or suggestion.
52;;
53;; Version 1.0:
54;; Brought over from Haskell mode v1.1.
55;;
56;; Present Limitations/Future Work (contributions are most welcome!):
57;;
58;; (None so far.)
59
60;;; Code:
61
62;; All functions/variables start with
63;; `(turn-(on/off)-)haskell-simple-indent'.
64
65(require 'haskell-mode)
66
67;;;###autoload
68(defgroup haskell-simple-indent nil
69 "Simple Haskell indentation."
70 :link '(custom-manual "(haskell-mode)Indentation")
71 :group 'haskell
72 :prefix "haskell-simple-indent-")
73
74;; Version.
75(defconst haskell-simple-indent-version "1.2"
76 "`haskell-simple-indent' version number.")
77(defun haskell-simple-indent-version ()
78 "Echo the current version of `haskell-simple-indent' in the minibuffer."
79 (interactive)
80 (message "Using haskell-simple-indent version %s"
81 haskell-simple-indent-version))
82
83;; Partly stolen from `indent-relative' in indent.el:
84(defun haskell-simple-indent ()
85 "Space out to under next visible indent point.
86
87Indent points are positions of non-whitespace following
88whitespace in lines preceeding point. Example:
89
90func arg cx = when (isTrue) $ do
91 print 42
92^ ^ ^ ^ ^ ^ ^ ^ ^ ^
93
94A position is visible if it is to the left of the first
95non-whitespace (indentation) of every nonblank line between the
96position and the current line. If there is no visible indent
97point beyond the current column, position given by
98`indent-next-tab-stop' is used instead."
99 (interactive)
100 (let* ((start-column (or (save-excursion
101 (back-to-indentation)
102 (if (not (eolp))
103 (current-column)))
104 (current-column)))
105 (invisible-from nil) ; `nil' means infinity here
106 (found)
107 (indent))
108 (save-excursion
109 ;; Loop stops if there no more lines above this one or when has
110 ;; found a line starting at first column.
111 (while (and (not found)
112 (or (not invisible-from)
113 (not (zerop invisible-from)))
114 (zerop (forward-line -1)))
115 ;; Ignore empty lines.
116 (if (not (looking-at "[ \t]*\n"))
117 (let ((this-indentation (current-indentation)))
118 ;; Is this line so indented that it cannot have
119 ;; influence on indentation points?
120 (if (or (not invisible-from)
121 (< this-indentation invisible-from))
122 (if (> this-indentation start-column)
123 (setq invisible-from this-indentation)
124 (let ((end (line-end-position)))
125 (move-to-column start-column)
126 ;; Is start-column inside a tab on this line?
127 (if (> (current-column) start-column)
128 (backward-char 1))
129 ;; Skip to the end of non-whitespace.
130 (skip-chars-forward "^ \t" end)
131 ;; Skip over whitespace.
132 (skip-chars-forward " \t" end)
133 ;; Indentation point found if not at the end of
134 ;; line and if not covered by any line below
135 ;; this one. In that case use invisible-from.
136 (setq indent (if (or (= (point) end)
137 (and invisible-from
138 (> (current-column) invisible-from)))
139 invisible-from
140 (current-column)))
141 ;; Signal that solution is found.
142 (setq found t))))))))
143
144
145 (let ((opoint (point-marker)))
146 ;; Indent to the calculated indent or last know invisible-from
147 ;; or use tab-to-tab-stop. Try hard to keep cursor in the same
148 ;; place or move it to the indentation if it was before it. And
149 ;; keep content of the line intact.
150 (setq indent (or indent
151 invisible-from
152 (if (fboundp 'indent-next-tab-stop)
153 (indent-next-tab-stop start-column))
154 (let ((tabs tab-stop-list))
155 (while (and tabs (>= start-column (car tabs)))
156 (setq tabs (cdr tabs)))
157 (if tabs (car tabs)))
158 (* (/ (+ start-column tab-width) tab-width) tab-width)))
159 (indent-line-to indent)
160 (if (> opoint (point))
161 (goto-char opoint))
162 (set-marker opoint nil))))
163
164(defun haskell-simple-indent-backtab ()
165 "Indent backwards. Dual to `haskell-simple-indent'."
166 (interactive)
167 (let ((saved-column (or (save-excursion
168 (back-to-indentation)
169 (if (not (eolp))
170 (current-column)))
171 (current-column)))
172 (i 0)
173 (x 0))
174
175 (save-excursion
176 (back-to-indentation)
177 (delete-region (line-beginning-position) (point)))
178 (while (< (or (save-excursion
179 (back-to-indentation)
180 (if (not (eolp))
181 (current-column)))
182 (current-column)) saved-column)
183 (haskell-simple-indent)
184 (setq i (+ i 1)))
185
186 (save-excursion
187 (back-to-indentation)
188 (delete-region (line-beginning-position) (point)))
189 (while (< x (- i 1))
190 (haskell-simple-indent)
191 (setq x (+ x 1)))))
192
193(defun haskell-simple-indent-newline-same-col ()
194 "Make a newline and go to the same column as the current line."
195 (interactive)
196 (let ((start-end
197 (save-excursion
198 (let* ((start (line-beginning-position))
199 (end (progn (goto-char start)
200 (search-forward-regexp
201 "[^ ]" (line-end-position) t 1))))
202 (when end (cons start (1- end)))))))
203 (if start-end
204 (progn (newline)
205 (insert (buffer-substring-no-properties
206 (car start-end) (cdr start-end))))
207 (newline))))
208
209(defun haskell-simple-indent-newline-indent ()
210 "Make a newline on the current column and indent on step."
211 (interactive)
212 (haskell-simple-indent-newline-same-col)
213 (insert (make-string haskell-indent-spaces ? )))
214
215(defun haskell-simple-indent-comment-indent-function ()
216 "Haskell version of `comment-indent-function'."
217 ;; This is required when filladapt is turned off. Without it, when
218 ;; filladapt is not used, comments which start in column zero
219 ;; cascade one character to the right
220 (save-excursion
221 (beginning-of-line)
222 (let ((eol (line-end-position)))
223 (and comment-start-skip
224 (re-search-forward comment-start-skip eol t)
225 (setq eol (match-beginning 0)))
226 (goto-char eol)
227 (skip-chars-backward " \t")
228 (max comment-column (+ (current-column) (if (bolp) 0 1))))))
229
230;;;###autoload
231(define-minor-mode haskell-simple-indent-mode
232 "Simple Haskell indentation mode that uses simple heuristic.
233In this minor mode, `indent-for-tab-command' (bound to <tab> by
234default) will move the cursor to the next indent point in the
235previous nonblank line, whereas `haskell-simple-indent-backtab'
236\ (bound to <backtab> by default) will move the cursor the
237previous indent point. An indent point is a non-whitespace
238character following whitespace.
239
240Runs `haskell-simple-indent-hook' on activation."
241 :lighter " Ind"
242 :group 'haskell-simple-indent
243 :keymap '(([backtab] . haskell-simple-indent-backtab))
244 (kill-local-variable 'comment-indent-function)
245 (kill-local-variable 'indent-line-function)
246 (when haskell-simple-indent-mode
247 (when (and (bound-and-true-p haskell-indentation-mode)
248 (fboundp 'haskell-indentation-mode))
249 (haskell-indentation-mode 0))
250 (set (make-local-variable 'comment-indent-function) #'haskell-simple-indent-comment-indent-function)
251 (set (make-local-variable 'indent-line-function) 'haskell-simple-indent)
252 (run-hooks 'haskell-simple-indent-hook)))
253
254;; The main functions.
255;;;###autoload
256(defun turn-on-haskell-simple-indent ()
257 "Turn on function `haskell-simple-indent-mode'."
258 (interactive)
259 (haskell-simple-indent-mode))
260(make-obsolete 'turn-on-haskell-simple-indent
261 'haskell-simple-indent-mode
262 "2015-07-23")
263
264(defun turn-off-haskell-simple-indent ()
265 "Turn off function `haskell-simple-indent-mode'."
266 (interactive)
267 (haskell-simple-indent-mode 0))
268
269;; Provide ourselves:
270
271(provide 'haskell-simple-indent)
272
273;;; haskell-simple-indent.el ends here