camlspotter avatar camlspotter committed 7768948

auto support of indentation modes

Comments (0)

Files changed (1)

 ; In your .emacs:
 ;
 ; ;; (load "offside-trap.el") is NOT good. It must be loaded 
-; ;; after loading "haskell-indentation.el" 
-; (autoload 'offside-trap-haskell-indentation-mode "offside-trap.el")
-; (autoload 'offside-trap-haskell-indent-mode "offside-trap.el")
+; ;; after loading "haskell-indentation.el" or "haskell-indent.el"
+; (autoload 'offside-trap-mode "offside-trap.el")))
 ;
 ; (add-hook 
 ;  'haskell-mode-hook
 ;  '(lambda ()
-;     (turn-on-haskell-doc-mode)
-;     (turn-on-haskell-indentation)
 ;
-;     ;; this must be called after turn-on-haskell-indentation or haskell-indentation-mode,
-;     ;; so that offside-trap-mode-map overrides haskell-indentation-mode-map
-;     (offside-trap-haskell-indentation-mode t) 
+;     ;; Load one of you like.
+;     ; (turn-on-haskell-indentation)
+;     ; (turn-on-haskell-indent)
+;
+;     ;; This must be called after turn-on-haskell-indentation/turn-on-haskell-indent,
+;     ;; so that offside-trap-mode-map overrides haskell-indentation/indent-mode-map
+;     (offside-trap-mode) 
 ;     ))
 ;
-; ; For haskell-indent users:
-; ;   Change haskell-indentation in the above hook to haskell-indent
-; 
 ; ; For gnome-terminal / xfce4-terminal / too-gnome-friendly-terminal users:
 ; ;   The default key setting does not work nicely for gnome-terminal, since it does not 
 ; ;   detect C-return/C-tab. Just throw the terminal for brain-less newbie morons and 
 	      (if (< offside-trap-sticky-line-start offside-trap-sticky-line-end)
 		  (indent-rigidly (offside-trap-bol (1+ offside-trap-sticky-line-start))
 				  (offside-trap-eol offside-trap-sticky-line-end)
-				  diff-chars))))))))
+				  diff-chars))
+	      ))))))
 
 ;; step mode
 ;; offside-trap-sticky-line-{start,end} must be set
 
     map)
   "Keymap for `offside-trap-sticky-mode'.")
