Remove duplication advice of yank and yank-pop

This commit is contained in:
toctan 2014-06-25 10:17:37 +08:00
parent 491bc0617f
commit 3ac1cc8f00

View file

@ -155,19 +155,20 @@
(file-writable-p buffer-file-name)) (file-writable-p buffer-file-name))
(save-buffer))) (save-buffer)))
(defmacro advise-commands (advice-name commands &rest body) (defmacro advise-commands (advice-name commands class &rest body)
"Apply advice named ADVICE-NAME to multiple COMMANDS. "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 (before ,(intern (concat (symbol-name command) "-" advice-name)) activate) `(defadvice ,command (,class ,(intern (concat (symbol-name command) "-" advice-name)) activate)
,@body)) ,@body))
commands))) commands)))
;; advise all window switching functions ;; advise all window switching functions
(advise-commands "auto-save" (advise-commands "auto-save"
(switch-to-buffer other-window windmove-up windmove-down windmove-left windmove-right) (switch-to-buffer other-window windmove-up windmove-down windmove-left windmove-right)
before
(prelude-auto-save-command)) (prelude-auto-save-command))
(add-hook 'mouse-leave-buffer-hook 'prelude-auto-save-command) (add-hook 'mouse-leave-buffer-hook 'prelude-auto-save-command)
@ -302,8 +303,8 @@ The body of the advice is in BODY."
(if (<= (- end beg) prelude-yank-indent-threshold) (if (<= (- end beg) prelude-yank-indent-threshold)
(indent-region beg end nil))) (indent-region beg end nil)))
(defadvice yank (after yank-indent activate) (advise-commands "indent" (yank yank-pop) after
"If current mode is one of 'prelude-yank-indent-modes, "If current mode is one of `prelude-yank-indent-modes',
indent yanked text (with prefix arg don't indent)." indent yanked text (with prefix arg don't indent)."
(if (and (not (ad-get-arg 0)) (if (and (not (ad-get-arg 0))
(not (member major-mode prelude-indent-sensitive-modes)) (not (member major-mode prelude-indent-sensitive-modes))
@ -312,16 +313,6 @@ indent yanked text (with prefix arg don't indent)."
(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)))))
(defadvice yank-pop (after yank-pop-indent activate)
"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 prelude-indent-sensitive-modes))
(or (derived-mode-p 'prog-mode)
(member major-mode prelude-yank-indent-modes)))
(let ((transient-mark-mode nil))
(yank-advised-indent-function (region-beginning) (region-end)))))
;; abbrev config ;; abbrev config
(add-hook 'text-mode-hook 'abbrev-mode) (add-hook 'text-mode-hook 'abbrev-mode)