Tweak auto-indent on yank advice
This commit is contained in:
parent
fc3ad64579
commit
5edc8a842f
|
@ -14,34 +14,31 @@
|
||||||
([remap mark-sexp] . easy-mark))
|
([remap mark-sexp] . easy-mark))
|
||||||
|
|
||||||
(use-package emacs
|
(use-package emacs
|
||||||
:config
|
:hook
|
||||||
(defadvice exchange-point-and-mark (before deactivate-mark activate compile)
|
(emacs-startup . (lambda ()
|
||||||
"When called with no active region, do not activate mark."
|
;; Based on code in prelude-editor.el
|
||||||
(interactive
|
(defun yank-advised-indent-function (beg end)
|
||||||
(list (not (region-active-p)))))
|
"Do indentation, as long as the region isn't too large."
|
||||||
|
(if (<= (- end beg) 10000)
|
||||||
|
(indent-region beg end nil)))
|
||||||
|
|
||||||
(defun yank-advised-indent-function (beg end)
|
(defmacro advise-commands (advice-name commands class &rest body)
|
||||||
"Do indentation, as long as the region isn't too large."
|
"Apply advice named ADVICE-NAME to multiple COMMANDS.
|
||||||
(if (<= (- end beg) 1000)
|
|
||||||
(indent-region beg end nil)))
|
|
||||||
|
|
||||||
(defmacro advise-commands (advice-name commands class &rest body)
|
|
||||||
"Apply advice named ADVICE-NAME to multiple COMMANDS.
|
|
||||||
|
|
||||||
The body of the advice is in BODY."
|
The body of the advice is in BODY."
|
||||||
`(progn
|
`(progn
|
||||||
,@(mapcar (lambda (command)
|
,@(mapcar (lambda (command)
|
||||||
`(defadvice ,command (,class ,(intern (concat (symbol-name command) "-" advice-name)) activate)
|
`(defadvice ,command (,class ,(intern (concat (symbol-name command) "-" advice-name)) activate)
|
||||||
,@body))
|
,@body))
|
||||||
commands)))
|
commands)))
|
||||||
|
|
||||||
(advise-commands "indent" (yank yank-pop) after
|
(advise-commands "indent" (yank yank-pop) after
|
||||||
(if (and (not (ad-get-arg 0))
|
(if (and (not (ad-get-arg 0))
|
||||||
(not (member major-mode '(conf-mode coffee-mode haml-mode python-mode slim-mode yaml-mode)))
|
(not (member major-mode '(conf-mode coffee-mode haml-mode python-mode slim-mode yaml-mode)))
|
||||||
(or (derived-mode-p 'prog-mode)
|
(or (derived-mode-p 'prog-mode)
|
||||||
(member major-mode '(LaTeX-mode TeX-mode))))
|
(member major-mode '(LaTeX-mode TeX-mode))))
|
||||||
(let ((transient-mark-mode nil))
|
(let ((transient-mark-mode nil))
|
||||||
(yank-advised-indent-function (region-beginning) (region-end))))))
|
(yank-advised-indent-function (region-beginning) (region-end))))))))
|
||||||
|
|
||||||
(provide 'init-kill)
|
(provide 'init-kill)
|
||||||
;;; init-kill.el ends here
|
;;; init-kill.el ends here
|
||||||
|
|
Loading…
Reference in New Issue