+
+;;;; haskell-indentation or haskell-indent
+
+;; default is haskell-indent, since debian installs it as a default indentation mode
+(defun is-haskell-indentation ()
+  (and (boundp 'haskell-indentation-mode)
+       haskell-indentation-mode))
  
+(defun offside-trap-newline-and-block-indent ()
+  (interactive)
+  (if (is-haskell-indentation)
+      (progn 
+	;; haskell-indentation 
+	(offside-trap-move-to-non-space-char)
+	(offside-trap-set-sticky-lines)
+	(setq overriding-terminal-local-map offside-trap-sticky-mode-map) ;; go into the sticky mode 
+	(offside-trap-block-indent-gen 'haskell-newline-and-indent))
+    ;; haskell-indent 
+    ;; haskell-newline-and-indent first moves the point to the next non-empty char then insert a newline, 
+    ;; which is bizarre... So first we perform this cursor movement by ourselves first.
+    (offside-trap-move-to-non-space-char)
+    (offside-trap-set-sticky-lines)
+    (setq overriding-terminal-local-map offside-trap-sticky-mode-map) ;; go into the sticky mode 
+    (offside-trap-block-indent-gen 'newline-and-indent)))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; haskell-indentation
 
-(defun offside-trap-haskell-indentation-newline-and-block-indent ()
-  (interactive)
-  ;; haskell-newline-and-indent first moves the point to the next non-empty char then insert a newline, 
-  ;; which is bizarre... So first we perform this cursor movement by ourselves first.
-  (offside-trap-move-to-non-space-char)
-  (offside-trap-set-sticky-lines)
-  (setq overriding-terminal-local-map offside-trap-sticky-mode-map) ;; go into the sticky mode 
-  (offside-trap-block-indent-gen 'haskell-newline-and-indent))
-
 ;; offside trap mode keymap (borrowed from isearch.el)
-(defvar offside-trap-haskell-indentation-mode-map
+(defun offside-trap-mode-map ()
   (let ((keymap (make-sparse-keymap)))
-    (define-key keymap (kbd "RET") 'offside-trap-haskell-indentation-newline-and-block-indent)
-    (define-key keymap (kbd "TAB") 'offside-trap-block-indent)
-    (define-key keymap (kbd "<tab>") 'offside-trap-block-indent)
-    ; gnome-terminal users: stop using it. It does not catch contrl modifier with return or tab.
-    (define-key keymap (kbd "<C-return>") 'haskell-newline-and-indent)
-    (define-key keymap (kbd "<C-tab>") 'indent-for-tab-command)
-    keymap))
-
-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; haskell-indent
-
-(defun offside-trap-haskell-indent-newline-and-block-indent ()
-  (interactive)
-  ;; haskell-newline-and-indent first moves the point to the next non-empty char then insert a newline, 
-  ;; which is bizarre... So first we perform this cursor movement by ourselves first.
-  (offside-trap-move-to-non-space-char)
-  (offside-trap-set-sticky-lines)
-  (setq overriding-terminal-local-map offside-trap-sticky-mode-map) ;; go into the sticky mode 
-  (offside-trap-block-indent-gen 'newline-and-indent))
-
-;; offside trap mode keymap (borrowed from isearch.el)
-(defvar offside-trap-haskell-indent-mode-map
-  (let ((keymap (make-sparse-keymap)))
-    (define-key keymap (kbd "RET") 'offside-trap-haskell-indent-newline-and-block-indent)
-    (define-key keymap (kbd "TAB") 'offside-trap-block-indent)
-    (define-key keymap (kbd "<tab>") 'offside-trap-block-indent)
-    ; gnome-terminal users: stop using it. It does not catch control modifier with return or tab.
-    (define-key keymap (kbd "<C-return>") 'newline)
-    (define-key keymap (kbd "<C-tab>") 'indent-for-tab-command)
+    (if (is-haskell-indentation)
+	(progn
+	  ;; haskell-indentation
+	  (define-key keymap (kbd "RET") 'offside-trap-newline-and-block-indent)
+	  (define-key keymap (kbd "TAB") 'offside-trap-block-indent)
+	  (define-key keymap (kbd "<tab>") 'offside-trap-block-indent)
+	  ;; gnome-terminal users: stop using it. It does not catch contrl modifier with return or tab.
+	  (define-key keymap (kbd "<C-return>") 'haskell-newline-and-indent)
+	  (define-key keymap (kbd "<C-tab>") 'indent-for-tab-command))
+      ;; haskell-indent
+      (define-key keymap (kbd "RET") 'offside-trap-newline-and-block-indent)
+      (define-key keymap (kbd "TAB") 'offside-trap-block-indent)
+      (define-key keymap (kbd "<tab>") 'offside-trap-block-indent)
+      ;; gnome-terminal users: stop using it. It does not catch control modifier with return or tab.
+      (define-key keymap (kbd "<C-return>") 'newline)
+      (define-key keymap (kbd "<C-tab>") 'indent-for-tab-command))
     keymap))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; minor mode
 
-(define-minor-mode offside-trap-haskell-indentation-mode
-  "Offside trap mode for haskell-indentation."
+(define-minor-mode offside-trap-mode
+  "Offside trap mode for haskell."
   :lighter " OffsideTrap"
-  :keymap offside-trap-haskell-indentation-mode-map)
-
-(define-minor-mode offside-trap-haskell-indent-mode
-  "Offside trap mode for haskell-indent."
-  :lighter " OffsideTrap"
-  :keymap offside-trap-haskell-indent-mode-map)
-
+  :keymap (offside-trap-mode-map))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.