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

Open all sections in indirect buffers #48

Closed
blaenk opened this issue Sep 18, 2017 · 7 comments · Fixed by #63
Closed

Open all sections in indirect buffers #48

blaenk opened this issue Sep 18, 2017 · 7 comments · Fixed by #63
Milestone

Comments

@blaenk
Copy link

blaenk commented Sep 18, 2017

Following up with #47, it might be cool if there were a command which would automatically open each and every section in its own indirect buffer + window, by-default laid out vertically in the order in which they appear in the .vue file. So it would behave something like this:

  1. you open a buffer that has vue-mode on
  2. M-x vue-mode-edit-all-sections (or whatever)
  3. window configuration is saved, as we will be taking over the frame (perhaps this can be an option), so the user can restore it manually via e.g. winner-mode or perhaps via some vue-mode-stop-editing-all-sections command
  4. delete all windows in the frame, then open one for each edit-indirect buffer opened for each section in the .vue file, in the order in which they appear in the .vue file.

This would more or less resemble the way a .vue file itself looks, but with the added benefit of using a more appropriate major mode for each.

Some unanswered questions and possible difficulties:

  1. I'm not sure if it's possible to open more than one edit-indirect buffer off of the same buffer.
  2. edit-indirect's behavior is that the changes aren't "committed" until the user commits them (e.g. via C-c C-c), which IIRC automatically closes the buffer (and window too I think). This would not be what we would want. We would like each buffer to remain open and otherwise work like "normal" files, so we can probably remap save-buffer to commit the changes, without closing the buffer. It seems like closing the buffer and window is done in edit-indirect--clean-up and seems to be mostly superficial, meaning if we omit that call everything might work fine, but it'll require some more investigating.

So depending on those two questions, it may require some changes to edit-indirect. The functionality behind edit-indirect appears to be pretty simple, from a cursory skim. It seems like the bulk of the code is mainly for making it generalized, i.e. to work in a variety of situations. It may be possible and even desirable to extract the core functionality in order to customize it to vue-mode's liking, if the way it exists now is not flexible to vue-mode's needs, or perhaps it can be worked out with edit-indirect to adapt any changes required.

@AdamNiederer
Copy link
Owner

I really like this idea. I don't think edit-indirect has the ability to save a buffer without closing it, but modifying it to do so should be pretty easy. Combined with something like golden-ratio-mode, it could make editing vue files a lot more ergonomic for people who don't care about full-buffer continuity (I'm thinking about grepping for classes or something whlie in the templates).

Perhaps narrowing the overarching vue-mode buffer and using it as a navigation TUI or overview of sorts would also be helpful in this case. I'll have to investigate that.

I'll definitely look into it soon; probably some time this weekend. Having that feature would probably make my work more productive as well.

@mimischi
Copy link

Do these changes actually mean, that we could start using js-mode2 instead of js-mode if this enables the project to get rid of mmm-mode?

@blaenk
Copy link
Author

blaenk commented Sep 19, 2017

This particular feature, which would be an extension of what has already been implemented in #47 , basically lets you create a buffer from a .vue section. So, since it's its own entirely separate buffer, you can set whatever mode you like, including js2-mode, just as you could with any other buffer, and "saving" any changes you make are automatically reflected in the overall .vue file's corresponding section.

mmm-mode is mainly (AFAIK) for fontifying (syntax highlighting) a region of a buffer with the fontification rules of another mode. In my experience when I have tried using js2-mode for this purpose it doesn't work very well. I think js2-mode is much more complex and does require its own buffer in order to be fully operational. This is something I found when trying to use js2-mode for highlighting regions within a markdown buffer, so I reverted to using js-mode.

So the best of both worlds, @AdamNiederer , would be to allow the user to specify the mode to use to highlight (fontify) sections in the .vue file (e.g. plain js-mode) and the mode to use when "edit-indirect"ing. Most of the time these would be equal so it should be made ergonomic towards specifying a single mode for both, but there are indeed circumstances when we would like to have them differ, such as using html-mode for region highlighting and web-mode for edit-indirect.

This is also something that concerns markdown-mode, so look at this issue for more information.

@AdamNiederer
Copy link
Owner

mmm-mode provides a little more than just fontification; it also gives you indentation and lets you use the keybindings of the underlying mode, which I wouldn't like to give up in the overview. I've been editing vue files with the "overview mode" for a while, and it's definitely much better than what only fontification would offer.

markdown-mode and org-mode don't let you use syntactic indentation and the submode's keybindings without opening an indirect buffer. If/when I do implement this method of editing vue files, I'll look into the costs/benefits of disabling mmm-mode in the overview buffer while this is active.

@AdamNiederer AdamNiederer mentioned this issue Sep 19, 2017
@blaenk
Copy link
Author

blaenk commented Sep 19, 2017

Fair enough, that's good to know.

Even so, I think it would be very very useful, arguably necessary, to be able to specify one mode to use in the overview mode and another to use in the indirect buffer. I haven't tried js2-mode in the overview mode, but it seems like @mimischi is hinting that it doesn't work very well, which is why I would (and do, in markdown-mode) use js-mode in the overview mode, but I definitely would want to use js2-mode in the indirect buffer.

Maybe if you allowed an optional :indirect property in the vue-modes option which is used for the indirect buffer if set, otherwise it would use the :mode's value for both.

@AdamNiederer
Copy link
Owner

AdamNiederer commented Sep 19, 2017

I definitely think having a seperate mode mapping for indirect modes is a good idea; we could also use sass-mode in indirect buffers insteead of my mmm-friendly clone of it. I'm not sure whether js2 should be the default for javascript in an indirect buffer, but users should definitely be able to customize it.

@blaenk
Copy link
Author

blaenk commented Sep 19, 2017

Oh yeah, with respect to js2-mode I was speaking for me personally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants