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
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions mmm-auto.el
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ positive and off otherwise." t))
(autoload 'mmm-end-current-region "mmm-cmds" "" t)
(autoload 'mmm-insertion-help "mmm-cmds" "" t)
(autoload 'mmm-insert-region "mmm-cmds" "" t)
(autoload 'mmm-indent-region "mmm-cmds" "" t)
(autoload 'mmm-indent-line-narrowed "mmm-cmds" "" t)

;;}}}
;;{{{ MMM Global Mode
Expand Down
37 changes: 37 additions & 0 deletions mmm-cmds.el
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,43 @@ NAME is a symbol naming the insertion."

;;}}}

;;{{{ Indentation helpers

(defun mmm-indent-line-narrowed ()
"An indent function which works on some modes where `mmm-indent-line' doesn't.
Works like `mmm-indent-line', but narrows the buffer before indenting to
appease modes which rely on constructs like (point-min) to indent."
(interactive)
(mmm-update-submode-region)
(if mmm-current-overlay
(save-restriction
(mmm-narrow-to-submode-region)
(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 from START to END according to `mmm-indent-line-function'.
Then, indent all submodes overlapping the region according to
`mmm-indent-line-function'"
(interactive)
(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)))))

;;}}}

;;{{{ Auto Insertion (copied from interactive session);-COM-
;-COM-
;-COM-;; Don't use `mmm-ify-region' of course. And rather than having
Expand Down
22 changes: 0 additions & 22 deletions mmm-region.el
Original file line number Diff line number Diff line change
Expand Up @@ -871,28 +871,6 @@ This will be the value of `indent-line-function' for the whole
buffer. It's supposed to delegate to the appropriate submode's
indentation function. See `mmm-indent-line' as the starting point.")

(defun mmm-indent-line-narrowed ()
"An indent function which works on some modes where `mmm-indent-line' doesn't.
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)))))

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