Emacs智能家居 [英] Smart home in Emacs

查看:120
本文介绍了Emacs智能家居的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你可以在Emacs的home键中有智慧的行为吗?智能我的意思是,而不是去角色号码0,它应该去第一个非空白字符,并转到0一秒钟按,然后回到第一个非空白的第三个等等。
聪明的结局也会很好。

解决方案

 (defun smart -beginning-of-line()
将点移动到第一个非空格字符或行首。

将该点移动到此行上的第一个非空格字符。$
(interactive^);在Emacs 22或更旧的
中使用(交互式)(let((oldpos(point) ))
(back-to-indentation)
(和(= oldpos(point))
(begin-of-line))))

global-set-key [home]'smart-beginning-of-line)

我不是相当确定智能端将做什么。你通常会有很多尾随的空白?



注意:这个功能与罗伯特·维科维奇之间的主要区别在于他总是移动到第一个按键上的第一个非空白字符,即使光标已经存在。在这种情况下,我会移动到第0列。



此外,他使用(开始的行文本)我使用(back-to-indentation)。这些都非常相似,但它们之间有一些区别。 (back-to-indentation)总是移动到一行上的第一个非空格字符。 (起始行文本)有时会移动它认为不重要的非空格字符。例如,在仅注释行上,它移动到注释文本的第一个字符,而不是注释标记。但是,根据您喜欢的行为,任一功能都可以用于我们的任何一个答案。


Can you have smart behavior for the home key in Emacs? By smart I mean that instead of going to the character number 0, it should go to the first non-blank character, and go to 0 on a second pressing, and back to the first non-blank in a third and so on. Having smart end would be nice as well.

解决方案

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

I'm not quite sure what smart end would do. Do you normally have a lot of trailing whitespace?

Note: The major difference between this function and Robert Vuković's is that his always moves to the first non-blank character on the first keypress, even if the cursor was already there. Mine would move to column 0 in that case.

Also, he used (beginning-of-line-text) where I used (back-to-indentation). Those are very similar, but there are some differences between them. (back-to-indentation) always moves to the first non-whitespace character on a line. (beginning-of-line-text) sometimes moves past non-whitespace characters that it considers insignificant. For instance, on a comment-only line, it moves to the first character of the comment's text, not the comment marker. But either function could be used in either of our answers, depending on which behavior you prefer.

这篇关于Emacs智能家居的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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