From 883bfd9e115aff50686cf34a4e8a5ce575c3251f Mon Sep 17 00:00:00 2001 From: Gracjan Polak Date: Mon, 26 Oct 2015 20:38:36 +0100 Subject: [PATCH] Remove haskell-simple-indent --- Makefile | 1 - doc/haskell-mode.texi | 7 - haskell-mode.el | 3 - haskell-simple-indent.el | 273 --------------------------- tests/haskell-indentation-tests.el | 14 -- tests/haskell-simple-indent-tests.el | 182 ------------------ 6 files changed, 480 deletions(-) delete mode 100644 haskell-simple-indent.el delete mode 100644 tests/haskell-simple-indent-tests.el diff --git a/Makefile b/Makefile index d93d2ed93..f85dca145 100644 --- a/Makefile +++ b/Makefile @@ -69,7 +69,6 @@ ELFILES = \ haskell-process.el \ haskell-repl.el \ haskell-session.el \ - haskell-simple-indent.el \ haskell-sort-imports.el \ haskell-string.el \ haskell-unicode-input-method.el \ diff --git a/doc/haskell-mode.texi b/doc/haskell-mode.texi index c18de4084..924004ff7 100644 --- a/doc/haskell-mode.texi +++ b/doc/haskell-mode.texi @@ -350,12 +350,6 @@ trade-offs: @ftable @code -@item haskell-simple-indent-mode - -A very simple indentation scheme; In this scheme, @key{TAB} will now -move the cursor to the next indent point in the previous non-blank line. -An indent point is a non-whitespace character following whitespace. - @item haskell-indent-mode Intelligent semi-automatic indentation for Haskell's layout rule. The @@ -386,7 +380,6 @@ convenient user interface or by adding @emph{one} of the following three lines to your @file{.emacs} file: @lisp -(add-hook 'haskell-mode-hook 'haskell-simple-indent-mode) (add-hook 'haskell-mode-hook 'haskell-indent-mode) (add-hook 'haskell-mode-hook 'haskell-indentation-mode) @end lisp diff --git a/haskell-mode.el b/haskell-mode.el index 5817335bf..b36416820 100644 --- a/haskell-mode.el +++ b/haskell-mode.el @@ -600,9 +600,6 @@ Indentation modes: `haskell-indent-mode', Guy Lapalme Intelligent semi-automatic indentation. - `haskell-simple-indent-mode', Graeme E Moss and Heribert Schuetz - Simple indentation. - Interaction modes: `interactive-haskell-mode' diff --git a/haskell-simple-indent.el b/haskell-simple-indent.el deleted file mode 100644 index 1d43d23f6..000000000 --- a/haskell-simple-indent.el +++ /dev/null @@ -1,273 +0,0 @@ -;;; haskell-simple-indent.el --- Simple indentation module for Haskell Mode -*- lexical-binding: t -*- - -;; Copyright (C) 1998 Heribert Schuetz, Graeme E Moss - -;; Author: Heribert Schuetz -;; Graeme E Moss -;; Keywords: indentation files Haskell - -;; This file is not part of GNU Emacs. - -;; This file is free software; you can redistribute it and/or modify -;; it under the terms of the GNU General Public License as published by -;; the Free Software Foundation; either version 3, or (at your option) -;; any later version. - -;; This file is distributed in the hope that it will be useful, -;; but WITHOUT ANY WARRANTY; without even the implied warranty of -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -;; GNU General Public License for more details. - -;; You should have received a copy of the GNU General Public License -;; along with this program. If not, see . - -;;; Commentary: - -;; Purpose: -;; -;; To support simple indentation of Haskell scripts. -;; -;; -;; Installation: -;; -;; To bind TAB to the indentation command for all Haskell buffers, add -;; this to .emacs: -;; -;; (add-hook 'haskell-mode-hook 'turn-on-haskell-simple-indent) -;; -;; Otherwise, call `turn-on-haskell-simple-indent'. -;; -;; -;; Customisation: -;; -;; None supported. -;; -;; -;; History: -;; -;; If you have any problems or suggestions, after consulting the list -;; below, email gem@cs.york.ac.uk quoting the version of you are -;; using, the version of Emacs you are using, and a small example of -;; the problem or suggestion. -;; -;; Version 1.0: -;; Brought over from Haskell mode v1.1. -;; -;; Present Limitations/Future Work (contributions are most welcome!): -;; -;; (None so far.) - -;;; Code: - -;; All functions/variables start with -;; `(turn-(on/off)-)haskell-simple-indent'. - -(require 'haskell-mode) - -;;;###autoload -(defgroup haskell-simple-indent nil - "Simple Haskell indentation." - :link '(custom-manual "(haskell-mode)Indentation") - :group 'haskell - :prefix "haskell-simple-indent-") - -;; Version. -(defconst haskell-simple-indent-version "1.2" - "`haskell-simple-indent' version number.") -(defun haskell-simple-indent-version () - "Echo the current version of `haskell-simple-indent' in the minibuffer." - (interactive) - (message "Using haskell-simple-indent version %s" - haskell-simple-indent-version)) - -;; Partly stolen from `indent-relative' in indent.el: -(defun haskell-simple-indent () - "Space out to under next visible indent point. - -Indent points are positions of non-whitespace following -whitespace in lines preceeding point. Example: - -func arg cx = when (isTrue) $ do - print 42 -^ ^ ^ ^ ^ ^ ^ ^ ^ ^ - -A position is visible if it is to the left of the first -non-whitespace (indentation) of every nonblank line between the -position and the current line. If there is no visible indent -point beyond the current column, position given by -`indent-next-tab-stop' is used instead." - (interactive) - (let* ((start-column (or (save-excursion - (back-to-indentation) - (if (not (eolp)) - (current-column))) - (current-column))) - (invisible-from nil) ; `nil' means infinity here - (found) - (indent)) - (save-excursion - ;; Loop stops if there no more lines above this one or when has - ;; found a line starting at first column. - (while (and (not found) - (or (not invisible-from) - (not (zerop invisible-from))) - (zerop (forward-line -1))) - ;; Ignore empty lines. - (if (not (looking-at "[ \t]*\n")) - (let ((this-indentation (current-indentation))) - ;; Is this line so indented that it cannot have - ;; influence on indentation points? - (if (or (not invisible-from) - (< this-indentation invisible-from)) - (if (> this-indentation start-column) - (setq invisible-from this-indentation) - (let ((end (line-end-position))) - (move-to-column start-column) - ;; Is start-column inside a tab on this line? - (if (> (current-column) start-column) - (backward-char 1)) - ;; Skip to the end of non-whitespace. - (skip-chars-forward "^ \t" end) - ;; Skip over whitespace. - (skip-chars-forward " \t" end) - ;; Indentation point found if not at the end of - ;; line and if not covered by any line below - ;; this one. In that case use invisible-from. - (setq indent (if (or (= (point) end) - (and invisible-from - (> (current-column) invisible-from))) - invisible-from - (current-column))) - ;; Signal that solution is found. - (setq found t)))))))) - - - (let ((opoint (point-marker))) - ;; Indent to the calculated indent or last know invisible-from - ;; or use tab-to-tab-stop. Try hard to keep cursor in the same - ;; place or move it to the indentation if it was before it. And - ;; keep content of the line intact. - (setq indent (or indent - invisible-from - (if (fboundp 'indent-next-tab-stop) - (indent-next-tab-stop start-column)) - (let ((tabs tab-stop-list)) - (while (and tabs (>= start-column (car tabs))) - (setq tabs (cdr tabs))) - (if tabs (car tabs))) - (* (/ (+ start-column tab-width) tab-width) tab-width))) - (indent-line-to indent) - (if (> opoint (point)) - (goto-char opoint)) - (set-marker opoint nil)))) - -(defun haskell-simple-indent-backtab () - "Indent backwards. Dual to `haskell-simple-indent'." - (interactive) - (let ((saved-column (or (save-excursion - (back-to-indentation) - (if (not (eolp)) - (current-column))) - (current-column))) - (i 0) - (x 0)) - - (save-excursion - (back-to-indentation) - (delete-region (line-beginning-position) (point))) - (while (< (or (save-excursion - (back-to-indentation) - (if (not (eolp)) - (current-column))) - (current-column)) saved-column) - (haskell-simple-indent) - (setq i (+ i 1))) - - (save-excursion - (back-to-indentation) - (delete-region (line-beginning-position) (point))) - (while (< x (- i 1)) - (haskell-simple-indent) - (setq x (+ x 1))))) - -(defun haskell-simple-indent-newline-same-col () - "Make a newline and go to the same column as the current line." - (interactive) - (let ((start-end - (save-excursion - (let* ((start (line-beginning-position)) - (end (progn (goto-char start) - (search-forward-regexp - "[^ ]" (line-end-position) t 1)))) - (when end (cons start (1- end))))))) - (if start-end - (progn (newline) - (insert (buffer-substring-no-properties - (car start-end) (cdr start-end)))) - (newline)))) - -(defun haskell-simple-indent-newline-indent () - "Make a newline on the current column and indent on step." - (interactive) - (haskell-simple-indent-newline-same-col) - (insert (make-string haskell-indent-spaces ? ))) - -(defun haskell-simple-indent-comment-indent-function () - "Haskell version of `comment-indent-function'." - ;; This is required when filladapt is turned off. Without it, when - ;; filladapt is not used, comments which start in column zero - ;; cascade one character to the right - (save-excursion - (beginning-of-line) - (let ((eol (line-end-position))) - (and comment-start-skip - (re-search-forward comment-start-skip eol t) - (setq eol (match-beginning 0))) - (goto-char eol) - (skip-chars-backward " \t") - (max comment-column (+ (current-column) (if (bolp) 0 1)))))) - -;;;###autoload -(define-minor-mode haskell-simple-indent-mode - "Simple Haskell indentation mode that uses simple heuristic. -In this minor mode, `indent-for-tab-command' (bound to by -default) will move the cursor to the next indent point in the -previous nonblank line, whereas `haskell-simple-indent-backtab' -\ (bound to by default) will move the cursor the -previous indent point. An indent point is a non-whitespace -character following whitespace. - -Runs `haskell-simple-indent-hook' on activation." - :lighter " Ind" - :group 'haskell-simple-indent - :keymap '(([backtab] . haskell-simple-indent-backtab)) - (kill-local-variable 'comment-indent-function) - (kill-local-variable 'indent-line-function) - (when haskell-simple-indent-mode - (when (and (bound-and-true-p haskell-indentation-mode) - (fboundp 'haskell-indentation-mode)) - (haskell-indentation-mode 0)) - (set (make-local-variable 'comment-indent-function) #'haskell-simple-indent-comment-indent-function) - (set (make-local-variable 'indent-line-function) 'haskell-simple-indent) - (run-hooks 'haskell-simple-indent-hook))) - -;; The main functions. -;;;###autoload -(defun turn-on-haskell-simple-indent () - "Turn on function `haskell-simple-indent-mode'." - (interactive) - (haskell-simple-indent-mode)) -(make-obsolete 'turn-on-haskell-simple-indent - 'haskell-simple-indent-mode - "2015-07-23") - -(defun turn-off-haskell-simple-indent () - "Turn off function `haskell-simple-indent-mode'." - (interactive) - (haskell-simple-indent-mode 0)) - -;; Provide ourselves: - -(provide 'haskell-simple-indent) - -;;; haskell-simple-indent.el ends here diff --git a/tests/haskell-indentation-tests.el b/tests/haskell-indentation-tests.el index 158e7b6f0..c0d0bf225 100644 --- a/tests/haskell-indentation-tests.el +++ b/tests/haskell-indentation-tests.el @@ -28,7 +28,6 @@ (require 'haskell-font-lock) (require 'haskell-indentation) (require 'haskell-indent) -(require 'haskell-simple-indent) ;;; Code: @@ -132,19 +131,6 @@ macro quotes them for you." (should-not haskell-indentation-mode) (should haskell-indent-mode))) -(ert-deftest haskell-indentation-turns-off-haskell-simple-indent () - (with-temp-buffer - (haskell-mode) - (haskell-simple-indent-mode) - (should haskell-simple-indent-mode) - (haskell-indentation-mode) - (should haskell-indentation-mode) - (should-not haskell-simple-indent-mode) - - (haskell-simple-indent-mode) - (should-not haskell-indentation-mode) - (should haskell-simple-indent-mode))) - (hindent-test "1 Check if '{' on its own line gets properly indented"" function = Record { field = 123 }" diff --git a/tests/haskell-simple-indent-tests.el b/tests/haskell-simple-indent-tests.el deleted file mode 100644 index 55c4aed8c..000000000 --- a/tests/haskell-simple-indent-tests.el +++ /dev/null @@ -1,182 +0,0 @@ -(require 'ert) -(require 'haskell-simple-indent) - -(defun find-indent-positions (lines-above-content) - (with-temp-buffer - (dolist (line lines-above-content) - (insert line) - (insert "\n")) - ;; cursor is at the beginning of the second line now - (let ((result '())) - (dotimes (i 10) - (haskell-simple-indent) - (setq result (cons (current-column) result))) - (reverse result)))) - - -(defun find-indent-and-backtab-positions (lines-above-content &optional prepare-buffer) - (with-temp-buffer - (if prepare-buffer - (funcall prepare-buffer)) - (dolist (line lines-above-content) - (insert line) - (insert "\n")) - ;; cursor is at the beginning of the second line now - (let ((result-forward '(0)) - (result-backward '())) - (dotimes (i 9) - (haskell-simple-indent) - (setq result-forward (cons (current-column) result-forward))) - (dotimes (i 9) - (setq result-backward (cons (current-column) result-backward)) - (haskell-simple-indent-backtab)) - (setq result-backward (cons (current-column) result-backward)) - (list (reverse result-forward) result-backward)))) - -(defun indent-and-backtab-last-line (lines &optional prepare-buffer) - (with-temp-buffer - (let (after-indent after-backtab) - (if prepare-buffer - (funcall prepare-buffer)) - (dolist (line lines) - (insert line) - (insert "\n")) - (forward-line -1) - (skip-chars-forward "^|") - (delete-char 1) - (haskell-simple-indent) - (insert "|") - (setq after-indent (buffer-substring (line-beginning-position) (line-end-position))) - (delete-char -1) - (haskell-simple-indent-backtab) - (insert "|") - (setq after-backtab (buffer-substring (line-beginning-position) (line-end-position))) - (list after-indent after-backtab)))) - -(ert-deftest find-indent-positions-1 () - (should (equal '(5 7 10 19 26 32 40 48 56 64) - (find-indent-positions '("main = do putStrLn \"Hello World!\""))))) - - -(ert-deftest find-indent-positions-2 () - (should (equal '(8 10 13 20 24 27 32 35 37 45) - (find-indent-positions '("\tx <- return 123 {- This is a comment -}"))))) - - -(ert-deftest find-indent-positions-3 () - (should (equal '(2 4 6 8 10 12 14 16 24 32) - (find-indent-positions '("a b c d" - " e f g h"))))) - - -(ert-deftest find-indent-positions-4 () - (should (equal '(2 4 5 8 16 24 32 40 48 56) - (find-indent-positions '("a b c d e f g h" - " long_streak"))))) - -(ert-deftest find-indent-positions-5 () - (should (equal '(2 4 6 13 15 17 19 24 32 40) - (find-indent-positions '(" f g e e iirelevant" - "a b c d" - " h idden" - " hidden" - "" - " e f g h" - ""))))) - -(ert-deftest find-indent-and-backtab-positions-1 () - (should (equal '((0 2 4 5 8 16 24 32 40 48) - (0 2 4 5 8 16 24 32 40 48)) - ;; Note: haskell-simple-indent-backtab is broken when - ;; it encounters TABs in source file. - (find-indent-and-backtab-positions '("a b c d e f g h" - " long_streak") - (lambda () - (setq indent-tabs-mode nil)))))) - -(ert-deftest find-indent-and-backtab-positions-1a () - (should (equal '((0 2 4 5 8 16 24 32 40 48) - (0 2 4 5 8 16 24 32 40 48)) - (find-indent-and-backtab-positions '("a b c d e f g h" - " long_streak"))))) - -(ert-deftest find-indent-and-backtab-positions-2 () - (should (equal '((0 8 10 13 20 24 27 32 35 37) - (0 8 10 13 20 24 27 32 35 37)) - (find-indent-and-backtab-positions '("\tx <- return 123 {- This is a comment -}") - (lambda () - (setq indent-tabs-mode nil)))))) - -(ert-deftest find-indent-and-backtab-positions-2a () - (should (equal '((0 8 10 13 20 24 27 32 35 37) - (0 8 10 13 20 24 27 32 35 37)) - (find-indent-and-backtab-positions '("\tx <- return 123 {- This is a comment -}"))))) - -(ert-deftest find-indent-and-backtab-positions-3 () - (should (equal '((0 2 4 6 13 15 17 19 24 32) - (0 2 4 6 13 15 17 19 24 32)) - (find-indent-and-backtab-positions '(" f g e e iirelevant" - "a b c d" - " h idden x" - " hidden 4 5" - "" - " e f g h" - "") - (lambda () - (setq indent-tabs-mode nil)))))) - -(ert-deftest find-indent-and-backtab-positions-3a () - (should (equal '((0 2 4 6 13 15 17 19 24 32) - (0 2 4 6 13 15 17 19 24 32)) - (find-indent-and-backtab-positions '(" f g e e iirelevant" - "a b c d" - " h idden x" - " hidden 4 5" - "" - " e f g h" - ""))))) - -(ert-deftest indent-and-backtab-last-line-1 () - (should (equal '("\t|" - "|") - (indent-and-backtab-last-line '("|"))))) - -(ert-deftest indent-and-backtab-last-line-2 () - (should (equal '("\t|x" - "|x") - (indent-and-backtab-last-line '("|x"))))) - -(ert-deftest indent-and-backtab-last-line-3 () - (should (equal '("\t|x" - "|x") - (indent-and-backtab-last-line '("| x"))))) - -(ert-deftest indent-and-backtab-last-line-4 () - (should (equal '(" |x" - " |x") - (indent-and-backtab-last-line '("a b c" - "| x"))))) - -(ert-deftest indent-and-backtab-last-line-5 () - (should (equal '("\tx|y" - "x|y") - (indent-and-backtab-last-line '("x|y"))))) - -(ert-deftest indent-and-backtab-last-line-6 () - (should (equal '("\t\t\tx|y" - "x|y") - (indent-and-backtab-last-line '("\t\t\tbase" - "x|y"))))) - -(ert-deftest indent-and-backtab-last-line-7 () - (should (equal '("\txy |" - " xy |") - (indent-and-backtab-last-line '(" p x" - "\t\t\tbase" - " xy |"))))) - -(ert-deftest indent-and-backtab-last-line-8 () - (should (equal '("\t\t this_is_|long" - "\t this_is_|long") - (indent-and-backtab-last-line '(" a a a a a a a a this_is_long" - " this_is_|long")))))