Created
January 16, 2011 22:16
-
-
Save uk-ar/782208 to your computer and use it in GitHub Desktop.
hideshow-cycle.el
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(progn | |
(load-library "hideshow") | |
(add-to-list 'hs-special-modes-alist | |
'(ruby-mode | |
"class\\|module\\|def\\|if\\|unless\\|case\\|while\\|until\\|for\\|begin\\|do" "end" "#" | |
;;"\\(def\\|do\\|{\\)" "\\(end\\|end\\|}\\)" "#" | |
(lambda (arg) (ruby-end-of-block)) | |
;;ruby-move-to-block | |
nil)) | |
;;hoge | |
;;fuga | |
;;hideshowvis | |
;;(auto-install-from-emacswiki "hideshowvis.el") | |
;; (progn | |
;; (autoload 'hideshowvis-enable | |
;; "hideshowvis" "Highlight foldable regions") | |
;; (autoload 'hideshowvis-minor-mode | |
;; "hideshowvis" | |
;; "Will indicate regions foldable with hideshow in the fringe." | |
;; 'interactive) | |
;; ;;copy from hideshowvis.el | |
;; (eval-after-load 'hideshowvis | |
;; '(progn | |
;; (define-fringe-bitmap 'hs-marker [0 24 24 126 126 24 24 0]) | |
;; (defcustom hs-fringe-face 'hs-fringe-face | |
;; "*Specify face used to highlight the fringe on hidden regions." | |
;; :type 'face | |
;; :group 'hideshow) | |
;; (defface hs-fringe-face | |
;; '((t (:foreground | |
;; "#888" :box | |
;; (:line-width 2 :color "grey75" :style released-button)))) | |
;; "Face used to highlight the fringe on folded regions" | |
;; :group 'hideshow) | |
;; (defcustom hs-face 'hs-face | |
;; "*Specify the face to to use for the hidden region indicator" | |
;; :type 'face | |
;; :group 'hideshow) | |
;; (defface hs-face | |
;; '((t (:background "#ff8" :box t))) | |
;; "Face to hightlight the ... area of hidden regions" | |
;; :group 'hideshow) | |
;; (defun display-code-line-counts (ov) | |
;; (when (eq 'code (overlay-get ov 'hs)) | |
;; (let* ((marker-string "*fringe-dummy*") | |
;; (marker-length (length marker-string)) | |
;; (display-string | |
;; (format "(%d)..." | |
;; (count-lines (overlay-start ov) (overlay-end ov)))) | |
;; ) | |
;; (overlay-put ov 'help-echo "Hiddent text. C-c,= to show") | |
;; (put-text-property 0 marker-length 'display | |
;; (list 'left-fringe | |
;; 'hs-marker 'hs-fringe-face) marker-string) | |
;; (overlay-put ov 'before-string marker-string) | |
;; (put-text-property 0 (length display-string) | |
;; 'face 'hs-face display-string) | |
;; (overlay-put ov 'display display-string) | |
;; ))) | |
;; (setq hs-set-up-overlay 'display-code-line-counts) | |
;; ) | |
;; ) | |
;; ) | |
;; (auto-install-from-url "https://github.com/secelis/hideshow-org/raw/master/hideshow-org.el") | |
(dolist (hook (list 'emacs-lisp-mode-hook | |
'c++-mode-hook | |
'python-mode-hook | |
'espresso-mode-hook | |
'ruby-mode-hook | |
)) | |
(add-hook hook | |
'(lambda() | |
(hs-minor-mode) | |
(hs-org/minor-mode) | |
;; (if (not(eq window-system nil)) | |
;; (hideshowvis-enable)) | |
) | |
)) | |
(require 'hideshow-org) | |
(progn | |
;; ;;copy from hs-discard-overlays | |
;; (defun hs-count-overlay-block() | |
;; "Delete hideshow overlays in region defined by FROM and TO. | |
;; Skip \"internal\" overlays if `hs-allow-nesting' is non-ni." | |
;; (let((from 0) | |
;; (to 0) | |
;; (total 0)) | |
;; (save-excursion | |
;; (when (hs-find-block-beginning) | |
;; (setq from (point)) | |
;; (funcall hs-forward-sexp-func 1) | |
;; (setq to (point)) | |
;; ;;(overlay-put (make-overlay minp maxp 'face 'lazy-highlight)) | |
;; )) | |
;; (when (< to from) | |
;; (setq from (prog1 to (setq to from)))) | |
;; (if hs-allow-nesting | |
;; (let (ov) | |
;; (while (> to (setq from (next-overlay-change from))) | |
;; (when (setq ov (hs-overlay-at from)) | |
;; (setq from (overlay-end ov)) | |
;; ;; (delete-overlay ov)))) | |
;; (setq total (1+ total))))) | |
;; (dolist (ov (overlays-in from to)) | |
;; (when (overlay-get ov 'hs) | |
;; ;;(delete-overlay ov))))) | |
;; (setq total (1+ total)) | |
;; ))) | |
;; total)) | |
;; ;; copy from hs-show-all | |
;; (defun my-hs-show-block () | |
;; "Show everything then run `hs-show-hook'. See `run-hooks'." | |
;; (interactive) | |
;; (hs-life-goes-on | |
;; (message "Showing blocks ...") | |
;; (let((from 0) | |
;; (to 0) | |
;; (hs-allow-nesting nil)) | |
;; (save-excursion | |
;; (when (hs-find-block-beginning) | |
;; (setq from (point)) | |
;; (funcall hs-forward-sexp-func 1) | |
;; (setq to (point)))) | |
;; (hs-discard-overlays from to)) | |
;; (message "Showing blocks ... done") | |
;; (run-hooks 'hs-show-hook))) | |
;; (defun hs-cycle() | |
;; (hs-life-goes-on | |
;; (interactive) | |
;; (save-excursion | |
;; (message "hp%s:n%s:com%s" (hs-already-hidden-p) (hs-count-overlay-block)(hs-inside-comment-p)) | |
;; (let ((count (hs-count-overlay-block))) | |
;; (progn | |
;; (cond | |
;; ((and (hs-inside-comment-p) (not(hs-already-hidden-p))) | |
;; (hs-hide-block)) | |
;; ((and (hs-inside-comment-p) (hs-already-hidden-p)) | |
;; (hs-show-block)) | |
;; ((and (= count 0)) | |
;; (hs-hide-block)) | |
;; ((and (= count 1) | |
;; (hs-already-hidden-p)) | |
;; (hs-show-block) | |
;; (hs-hide-level 1)) | |
;; (t (my-hs-show-block))) | |
;; ))))) | |
;; ;;hoge | |
;; ;;fuga | |
(defadvice hs-toggle-hiding (around hs-cycle-or-none activate) | |
(interactive) | |
(hs-life-goes-on | |
(if | |
(and | |
(or (not transient-mark-mode) | |
(and transient-mark-mode (not mark-active)));;require | |
(or (and (hs-inside-comment-p) | |
(= (line-number-at-pos) | |
(line-number-at-pos(car (hs-inside-comment-p))))) | |
(let ((pos (point)) | |
from to) | |
(save-excursion | |
;; copy from hs-hide-level-recursive | |
(when (hs-find-block-beginning) | |
(setq from (point)) | |
(funcall hs-forward-sexp-func 1) | |
(setq to (point)) | |
(and (= (line-number-at-pos pos) | |
(line-number-at-pos from)) | |
(not (= (line-number-at-pos from) | |
(line-number-at-pos to))))))))) | |
ad-do-it | |
;;(hs-cycle) | |
))) | |
) | |
;;(ad-deactivate-regexp "hs-cycle-or-none") | |
;;(global-set-key "\C-o" 'hs-toggle-hiding) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment