diff --git a/helpers.el b/helpers.el index 64264d1..e1c5353 100644 --- a/helpers.el +++ b/helpers.el @@ -197,3 +197,24 @@ there's a region, all lines that region covers will be duplicated." (rename-buffer new-name) (set-visited-file-name new-name) (set-buffer-modified-p nil))))))) + + +;; +;; HideShow mode helpers +;; - from: http://www.emacswiki.org/emacs/HideShow +;; +(defun toggle-selective-display (column) + (interactive "P") + (set-selective-display + (or column + (unless selective-display + (1+ (current-column)))))) + +(defun toggle-hiding (column) + (interactive "P") + (if hs-minor-mode + (if (condition-case nil + (hs-toggle-hiding) + (error t)) + (hs-show-all)) + (toggle-selective-display column))) diff --git a/keybindings.el b/keybindings.el index c18810a..06c1c90 100644 --- a/keybindings.el +++ b/keybindings.el @@ -57,6 +57,10 @@ (global-set-key (kbd "C-c /") 'comment-or-uncomment-region-or-line) (global-set-key (kbd "C-c C-/") 'comment-or-uncomment-region-or-line) +;; Custom HideShow toggles (via helpers.el) +(global-set-key (kbd "C-=") 'toggle-selective-display) +(global-set-key (kbd "C-\\") 'toggle-hiding) + (when (require 'auto-complete nil 'noerror) (define-key ac-completing-map (kbd "RET") 'ac-complete) (define-key ac-completing-map (kbd "C-m") 'ac-complete) diff --git a/mode-customizations/coffee-mode.el b/mode-customizations/coffee-mode.el index eca604c..d6dfbca 100644 --- a/mode-customizations/coffee-mode.el +++ b/mode-customizations/coffee-mode.el @@ -7,6 +7,7 @@ (flycheck-mode) (linum-mode t) (fci-mode) + (hs-minor-mode 1) (auto-complete-mode) (subword-mode) (whitespace-mode) diff --git a/mode-customizations/css-mode.el b/mode-customizations/css-mode.el index cc33f1e..44233f9 100644 --- a/mode-customizations/css-mode.el +++ b/mode-customizations/css-mode.el @@ -3,6 +3,7 @@ (flyspell-prog-mode) (linum-mode t) (fci-mode) + (hs-minor-mode 1) (auto-complete-mode) (subword-mode) (setq css-indent-offset 2) diff --git a/mode-customizations/emacs-lisp-mode.el b/mode-customizations/emacs-lisp-mode.el index 4939b17..2dcec7b 100644 --- a/mode-customizations/emacs-lisp-mode.el +++ b/mode-customizations/emacs-lisp-mode.el @@ -4,6 +4,7 @@ (flyspell-prog-mode) (linum-mode t) (fci-mode) + (hs-minor-mode 1) (auto-complete-mode)) (add-hook 'emacs-lisp-mode-hook 'customizations-for-emacs-lisp-mode) diff --git a/mode-customizations/erlang-mode.el b/mode-customizations/erlang-mode.el index 3cf5b62..8789aa5 100644 --- a/mode-customizations/erlang-mode.el +++ b/mode-customizations/erlang-mode.el @@ -13,6 +13,7 @@ (flyspell-prog-mode) (linum-mode t) (fci-mode) + (hs-minor-mode 1) (auto-complete-mode) (setq highlight-indentation-offset 2) (highlight-indentation-mode) diff --git a/mode-customizations/go-mode.el b/mode-customizations/go-mode.el index 0a6451e..628a509 100644 --- a/mode-customizations/go-mode.el +++ b/mode-customizations/go-mode.el @@ -4,6 +4,7 @@ (flycheck-mode) (linum-mode t) (fci-mode) + (hs-minor-mode 1) (auto-complete-mode) (whitespace-mode) (subword-mode) diff --git a/mode-customizations/js-mode.el b/mode-customizations/js-mode.el index eff2858..a98966d 100644 --- a/mode-customizations/js-mode.el +++ b/mode-customizations/js-mode.el @@ -5,6 +5,7 @@ (flycheck-mode) (linum-mode t) (fci-mode) + (hs-minor-mode 1) (auto-complete-mode) (subword-mode) (setq tab-width 2) diff --git a/mode-customizations/lisp-mode.el b/mode-customizations/lisp-mode.el index b80cf39..4a1e516 100644 --- a/mode-customizations/lisp-mode.el +++ b/mode-customizations/lisp-mode.el @@ -4,6 +4,7 @@ (flyspell-prog-mode) (linum-mode t) (fci-mode) + (hs-minor-mode 1) (auto-complete-mode)) (add-hook 'lisp-mode-hook 'customizations-for-lisp-mode) diff --git a/mode-customizations/php-mode.el b/mode-customizations/php-mode.el index 4b7dfff..d1e0cd3 100644 --- a/mode-customizations/php-mode.el +++ b/mode-customizations/php-mode.el @@ -6,6 +6,7 @@ (flyspell-prog-mode) (linum-mode t) (fci-mode) + (hs-minor-mode 1) (auto-complete-mode) (subword-mode) (setq php-basic-offset 2) diff --git a/mode-customizations/python-mode.el b/mode-customizations/python-mode.el index 6a79f02..129c56e 100644 --- a/mode-customizations/python-mode.el +++ b/mode-customizations/python-mode.el @@ -3,6 +3,7 @@ (flyspell-prog-mode) (linum-mode t) (fci-mode) + (hs-minor-mode 1) (auto-complete-mode) (subword-mode) (highlight-indentation-mode) diff --git a/mode-customizations/ruby-mode.el b/mode-customizations/ruby-mode.el index 71568c1..a33f5b8 100644 --- a/mode-customizations/ruby-mode.el +++ b/mode-customizations/ruby-mode.el @@ -49,7 +49,7 @@ (setq ruby-use-encoding-map nil) (setq whitespace-action (quote (auto-cleanup))) (define-key ruby-mode-map (kbd "RET") 'reindent-then-newline-and-indent) - (define-key ruby-mode-map (kbd "C-c C-h") 'hs-toggle-hiding) + (define-key ruby-mode-map (kbd "C-c C-h") 'toggle-hiding) (define-key ruby-mode-map (kbd "C-c C-l") 'goto-line) ) @@ -57,9 +57,11 @@ ;; Set up hs-mode (HideShow) for Ruby (add-to-list 'hs-special-modes-alist - '(ruby-mode - "\\(def \\|class\\|module\\|do\\)" "end" "#" - (lambda (arg) (ruby-end-of-block)) nil)) + `(ruby-mode + ,(rx (or "def" "class" "module" "{" "[")) ; Block start + ,(rx (or "}" "]" "end")) ; Block end + ,(rx (or "#" "=begin")) ; Comment start + ruby-forward-sexp nil)) ;; Workaround for missing method in ruby-mode.el ;; See: https://gist.github.com/1213051 diff --git a/mode-customizations/sh-mode.el b/mode-customizations/sh-mode.el index 04f3b68..e0dab7c 100644 --- a/mode-customizations/sh-mode.el +++ b/mode-customizations/sh-mode.el @@ -9,6 +9,7 @@ (flycheck-mode) (linum-mode t) (fci-mode) + (hs-minor-mode 1) (auto-complete-mode) (whitespace-mode) (subword-mode)