emacs 高级的 复制 剪切 粘贴

;;


(defun my-copy-lines(num)
  (point-to-register 0)
  (beginning-of-line)
  (let ((begin-point (point)))
    (forward-line num)
    (copy-region-as-kill begin-point (point)))
  (jump-to-register 0) )
;;功能
;;
(defun opt-region-or-whole-line(opt-type   arg)
  "提供高级的复制 剪切功能
"
  (if (string= opt-type "copy")
      (setq do-region-func 'copy-region-as-kill do-line-func  'my-copy-lines  )
    (setq do-region-func 'kill-region do-line-func  'kill-whole-line  )
    )
  (if (and  mark-active (not  (= (region-beginning) (region-end) )))
      (if (string-match "\n"
            (buffer-substring-no-properties (region-beginning)(region-end)))
      (progn
        (if (string= opt-type "copy" ) (point-to-register 0))
        (setq reg-begin-pos (region-beginning))
        (setq reg-end-pos (region-end))
        (forward-char (- reg-begin-pos (point) ))
        (beginning-of-line)
        (setq  start-pos  (point))
        (forward-char (- reg-end-pos (point) ))  ;;------
        (end-of-line)
        (setq  end-pos  (point))
        (setq  end-pos  (if (= (point) (point-max) ) (point-max) (+ (point) 1 ) ))
        (funcall do-region-func start-pos end-pos )
        (if (string= opt-type "copy" ) (jump-to-register 0))
        ) ;-----------
        (funcall do-region-func (region-beginning) (region-end) ))
    (progn
      (or arg (setq arg 1))
      (message "%s line :%d"  opt-type arg)
      (funcall do-line-func arg))))

;;;###autoload
(defun copy-region-or-whole-line(&optional arg)
  "有选择区域时:
        1:复制的内容是跨行的:复制区域所在的所有行的内容。不仅仅是区域内的内容
        2:复制的内容没有跨行:复制区域中的内内容
   没有选择区域时:
        1:复制所在的行
        2:支持复制多行.  如 复制3行是  M-3 C-w  
"
  (interactive "P")
  (opt-region-or-whole-line "copy" arg)
  )

;;;###autoload
(defun kill-region-or-whole-line(&optional arg)
  "有选择区域时:
        1:剪切的内容是跨行的:剪切区域所在的所有行的内容。不仅仅是区域内的内容
        2:剪切的内容没有跨行:剪切区域中的内内容
   没有选择区域时:
        1:剪切所在的行
        2:支持剪切多行.  如 剪切3行是  M-3 C-k
"
  (interactive "P")
  (opt-region-or-whole-line "kill" arg))


(defun begin-line-and-yank ( arg)
  "如果复制的是跨行的数据由跳到行首,再yank"
  (interactive "P")
  (if (string-match "\n" (current-kill 0 )) (move-beginning-of-line 1))
  (yank ))

(global-set-key (kbd "C-y") 'begin-line-and-yank)
(global-set-key (kbd "C-k") 'kill-region-or-whole-line )
(global-set-key "\C-w" 'copy-region-or-whole-line)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值