emacs中M-- C-k有bug ?

Vim、Emacs配置和使用
回复
iaagssphinx
帖子: 20
注册时间: 2010-12-19 16:04

emacs中M-- C-k有bug ?

#1

帖子 iaagssphinx » 2011-07-04 17:25

M--(Meta和-)在emacs中是对操作取反的意思,
C-k是删除从光标处到结尾,那M-- C-k应该是删除从光标处到开头吧。
但我在emacs23里操作时,它多删除了一行

hello world1
hello | world2
hello world3

当光标在hello world2中间时执行M-- C-k, 结果是把hello world1也一起删除了。
不知道这是正常的结果还是bug。
如果正常的话该怎么解释M--的作用呢。
头像
tonghuix
帖子: 355
注册时间: 2010-10-08 0:55

Re: emacs中M-- C-k有bug ?

#2

帖子 tonghuix » 2011-07-05 9:45

我也是发现了

谢谢楼主提醒的
/***
* @tonghuix 佟辉 Tong Hui
* @brief 启智开源 编码自由
* @brief Open Source Open Mind, Coding for free!
* @website: https://tonghuix.io
* @weibo http://weibo.com/234826309
* @Twitter http://twitter.com/tonghuix
* @G+ http://gplus.to/tonghuix
*/
deepwhite
帖子: 14
注册时间: 2008-01-15 14:11

Re: emacs中M-- C-k有bug ?

#3

帖子 deepwhite » 2011-07-07 10:49

1. 没有规定 Meta- 就一定要取反,比如 C-a 是到行首,那 M-a 是到行尾么?

2. 按键绑定是由用户设置的(当然也有默认的几个设置),具体来说,到底 M-C-k 是做什么的,应该通过 describe-key-briefly来查看,而不是通过一个 word 的语义来想当然。

尽管很多东西可以通过语义来猜测其作用(比如内核代码中的诸多函数名),但是这些名字毕竟也只是程序员自己写的,一个不好的名字可能不能正确的反应其作用,此外,诸如 Emacs 这种可定制性很强的东西,从按键的 M 或者 C 上,根本没法猜这个按键的功能。
只能通过 describe-key-briefly 来看。
tusooa
帖子: 6548
注册时间: 2008-10-31 22:12
系统: 践兔
联系:

Re: emacs中M-- C-k有bug ?

#4

帖子 tusooa » 2011-07-09 14:49

楼上,lz说的是M--,不是meta.
*Help* 写了:

代码: 全选

M-- runs the command negative-argument, which is an interactive compiled Lisp function in
`simple.el'.

It is bound to C--, M--, C-M--.

(negative-argument ARG)

Begin a negative numeric argument for the next command.
C-u following digits or minus sign ends the argument.
不过没用过M-- C-k

代码: 全选

] ls -ld //
deepwhite
帖子: 14
注册时间: 2008-01-15 14:11

Re: emacs中M-- C-k有bug ?

#5

帖子 deepwhite » 2011-07-11 9:42

tusooa 写了:楼上,lz说的是M--,不是meta.
*Help* 写了:

代码: 全选

M-- runs the command negative-argument, which is an interactive compiled Lisp function in
`simple.el'.

It is bound to C--, M--, C-M--.

(negative-argument ARG)

Begin a negative numeric argument for the next command.
C-u following digits or minus sign ends the argument.
不过没用过M-- C-k
嗯。我看错了……
datura
帖子: 102
注册时间: 2007-01-19 12:46

Re: emacs中M-- C-k有bug ?

#6

帖子 datura » 2011-07-11 17:02

偶这里没有这个bug
头像
flyli
帖子: 26
注册时间: 2007-11-20 19:28
来自: 四川绵阳

Re: emacs中M-- C-k有bug ?

#7

帖子 flyli » 2012-02-10 17:37

iaagssphinx 写了:M--(Meta和-)在emacs中是对操作取反的意思,
C-k是删除从光标处到结尾,那M-- C-k应该是删除从光标处到开头吧。
但我在emacs23里操作时,它多删除了一行

hello world1
hello | world2
hello world3

当光标在hello world2中间时执行M-- C-k, 结果是把hello world1也一起删除了。
不知道这是正常的结果还是bug。
如果正常的话该怎么解释M--的作用呢。
呵呵,今天我也遇到这个问题了,网上查了很久,发现只有这里有人回答这个问题,
后来我翻阅了emacs的帮助系统,终于解决了这个问题,于是到这里来同你分享下
发现 M--其实并不是取反的意思(也有点这方面意思)
M--和M-0 M-1 M-2是一个意思
M--最后的那个-其实是一个负号的意思
比如M-- 1 C-k同你的运行结果是一样的
而 M-- 0 C-k其实才是你想要的结果
而M-- 8 C-k这条命令你试下的话,就会返现他会删除你的后8行,以此类推~
学习,永无止境
头像
josephyoung
帖子: 158
注册时间: 2011-11-05 18:53
来自: 南极圈

Re: emacs中M-- C-k有bug ?

#8

帖子 josephyoung » 2012-02-10 20:14

要高清楚这个问题可能首先得搞清楚C-k的工作原理
头像
josephyoung
帖子: 158
注册时间: 2011-11-05 18:53
来自: 南极圈

Re: emacs中M-- C-k有bug ?

#9

帖子 josephyoung » 2012-02-10 20:26

C-k runs the command kill-line, which is an interactive compiled Lisp
function in `simple.el'.

It is bound to C-k, <deleteline>.

(kill-line &optional ARG)

Kill the rest of the current line; if no nonblanks there, kill thru newline.
With prefix argument ARG, kill that many lines from point.
Negative arguments kill lines backward.
With zero argument, kills the text before point on the current line.
结合M--的介绍,M-- C-k就应该是传了负参数给C-k,应该是-1
在emacs输入C-u -1 M-x kill-line, 行为与M-- C-k表现一致,可见M--默认就是传递-1给后面的命令
请仔细看4楼引用的M--的介绍的倒数第二行---“M--传递一个负的数字参数给下一个命令”,所以M--的命令执行方式与简单的对操作取反是有区别的
回复