Emacs自定义配置(一):智能复制行,未选定时注释当前行,Copy后智能缩进

来源:互联网 发布:2016上海程序员工资 编辑:程序博客网 时间:2024/06/07 03:38

把下面的代码写入到~/.emacs文件中

;;=====================================================================;;Copy代码段后自动格式化;;=====================================================================(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))))));;=====================================================================;;只能COPY,M+k复制当前行;;=====================================================================(defadvice kill-line (before check-position activate)  (if (member major-mode              '(emacs-lisp-mode scheme-mode lisp-mode                                c-mode c++-mode objc-mode js-mode                                latex-mode plain-tex-mode))      (if (and (eolp) (not (bolp)))          (progn (forward-char 1)                 (just-one-space 0)                 (backward-char 1))))) (defadvice kill-ring-save (before slick-copy activate compile)  "When called interactively with no active region, copy a single line instead."  (interactive (if mark-active (list (region-beginning) (region-end))                 (message "Copied line")                 (list (line-beginning-position)                       (line-beginning-position 2))))) (defadvice kill-region (before slick-cut activate compile)  "When called interactively with no active region, kill a single line instead."  (interactive   (if mark-active (list (region-beginning) (region-end))     (list (line-beginning-position)           (line-beginning-position 2))))) ;; Copy line from point to the end, exclude the line break(defun qiang-copy-line (arg)  "Copy lines (as many as prefix argument) in the kill ring"  (interactive "p")  (kill-ring-save (point)                  (line-end-position))                  ;; (line-beginning-position (+ 1 arg)))  (message "%d line%s copied" arg (if (= 1 arg) "" "s"))) (global-set-key (kbd "M-k") 'qiang-copy-line);;=====================================================================;;注释当前行"M+;";;=====================================================================(defun qiang-comment-dwim-line (&optional arg)  "Replacement for the comment-dwim command.If no region is selected and current line is not blank and we are not at the end of the line,then comment current line.Replaces default behaviour of comment-dwim, when it inserts comment at the end of the line."  (interactive "*P")  (comment-normalize-vars)  (if (and (not (region-active-p)) (not (looking-at "[ \t]*$")))      (comment-or-uncomment-region (line-beginning-position) (line-end-position))    (comment-dwim arg)))(global-set-key "\M-;" 'qiang-comment-dwim-line)


0 0
原创粉丝点击