Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decent folding like in Vim #3226

Closed
ReneFroger opened this issue Oct 1, 2015 · 35 comments
Closed

Decent folding like in Vim #3226

ReneFroger opened this issue Oct 1, 2015 · 35 comments
Labels
Enhancement ☺ Fixed in develop stale marked as a stale issue/pr (usually by a bot)

Comments

@ReneFroger
Copy link

One of the things that I miss in Spacemacs, was the decent folding like Vim have. I opened a topic about it on Emacs Stackexchange.

@mrkkrp took the challenge, and developed the package Vimish fold that succesfully emulates nearly all the abilities of Vim folding method.

See this screenscast to see it in the action:

72bfce16-6795-11e5-8c46-ffb3559cdc1d

I was wondering if this could be included with Spacemacs, given the fact that one of the goals of Spacemacs is to emulate Vim.

Given the fact that Vim creates the folding in visual mode with the key zf, I remapped the features of Vimish fold, might be some inspiration for you? :

(key-seq-define evil-normal-state-map "sf" 'vimish-fold-toggle) 
(key-seq-define evil-visual-state-map "sf" 'vimish-fold) 
(key-seq-define evil-normal-state-map "sd" 'vimish-fold-delete) 
(key-seq-define evil-normal-state-map "sj" 'vimish-fold-next-fold) 
(key-seq-define evil-normal-state-map "sk" 'vimish-fold-previous-fold) 

Note that you will be still able to use the key s, but with another timing.

@TheBB
Copy link
Contributor

TheBB commented Oct 1, 2015

Can't we get this to work with the regular z keys by making the necessary adjustments to evil-fold-list?

@robbyoconnor
Copy link
Contributor

Yeah I don't see any value in adding this as it can be done with the z keys...and it _DOES_ emulate vim just fine...

@alexmurray
Copy link

How about

(add-to-list 'evil-fold-list '((vimish-fold-mode)
                               :open-all   vimish-fold-unfold-all
                               :close-all  nil
                               :toggle     vimish-fold-toggle
                               :open       vimish-fold-unfold
                               :open-rec   nil
                               :close      vimish-fold))

@robbyoconnor
Copy link
Contributor

I personally don't see value but I'm stubborn as hell.

@alexmurray
Copy link

Also to create a fold with zf:

(define-key evil-visual-state-map (kbd "zf") #'vimish-fold)

@alexmurray
Copy link

@alexmurray
Copy link

Update - PR for evil itself (without the need for the change to vimish-fold) - https://bitbucket.org/lyro/evil/pull-requests/24/add-vimish-fold-folding-support-and-fold

@TheBB
Copy link
Contributor

TheBB commented Oct 2, 2015

@robbyoconnor Vim can do a whole lot more with folds than any of the currently implemented fold methods, like create folds from arbitrary regions. It's one of the few remaining feature gaps between Emacs/Evil/Spacemacs and Vim. If this package does what is advertised it's a no-brainer for me to include it.

Good job on the PR @alexmurray, exactly what I had in mind.

@robbyoconnor
Copy link
Contributor

👍

@punassuming
Copy link
Contributor

This is handy, but how does the work with hideshow as well? The capability to collapse all folds is valuable. I am also working on package to extend evil and hs to be more like vim, that I will release once I figure out how I am going to maintain multiple ranger frames simultaneously.

@syl20bnr
Copy link
Owner

syl20bnr commented Oct 2, 2015

WOW you guys are amazing 👍
@ReneFroger thank you for pointing it out.

@stormpat
Copy link
Contributor

stormpat commented Oct 2, 2015

👍

@nashamri
Copy link
Contributor

nashamri commented Oct 2, 2015

Ohh nice! this was indeed missing from spacemacs!! good job guys!!

@alexmurray
Copy link

Since this doesn't appear to be landing in evil just yet - for the impatient have a look at https://github.com/alexmurray/evil-vimish-fold

@cataclysmic
Copy link

Hey Guys,

great work. I'm loving it. I am really missing the code folding capabilities from Vim.
I do have 2 questions that you might be able to help me with.

  1. Do you have plans for adding the "Manual" ( {{{ }}} ) code folding option? I know there is folding.el but I only have troubles with it and I am so used to the nice and quick way in Vim.

  2. I try code folding on existing folding marks (I just recently moved from Vim to Emacs and my codes are full of folding marks.) but I only get an error message saying: "Folding is not supported for any of these major / minor modes." Is there any way I can add that mode (ESS) ?
    [ I know this might be more of a stackexchange question but you have looked into the evil-code in detail and might be the best to help me. ;-) ]

Anyway thanks again for the package.

@ReneFroger
Copy link
Author

@cataclysmic

http://emacs.stackexchange.com/questions/14781/how-can-i-replicate-vims-code-folding

One of these packages have the capability to fold the {{{ marks.

@cataclysmic
Copy link

Thanx for the reply.
Sadly all those packages try to mimic the "non-manual" folding of Vim. Which I don't need. The folding.el can work with {{{ }}} folds but it's pretty messy as it needs the fold in empty lines except for the {{{ and }}}.
Then apparently it removes the linebreaks somehow and presents the code in a more compact way. It shows compacted code into one line littered with ^M. Not really folding to me.
I am used to something like this:
# code segment description #{{{
code
foo
bar
#}}}

when folded turning into:
# code segment description #{{{ ..........

I work mainly with statistical software which requires doing the same things many times over with only minor changes. So the recommended "Search for the function you need" approach really doesn't work for me as it produces too many results.

@ReneFroger
Copy link
Author

@cataclysmic what if you open an issue on the issue tracker of Vimish Fold?

@cataclysmic
Copy link

Great idea. I wanted to check all the options first. There just soooo many packages out there. ;-)

@mkomitee
Copy link

FYI, the PR to evil got declined. Maybe evil-vimish-fold integration in spacemacs is a good idea?

@cataclysmic
Copy link

Hm Sad.

Thank you for trying.

On 15.02.2016 05:03, Michael Komitee wrote:

FYI, the PR to evil got declined. Maybe evil-vimish-fold integration
in spacemacs is a good idea?


Reply to this email directly or view it on GitHub
#3226 (comment).

@StreakyCobra
Copy link
Contributor

Maybe evil-vimish-fold integration in spacemacs is a good idea?

PR welcome :-)

@hh
Copy link

hh commented Jun 20, 2016

@cataclysmic did you ever find a nice approach for getting folding working? vimish-fold doesn't seem that great for ruby code (just trying to fold do/end blocks for chef resources).

@cataclysmic
Copy link

Hi there,

honestly I moved to using outline-(minor)-mode.
It's a hassle to convert from my old vim-folds but was the best solution
for me.

On 20.06.2016 19:06, Hippie Hacker wrote:

@cataclysmic https://github.com/cataclysmic did you ever find a nice
approach for getting folding working? vimish-fold doesn't seem that
great for ruby code (just trying to fold do/end blocks for chef
resources).


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#3226 (comment),
or mute the thread
https://github.com/notifications/unsubscribe/AEszu-rTKTbD_dbwdl-GnYSYc9Sh1Wbxks5qNsicgaJpZM4GHlcZ.

@StreakyCobra
Copy link
Contributor

You may try to set dotspacemacs-folding-method to 'origami on the develop branch. It has been reported to work better than evil's one.

@mrkgnao
Copy link

mrkgnao commented Oct 22, 2016

@StreakyCobra doing that gives me a symbol's value as variable is void: p for some reason.

@TheBB
Copy link
Contributor

TheBB commented Oct 24, 2016

Show us your code please.

@cataclysmic
Copy link

cataclysmic commented Oct 24, 2016

Not sure if you meant me but here:

;;* Folding  in LaTeX
  (add-hook 'LaTeX-mode-hook 'outline-minor-mode)
  (eval-after-load 'outline
  '(progn
   (require 'outline-magic)
   (define-key outline-minor-mode-map (kbd "<tab>") 'outline-cycle)))

   ;;* Folding in R
    (add-hook 'ess-mode-hook
        '(lambda ()
           (outline-minor-mode)
           (setq outline-regexp "[*#]+")
           ))
  (eval-after-load 'outline
    '(progn
   (require 'outline-magic)
   (define-key outline-minor-mode-map (kbd "<tab>") 'outline-cycle)))

In the code it looks like:

 # First level fold
 .....
 ## Second level fold
 ....
 ### third level fold
 .....

`

@challsted
Copy link

challsted commented Nov 22, 2016

@mrkgnao I just started learning to edit my .spacemacs file about 2 days ago, and was having this very error appear when i made a change to dotspacemacs-line-numbers. I found out my issue was that i was missing a single quote before the word you add to the end.

Example of what i was doing (wrong):
dotspacemacs-line-numbers relative

Example of what I had to change it to to make it work (correct):
dotspacemacs-line-numbers 'relative (the extra ' at the beginning of the word made that error go away for me. Hopefully it will do the same for you.

@cataclysmic do you have a sample of what you used to fold your tripple braces? ({{{/}}}). I maintain a dotfiles repo which includes a .vimrc and init.vim (neovim's vimrc equivilent) and would love to edit them in emacs too :), but its quite annoying editing a very long file with no manual folds set when they dont fold.

EDIT: Well digging into it more, it seems that evil-vimish-fold has been incorporated into spacemacs, i was able to use zc to close all of my manual folding points, and tested a close and reopen of the file keeps the folds closed, which looks a lot nicer 👍

@nixmaniack
Copy link
Contributor

@challsted Take a look at dotspacemacs-folding-method for more information. You have two options 'origami which looks more matured as compared to 'evil which is default. YMMV.

@costa
Copy link

costa commented Jun 18, 2019

I hope someone within the project will look into this soon, since it's the only feature of Spacemacs that I'm currently missing — coming from me after several years of usage, it's incredible.

I'm particularly interested in this for Ruby DSLs (this may be helpful: https://gist.github.com/littlemove/5c55dfe0bb724f4420c0).

@costa
Copy link

costa commented Jun 18, 2019

I'm actually not sure about "Vim-style" folding; I will be absolutely happy with a kinda org minor mode (for Ruby or whatever), with functionality like dragging blocks/methods etc.

@github-actions
Copy link

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Please let us know if this issue is still valid!

@github-actions github-actions bot added the stale marked as a stale issue/pr (usually by a bot) label Jun 17, 2020
@Kazark
Copy link
Contributor

Kazark commented Oct 14, 2020

I've attempted to integrate evil-vimish-fold: #14047

@duianto
Copy link
Contributor

duianto commented Oct 17, 2020

The following PRs changes have been applied to the develop branch:
[editing] Integrate evil-vimish-fold via dotspacemacs-folding-method #14047

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement ☺ Fixed in develop stale marked as a stale issue/pr (usually by a bot)
Projects
None yet
Development

No branches or pull requests