通用右对齐功能 [英] Generic right-align function
本文介绍了通用右对齐功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
现在我知道如何在Emacs中右对齐数值列,我有这个解决方案的两个问题
Now that I know how to right-align columns of numeric values in Emacs, I have two issues with this solution:
- 很难记住
- 它不灵活
例如,当第一列中的某些值包含一个数字时,它不起作用。
For instance, it doesn't work when some of the values in the first column contains a number.
不幸的是它插入标签。
现在我使用矩形函数( Cx r / kbd>)相当多。这让我想起来:是否可以使用一个函数来对齐所选矩形中的所有文本?
Now I use rectangle functions (C-xrk) quite a lot. That made me think: would it be possible to have a function that right-aligns all text in the selected rectangle?
推荐答案
(defun right-justify-rectangle (start end)
(interactive "r")
(apply-on-rectangle (lambda (c0 c1)
(move-to-column c1 t)
(let ((start (- (point) (- c1 c0)))
(end (point)))
(when (re-search-backward "\\S-" start t)
(transpose-regions start (match-end 0)
(match-end 0) end))))
start end))
为避免 Tab ,自定义变量 indent-tabs-mode
。
更合理地处理 indent-tabs-mode
(defun right-justify-rectangle (start end)
(interactive "r")
(let ((indent-tabs-mode nil))
(apply-on-rectangle (lambda (c0 c1)
(move-to-column c1 t)
(let ((start (- (point) (- c1 c0)))
(end (point)))
(when (re-search-backward "\\S-" start t)
(transpose-regions start (match-end 0)
(match-end 0) end))))
start end))
(when indent-tabs-mode (tabify start end)))
这篇关于通用右对齐功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文