Do not indent region with indent sensitive modes

- Rename and move yank indent vars into prelude-custom.el
- Add coffee-mode to prelude-indent-sensitive-modes
- Do not mess up indentation when cleanup with indentation sensitive
  modes, such as Python.
This commit is contained in:
toctan 2014-06-25 10:03:15 +08:00
parent d226fd63f7
commit 491bc0617f
3 changed files with 26 additions and 20 deletions

View file

@ -273,7 +273,8 @@ there's a region, all lines that region covers will be duplicated."
"Cleanup a region if selected, otherwise the whole buffer."
(interactive)
(call-interactively 'untabify)
(call-interactively 'indent-region)
(unless (member major-mode prelude-indent-sensitive-modes)
(call-interactively 'indent-region))
(whitespace-cleanup))
(defun prelude-eval-and-replace ()

View file

@ -76,6 +76,23 @@ in the desired elisp file."
:type 'string
:group 'prelude)
(defcustom prelude-indent-sensitive-modes
'(coffee-mode python-mode slim-mode haml-mode)
"Modes for which auto-indenting is suppressed."
:type 'list
:group 'prelude)
(defcustom prelude-yank-indent-modes '(LaTeX-mode TeX-mode)
"Modes in which to indent regions that are yanked (or yank-popped).
Only modes that don't derive from `prog-mode' should be listed here."
:type 'list
:group 'prelude)
(defcustom prelude-yank-indent-threshold 1000
"Threshold (# chars) over which indentation does not automatically occur."
:type 'number
:group 'prelude)
(provide 'prelude-custom)
;;; prelude-custom.el ends here

View file

@ -297,40 +297,28 @@ The body of the advice is in BODY."
(with-region-or-buffer untabify)
;; automatically indenting yanked text if in programming-modes
(defvar yank-indent-modes
'(LaTeX-mode TeX-mode)
"Modes in which to indent regions that are yanked (or yank-popped).
Only modes that don't derive from `prog-mode' should be listed here.")
(defvar yank-indent-blacklisted-modes
'(python-mode slim-mode haml-mode)
"Modes for which auto-indenting is suppressed.")
(defvar yank-advised-indent-threshold 1000
"Threshold (# chars) over which indentation does not automatically occur.")
(defun yank-advised-indent-function (beg end)
"Do indentation, as long as the region isn't too large."
(if (<= (- end beg) yank-advised-indent-threshold)
(if (<= (- end beg) prelude-yank-indent-threshold)
(indent-region beg end nil)))
(defadvice yank (after yank-indent activate)
"If current mode is one of 'yank-indent-modes,
"If current mode is one of 'prelude-yank-indent-modes,
indent yanked text (with prefix arg don't indent)."
(if (and (not (ad-get-arg 0))
(not (member major-mode yank-indent-blacklisted-modes))
(not (member major-mode prelude-indent-sensitive-modes))
(or (derived-mode-p 'prog-mode)
(member major-mode yank-indent-modes)))
(member major-mode prelude-yank-indent-modes)))
(let ((transient-mark-mode nil))
(yank-advised-indent-function (region-beginning) (region-end)))))
(defadvice yank-pop (after yank-pop-indent activate)
"If current mode is one of `yank-indent-modes',
"If current mode is one of `prelude-yank-indent-modes',
indent yanked text (with prefix arg don't indent)."
(when (and (not (ad-get-arg 0))
(not (member major-mode yank-indent-blacklisted-modes))
(not (member major-mode prelude-indent-sensitive-modes))
(or (derived-mode-p 'prog-mode)
(member major-mode yank-indent-modes)))
(member major-mode prelude-yank-indent-modes)))
(let ((transient-mark-mode nil))
(yank-advised-indent-function (region-beginning) (region-end)))))