你能在Emacs中拥有智能行为吗?通过智能我的意思是,它不应该转到字符编号0,而应该转到第一个非空白字符,然后在第二次按下时转到0,在第三个按下转到第一个非空白,依此类推.拥有聪明的结局也会很好.
cjm*_*cjm 60
(defun smart-beginning-of-line ()
"Move point to first non-whitespace character or beginning-of-line.
Move point to the first non-whitespace character on this line.
If point was already at that position, move point to beginning of line."
(interactive "^") ; Use (interactive) in Emacs 22 or older
(let ((oldpos (point)))
(back-to-indentation)
(and (= oldpos (point))
(beginning-of-line))))
(global-set-key [home] 'smart-beginning-of-line)
Run Code Online (Sandbox Code Playgroud)
我不太确定聪明的结局会做什么.你通常有很多尾随空格吗?
注意:这个函数和RobertVuković之间的主要区别在于,即使光标已经存在,他总是会移动到第一个按键上的第一个非空白字符.在这种情况下,我将移至第0列.
此外,他使用(beginning-of-line-text)我使用的地方(back-to-indentation).这些非常相似,但它们之间存在一些差异. (back-to-indentation)始终移动到一行上的第一个非空白字符. (beginning-of-line-text)有时会移动它认为无关紧要的非空白字符.例如,在仅注释行上,它移动到注释文本的第一个字符,而不是注释标记.但是,根据您喜欢的行为,可以在我们的任何一个答案中使用任一函数.
Rob*_*vić 12
这适用于GNU Emacs,我没有尝试使用XEmacs.
(defun My-smart-home () "Odd home to beginning of line, even home to beginning of text/code."
(interactive)
(if (and (eq last-command 'My-smart-home)
(/= (line-beginning-position) (point)))
(beginning-of-line)
(beginning-of-line-text))
)
(global-set-key [home] 'My-smart-home)
Run Code Online (Sandbox Code Playgroud)
小智 6
感谢这个方便的功能.我现在一直使用它并喜欢它.我只做了一个小改动:(交互式)成为:(交互式"^")
从emacs帮助:如果字符串以^' andshift-select-mode 开头'是非零的,则Emacs首先调用函数`handle-shift-select'.
基本上,如果使用shift-select-mode,这会使shift-home从当前位置选择到行的开头.它在迷你缓冲器中特别有用.
| 归档时间: |
|
| 查看次数: |
3282 次 |
| 最近记录: |