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

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

问题描述

你能在 Emacs 中为 home 键设置智能行为吗?聪明我的意思是,不是转到字符编号 0,而是应该转到第一个非空白字符,然后在第二次按下时转到 0,在第三次按下时返回到第一个非空白字符,依此类推.有聪明的结局也会很好.

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?

注意:此功能与 Robert Vuković 的主要区别在于,即使光标已经在第一次按键时,他也始终移动到第一个非空白字符.在这种情况下,我的将移动到第 0 列.

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.

此外,他使用了(beginning-of-line-text),而我使用了(back-to-indentation).它们非常相似,但它们之间存在一些差异.(back-to-indentation) 总是移动到一行的第一个非空白字符.(beginning-of-line-text) 有时会移过它认为无关紧要的非空白字符.例如,在仅注释行上,它移动到注释文本的第一个字符,而不是注释标记.但是,这两个函数都可以用于我们的任一答案中,具体取决于您喜欢哪种行为.

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天全站免登陆