在emacs中移动区域或行 [英] Shift a region or line in emacs

查看:122
本文介绍了在emacs中移动区域或行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方式,通过 n 空格将文本向右或向左移动。在vim >> 中类似的功能。它应该在一个区域上工作,或者如果当前行没有选择区域,并且不将光标从当前位置移动。

I'm looking for a way in emacs to shift text to the right or to the left by n spaces. A similar functionality that it in vim << or >>. It should work on a region or if no region is selected on a current line and not move the cursor from its current location.

EmacsWiki 因为 Mx indent-rigidly 不起作用,因为它有点记得最后一个地区的使用和转移。最近似乎是一个这里,但我没有设法使它工作我不是一个lisp开发人员,所以很难修改代码。我会感谢任何帮助。

The solution from EmacsWiki does not work very well as the M-x indent-rigidly since it somewhat remembers the last region used and shifts that one instead. The closest seems to be the one here but I did not managed to make it work. I'm not a lisp developer so it's difficult to modify the code. I will appreciate any help.

谢谢!

推荐答案

也许这


(defun shift-text (distance)
  (if (use-region-p)
      (let ((mark (mark)))
        (save-excursion
          (indent-rigidly (region-beginning)
                          (region-end)
                          distance)
          (push-mark mark t t)
          (setq deactivate-mark nil)))
    (indent-rigidly (line-beginning-position)
                    (line-end-position)
                    distance)))

(defun shift-right (count)
  (interactive "p")
  (shift-text count))

(defun shift-left (count)
  (interactive "p")
  (shift-text (- count)))

这篇关于在emacs中移动区域或行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