Difference between revisions of "Emacs/Code folding"

From HaskellWiki
Jump to: navigation, search
m (Added infobox.)
(Blanked the page)
Line 1: Line 1:
{{Haskell infobox}}
=== Folding ===
For folding parts of code you can use
*and '''hs-outline-level''' (based on py-outline-level created by Gb)
;; this gets called by outline to determine the level. Just use the length of the whitespace
  (defun hsk-outline-level ()
    (let (buffer-invisibility-spec)
        (skip-chars-forward "\t ")
;; this get called after haskell mode is enabled
    (lambda ()
        ;; outline uses this regexp to find headers. I match lines with no indent and indented
        ;; some lines, such as "--" ... "class"
        (setq outline-regexp "^[^\t ].*\\|^.*[\t ]+\\(where\\|of\\|do\\|in\\|if\\|then\\|else\\|let\\|module\\|import\\|deriving\\|instance\\|class\\)[\t\n ]")
        ;; enable our level computation
          (setq outline-level 'hsk-outline-level)
        ;; do not use their \C-c@ prefix, too hard to type. Note this overides some python mode bindings
        ;;(setq outline-minor-mode-prefix "C-c")
        ;; turn on outline mode
          (outline-minor-mode t)
        ;; initially hide all but the headers
*Also, you can use '''toggle-selective-display''' for global folding
;; folding for all rows, starting on the current column
    (defun toggle-selective-display (column)
      (interactive "P")
      (or column
          (unless selective-display
            (1+ (current-column))))))
  (global-set-key (kbd "C-x $") 'toggle-selective-display)
    (defun toggle-hiding (column)
      (interactive "P")
      (if hs-minor-mode
          (if (condition-case nil
                (error t))
        (toggle-selective-display column)))
  (global-set-key (kbd "C-@") 'toggle-hiding)
*and '''narrowing capabilities''' for folding the rest of code
    (put 'narrow-to-defun 'disabled nil)
    (put 'narrow-to-page 'disabled nil)
    (put 'narrow-to-region 'disabled nil)
*or '''folding-mode''', if you do not mind add markers such as '''{-{{{-}''' and '''{-}}}-}''' in code.

Revision as of 12:32, 11 April 2016