【问题标题】:How to do an invert selection in emacs?如何在emacs中进行反转选择?
【发布时间】:2015-03-11 13:04:56
【问题描述】:

我目前选择了一个文本区域。我想杀死/拉动(或以任何其他方式格式化)除所选区域之外的整个缓冲区。有什么方法可以在 emacs 中进行反转选择并完成相同的操作吗?

【问题讨论】:

    标签: emacs textselection


    【解决方案1】:
    1. C-w kill-region 中间的文字。
    2. C-x h mark-whole-buffer 剩下的文字。
    3. 做你的事。
    4. C-y yank 中间文字。

    【讨论】:

    • 但是例如,一旦文本的其余部分被杀死,那么kill ring 不会受到影响吗?那么第 4 步可能不会产生预期的结果。
    • 然后使用M-y。这是一枚戒指,它可以容纳不止一个杀戮。
    【解决方案2】:
    (defun my-copy-inverted-region-as-kill (beginning end)
      "Copy to the kill ring everything except the marked region."
      (interactive "r")
      (let ((srcbuf (current-buffer))
            (offset (point-min)))
        (with-temp-buffer
          (insert-buffer-substring srcbuf)
          (delete-region (- beginning offset) (- end offset))
          (copy-region-as-kill (point-min) (point-max)))))
    

    【讨论】:

      【解决方案3】:

      不能存在非连续区域。 但是,这会将相反的命令放在 C-c DEL

      (global-set-key "\^C\^?"        ; help edit mail files, etc.
              (defun erase-buffer-except-region (beg end)
                "Erase the buffer except for the region."
                (interactive "r")
                (when (< end beg)
                  (cl-rotatef beg end))
                (delete-region end (point-max))
                (delete-region (point-min) beg)))
      

      【讨论】:

      • 也许突出显示库应该让您删除或保留突出显示的区域,这些区域可以是不连续的。
      猜你喜欢
      • 2021-10-01
      • 2011-12-03
      • 1970-01-01
      • 1970-01-01
      • 2022-11-11
      • 1970-01-01
      • 2021-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多