拷貝代碼自動格式化

拷貝代碼自動格式化python

Emacs 裏對代碼的格式化支持的很是好,不但能夠在編輯的時候自動幫你格式化,還能夠選中一塊代碼,按 Ctrl-Alt-\ 對這塊代碼從新進行格式化。若是要粘貼一塊代碼的話,粘貼完了緊接着按 Ctrl-Alt-\ 就能夠把新加入的代碼格式化好。但是,對於這種粘貼加上從新格式化的機械操做,Emacs 應該能夠將它自動化才能配得上它的名氣,把下面的代碼加到配置文件裏,你的 Emacs 就會擁有這種能力了c++

(dolist (command '(yank yank-pop))
  (eval
   `(defadvice ,command (after indent-region activate)
      (and (not current-prefix-arg)
           (member major-mode
                   '(emacs-lisp-mode
                     lisp-mode
                     clojure-mode
                     scheme-mode
                     haskell-mode
                     ruby-mode
                     rspec-mode
                     python-mode
                     c-mode
                     c++-mode
                     objc-mode
                     latex-mode
                     js-mode
                     plain-tex-mode))
           (let ((mark-even-if-inactive transient-mark-mode))
             (indent-region (region-beginning) (region-end) nil))))))
相關文章
相關標籤/搜索