Shift a region or line in emacs

前端 未结 3 1169
轻奢々
轻奢々 2021-02-02 17:04

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 >>

3条回答
  •  孤城傲影
    2021-02-02 17:40

    Maybe this works the way you want.

    (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)))
    

提交回复
热议问题