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

implement mmm-indent-region #111

Open
stephe-ada-guru opened this issue Jul 14, 2020 · 12 comments
Open

implement mmm-indent-region #111

stephe-ada-guru opened this issue Jul 14, 2020 · 12 comments

Comments

@stephe-ada-guru
Copy link
Contributor

I finally got around to working on mmm-indent-region. Initial patch attached.

One issue is whether we actually need indent-dont-widen, and whether this works for other modes. I've tested with wisitoken-grammar-mode.
mmm-indent-region.patch.txt

@dgutov
Copy link
Owner

dgutov commented Jul 14, 2020

Could you describe the benefits? Performance? Does it change the current behavior?

@stephe-ada-guru
Copy link
Contributor Author

stephe-ada-guru commented Jul 15, 2020

I take it back ; apparently I did not test carefully enough. I have code like:
declaration

  : PERCENT token_keyword_non_grammar IDENTIFIER declaration_item_list
    %((wisi-statement-action [1 statement-start])
      (wisi-name-action 3)
      (wisi-face-apply-action
       [1 nil font-lock-constant-face
          2 nil font-lock-keyword-face
          3 nil font-lock-function-name-face])
      (wisi-indent-action [nil nil nil (wisi-hanging 4 2)]))%

where %()% delimits an elisp submode. I want to keep the initial indent. But when the buffer is narrowed to the submode region, "(wisi-statement-action" is in column zero. In addition, indenting these lines screws up following overlays; they need to be updated after indenting each region.

I'll see if I can fix this.

@stephe-ada-guru
Copy link
Contributor Author

Fixed both problems: updated patch attached. I suspect there should be a user option for "preserve indent of first line".
mmm-indent-region.patch.txt

@dgutov
Copy link
Owner

dgutov commented Jul 15, 2020

He Stephen,

I think you didn't answer my questions. What is the overall goal of this patch?

First of all, indent-region-function shouldn't contradict indent-line-function. If it creates a different indentation behavior, that's a problem. The only thing it's allowed to improve is performance.

Second, if we do choose to improve mmm-indent-line, we should first try to see whether it improves the behavior in different configurations. And hopefully doesn't break others which indent okay currently.

Also see #75 for a similar, yet unfinished, discussion.

@stephe-ada-guru
Copy link
Contributor Author

stephe-ada-guru commented Jul 16, 2020 via email

@dgutov
Copy link
Owner

dgutov commented Jul 17, 2020

The default indent-region-function delegates to indent-line, and
mmm-mode sets indent-line-function, which is why indent-region works in
many modes.

But without this patch, an indent-region-function provided by a major
mode does not respect the submodes.

Thank you, that makes sense.

I have yet to look into this patch in detail, but what about the fact that mmm-indent-line does not do any narrowing?

Your patch includes a call to narrow-to-region inside mmm-indent-region-list. Won't that create different behavior by default?

@stephe-ada-guru
Copy link
Contributor Author

stephe-ada-guru commented Jul 17, 2020 via email

@dgutov
Copy link
Owner

dgutov commented Jul 17, 2020

I was copying mmm-mmm-fontify-region-list, which does narrowing.

Right. But font-lock-keywords and indent-line-function don't have to be 100% consistent. indent-region-function and indent-line-function do.

We actually have an alternative one (mmm-indent-line-function cat be set to mmm-indent-line-narrowed), but the default indent-region-function should be compatible with mmm-indent-line.

I tested with narrow-to-region commented out; that is actually better,

It's probably better in some cases, yet worse in others. That's why, ultimately, major modes can override mmm-indent-line-function too (html-erb-mode sets it to mmm-erb-indent-line, you can take a look). But it's better to be conservative for the default behavior.

@dgutov
Copy link
Owner

dgutov commented Jul 17, 2020

I'll test some more, and post a new patch.

Looking forward to it.

@stephe-ada-guru
Copy link
Contributor Author

Here's an updated patch; it's been working well.
mmm-indent-region.patch.txt

@dgutov
Copy link
Owner

dgutov commented Aug 13, 2020

Hi Stephen, I see you've added a mmm-indent-narrow property, which enabled/disables narrowing.

Even so, the default indent-line-function doesn't use it, right? Doesn't that lead to an incompatibility? We'll need to resolve it, one way or another.

@stephe-ada-guru
Copy link
Contributor Author

stephe-ada-guru commented Aug 13, 2020 via email

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

No branches or pull requests

2 participants