From 18b6eec6adf98cc096d368db5443449971265115 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Tue, 28 Feb 2012 20:38:50 +0900 Subject: [PATCH] Defining C-< and C-> for indentation. --- elisp/Makefile | 2 +- elisp/ghc-indent.el | 35 +++++++++++++++++++++++++++++++++++ elisp/ghc.el | 5 +++++ ghc-mod.cabal | 3 ++- 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 elisp/ghc-indent.el diff --git a/elisp/Makefile b/elisp/Makefile index 4e202fe..efe0543 100644 --- a/elisp/Makefile +++ b/elisp/Makefile @@ -1,5 +1,5 @@ SRCS = ghc.el ghc-func.el ghc-doc.el ghc-comp.el ghc-flymake.el \ - ghc-command.el ghc-info.el ghc-ins-mod.el + ghc-command.el ghc-info.el ghc-ins-mod.el ghc-indent.el EMACS = emacs DETECT = xemacs diff --git a/elisp/ghc-indent.el b/elisp/ghc-indent.el new file mode 100644 index 0000000..f4f4d1a --- /dev/null +++ b/elisp/ghc-indent.el @@ -0,0 +1,35 @@ +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;; +;;; ghc-indent.el +;;; + +;; Author: Kazu Yamamoto +;; Created: Feb 28, 2012 + +;;; Code: + +(defvar ghc-indent-offset 4) + +(defun ghc-make-indent-shallower (beg end) + (interactive "r") + (let ((n ghc-indent-offset)) + (save-excursion + (save-restriction + (narrow-to-region beg end) + (goto-char beg) + (while (not (eobp)) + (delete-region (point) (+ (point) n)) + (forward-line)))))) + +(defun ghc-make-indent-deeper (beg end) + (interactive "r") + (let ((indent (make-string ghc-indent-offset 32))) + (save-excursion + (save-restriction + (narrow-to-region beg end) + (goto-char beg) + (while (not (eobp)) + (insert indent) + (forward-line)))))) + +(provide 'ghc-indent) diff --git a/elisp/ghc.el b/elisp/ghc.el index 43e41c7..ad83d60 100644 --- a/elisp/ghc.el +++ b/elisp/ghc.el @@ -27,6 +27,7 @@ (require 'ghc-flymake) (require 'ghc-command) (require 'ghc-ins-mod) +(require 'ghc-indent) (require 'dabbrev) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; @@ -54,6 +55,8 @@ (defvar ghc-module-key "\C-c\C-m") (defvar ghc-expand-key "\C-c\C-e") (defvar ghc-hoogle-key (format "\C-c%c" (ghc-find-C-h))) +(defvar ghc-shallower-key "\C-c<") +(defvar ghc-deeper-key "\C-c>") ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;; @@ -82,6 +85,8 @@ (define-key haskell-mode-map ghc-toggle-key 'ghc-flymake-toggle-command) (define-key haskell-mode-map ghc-module-key 'ghc-insert-module) (define-key haskell-mode-map ghc-hoogle-key 'haskell-hoogle) + (define-key haskell-mode-map ghc-shallower-key 'ghc-make-indent-shallower) + (define-key haskell-mode-map ghc-deeper-key 'ghc-make-indent-deeper) (ghc-comp-init) (setq ghc-initialized t))) diff --git a/ghc-mod.cabal b/ghc-mod.cabal index 25f58d7..0556912 100644 --- a/ghc-mod.cabal +++ b/ghc-mod.cabal @@ -22,7 +22,8 @@ Cabal-Version: >= 1.6 Build-Type: Simple Data-Dir: elisp Data-Files: Makefile ghc.el ghc-func.el ghc-doc.el ghc-comp.el - ghc-flymake.el ghc-command.el ghc-info.el ghc-ins-mod.el + ghc-flymake.el ghc-command.el ghc-info.el + ghc-ins-mod.el ghc-indent.el Executable ghc-mod Main-Is: GHCMod.hs Other-Modules: Browse