我想在整个文件上运行sort-lines
命令。如何在一系列行上运行emacs命令?
C-XħM-X排序线输入
我需要在运行sort-lines
命令之前标示的区域。
如何跳过C-xh。我可以提供一个参数(如vim中的%
)到sort-lines
命令吗?
我想在整个文件上运行sort-lines
命令。如何在一系列行上运行emacs命令?
C-XħM-X排序线输入
我需要在运行sort-lines
命令之前标示的区域。
如何跳过C-xh。我可以提供一个参数(如vim中的%
)到sort-lines
命令吗?
这里似乎是最简单的解决方案 - 如果没有区域被激活,通过缓冲区的范围,以sort-lines
:
(defun my-sort-lines (reverse begin end)
(interactive "P\nr")
(sort-lines reverse
(if (region-active-p) begin (point-min))
(if (region-active-p) end (point-max))))
我不是专家,但我不相信sort-lines
可以接受行号作为参数。也就是说,编写一个函数来完成这件事不应该很困难。以下是我刚刚入侵的一个快速问题:
(defun my-sort-lines (start end)
(interactive "nStart: \nnEnd: ")
(save-excursion
(save-restriction
(goto-line start)
(mark)
(goto-line (1+ end))
(narrow-to-region (mark) (point))
(sort-lines nil (point-min) (point-max))
(widen))))
从我所做的有限量的测试中,它似乎可行。我相信有一些改进可以做,因为我对emacs lisp的经验很少。