Emacs equivalent of Vim's foldmethod = indent

前端 未结 3 1607
猫巷女王i
猫巷女王i 2020-12-11 02:03

Question: Does Emacs have a canonical equivalent of Vim\'s Folding with Foldmethod=indent?

I am particularly interested in something that can work a

3条回答
  •  有刺的猬
    2020-12-11 02:54

    maybe selective-display? I have the following function bound to [f2]

    ;; http://emacs.wordpress.com/2007/01/16/quick-and-dirty-code-folding/
    (defun jao-toggle-selective-display (column)
      (interactive "P")
      (set-selective-display
       (if selective-display nil (or column 1))))
    

    That's pretty bare-bones, though, and you'd really want it to be Pythony-indentation sensitive....

    UPDATE: I was staring at this last night, and realized that I was tired of C-u entering the column I was on (plus 1).... so I coded it up:

    (defun toggle-selective-display-column ()
      "set selective display fold everything greater than the current column, or toggle off if active"
      (interactive)
      (set-selective-display
       (if selective-display nil (or (+ (current-column) 1) 1))))
    

    Further elaboration should combine the two functions.

    See also: How to achieve code folding effects in emacs

提交回复
热议问题