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

Add mmm-indent-region #75

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 28 additions & 16 deletions mmm-region.el
Original file line number Diff line number Diff line change
Expand Up @@ -876,22 +876,34 @@ indentation function. See `mmm-indent-line' as the starting point.")
Works like `mmm-indent-line', but narrows the buffer before indenting to
appease modes which rely on constructs like (point-min) to indent."
(interactive)
(funcall
(save-excursion
(back-to-indentation)
(mmm-update-submode-region)
(let ((indent-function (get
(if (and mmm-current-overlay
(> (overlay-end mmm-current-overlay) (point)))
mmm-current-submode
mmm-primary-mode)
'mmm-indent-line-function)))
(if mmm-current-overlay
(save-restriction
(narrow-to-region (overlay-start mmm-current-overlay)
(overlay-end mmm-current-overlay))
indent-function)
indent-function)))))
(if mmm-current-overlay
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But mmm-current-overlay can be outdated, can't it?

That's why we call mmm-update-submode-region down there.

(save-excursion
(back-to-indentation)
(mmm-update-submode-region)
(save-restriction
(narrow-to-region (overlay-start mmm-current-overlay)
(overlay-end mmm-current-overlay))
(funcall (get
(if (and mmm-current-overlay
(> (overlay-end mmm-current-overlay) (point)))
mmm-current-submode
mmm-primary-mode)
'mmm-indent-line-function))))
(mmm-indent-line)))

(defun mmm-indent-region (start end)
"Indent the region according to `mmm-indent-line-function', then indent all
submodes overlapping the region according to `mmm-indent-line-function'"
(save-excursion
(while (< (point) end)
(indent-according-to-mode)
(forward-line 1))
;; Indent each submode in the region seperately
(dolist (submode (mmm-overlays-overlapping start end))
(goto-char (overlay-start submode))
(while (< (point) (min end (overlay-end submode)))
(indent-according-to-mode)
(forward-line 1)))))

(defun mmm-indent-line ()
(interactive)
Expand Down