首页 > 其他, 初级 > Emacs中鼠标的运用

Emacs中鼠标的运用

2010年4月6日 ahei 发表评论 阅读评论

作者: 王纯业

默认配置

用鼠标左键 click 一个位置,可以以移动光标到这个位置,这是最基本,也是最自然的功能了。

1
2
(global-set-key (kbd "<mouse-1>") 'mouse-set-point)
(global-set-key (kbd "<down-mouse-1>") 'mouse-drag-region)

这段代码不用放在配置文件中,因为默认配置就是这样。
尽管是默认配置,我还是把他们写出了,因为有的时候我们想改变默认配置。把默认的功能对应到其他的按键方式上去。

鼠标左键的功能

用鼠标选择 region

左键的拖拉,可以选择一片区域,这片选择的region 就自动拷贝起来。以后可以用 C-y 把选择的 region 粘贴出来。此时 down-mouse-1 事件和 mouse-drag-region 帮定在一起。
如果拖拉到窗口的外面,那么会自动滚动窗口中的内容,直到你选择到你要的位置,这样就可以选择到超过一个屏幕范围的内容了。

用鼠标选择一个语法单元

如果 double click 左键,那么就会根据点取位置上的内容,来选择不同的内容。
如果点取的字符是一个 "symbol" 的语法,那么就会选择一个symbol 。 这样说有一些过于技术性的描述了。

我们知道, Emacs 支持很多 mode ,例如 c mode, c++ mode , lisp mode 等等等等, 每一个 mode 都定义不同的语法。 例如lisp mode 下 “-” 可以作为 symbol 的名字,在 c mode 下, “_” 下划线可以作为变量的名字。他们的 如果你双击在这个这样的字符上,那么就会选择整个变量名字。 具体来说,假如是在c mode 下,有一个变量 “m_a_big_number” ,如果双击在在下划线上,那么选择整个变量名称,如果双击在一个, 例如 n , 那么选择的就是这个字母所在的单词上,就是 number 。

如果点取的字符是一个括号的话,那么就会选取这个括号扩住的部
分。 例如在 c mode 下 .

1
2
3
for(i=0;i<100;i++){
    printf("Hello World");
}

点取 “{” 就会选择到另一个 “}” 的部分,同样道理应用于单引号双,双引号,中括号,圆括号。

选择一行文字

快速三次连续点击左键。

来点高难动作

双击加拖拉, 分解动作是 down up down move up . 可以以单词的边界来选择 region 。类似于 touch pad 的笔记本触摸鼠标的拖拉.

三击加拖拉,分解动作时 down up down up down move up. 可以按行来选择 region 。

鼠标中键的功能

粘贴

click 鼠标中键,可以在鼠标所点的位置粘贴文字。

1
(global-set-key (kbd "<mouse-2>") 'mouse-yank-at-click)

这段代码不用放在配置文件中,因为默认配置就是这样。

点取对象

在有些 buffer 中,不能修改 buffer 的内容,那么就鼠标中键的上面所说的作用也就没有什么意义了,于是,一般都把他们帮定在一个类似于按回车的功能上,例如自动补齐的时候,帮助等等。有点类似于浏览器的左键的功能,点击了一个超连接。

鼠标右键的功能

第一次 click 后,把 mark 设置在鼠标点过的位置,选择一个region , 也就是类似鼠标左键的拖拉。

第二次 click 后,如果 click 的位置和上一次的一样,那么完成的是剪切上一次选中的内容。如果 click 的位置和上一次不一样,那么完成的功能是重新选择一个 region .

也就是说,连续两次用鼠标右键选择相同的 region ,可以 cut 掉这个 region 。

1
(global-set-key (kbd "<mouse-3>") 'mouse-save-then-kill)

这段代码不用放在配置文件中,因为默认配置就是这样。

其他

Ctrl + 点击左键

按住 Ctrl 点击鼠标左键,可以调出一个菜单,这个菜单按 mode 分组选择切换 buffer 。

1
(global-set-key (kbd "<C-down-mouse-1>") 'mouse-buffer-menu)

这段代码不用放在配置文件中,因为默认配置就是这样。
我认为把它帮定在单击事件上也不错。

1
2
 (global-set-key (kbd "<C-down-mouse-1>") nil) ;; 去掉原来的帮定关系
 (global-set-key (kbd "<C-mouse-1>") 'mouse-buffer-menu)
Shift + 单击左键

可以选择字体。

1
(global-set-key (kbd "<S-down-mouse-1>") 'mouse-set-font)

这段代码不用放在配置文件中,因为默认配置就是这样。
我认为这个功能不常用,可以用来帮定到其他的功能上去。

Alt + 鼠标

这里的很多功能都是和 secondary selection 有关的,如果不常用 secondary selection 的话,可以考虑把这些键帮定在其他功能上.

Ctrl + 鼠标右键

可以调出和编辑功能相关的功能菜单.

1
(global-set-key (kbd "<C-down-mouse-2>") 'mouse-popup-menuar-stuff)

这段代码不用放在配置文件中,因为默认配置就是这样。

非默认配置

没有滚轴鼠标的朋友看过来.

1
2
(require 'mouse-drag)
(global-set-key (kbd "<S-down-mouse-1>") 'mouse-drag-throw)

这个功能类似于在 IE 中单击滚轴鼠标的中键,然后出现一个图案,移动鼠标就可以滚动窗口中的内容, 滚动的速度可以和鼠标离图案的远近有关系. 这里是帮定了 Shift + 拖动鼠标左键.

如果觉得不太习惯滚动方向,可以用下面的语句调整滚动方向.

1
(setq mouse-throw-with-scroll-bar nil)

下面的功能类似于 acrobat 中的手的功能,可以用鼠标移动来滚动内容.

1
2
(require 'mouse-drag)
(global-set-key (kbd "<S-down-mouse-1>") 'mouse-drag-drag)

同样,这里帮定了 Shift + 拖动鼠标左键。

用鼠标快速 copy ,cut , paste

1
2
3
(require 'mouse-copy)
(global-set-key [M-down-mouse-1] 'mouse-drag-secondary-pasting)
(global-set-key [M-S-down-mouse-1] 'mouse-drag-secondary-moving)

使用方法,把光标移动到要粘贴的地方,然后用按住 Alt + 拖拉鼠标, 选择要拷贝的部分, 抬起鼠标,选择的部分就粘贴到了光标所在位置. 也就是说,一个动作完成 copy & paste 的工作,而且不改变 kill ring 的内容, 用 windows 的术语是剪切板. 和上面的方法类似, 如果按住 Alt + Shift + 拖动鼠标,那么就会完成 cut & paste 的功能.

前面介绍过用鼠标双击可以选择单词(根据字母的语法性质),可以按照词语边界选择(双击+拖动), 可以选择多行 (三击+ 拖动), 这些选择方式在这里都是一样的工作.

这个功能在编写程序的时候十分有用,我们经常需要移动一块代码, 而且移动到的位置也是很近的地方. 或者拷贝附近的一段代码.

分享家:Addthis中国
GD Star Rating
a WordPress rating system
Emacs中鼠标的运用, 9.5 out of 10 based on 15 ratings 标签:ann, ann77, C/C++, ctrl, Emacs, screenshot, windows, 光标, 浏览器, 王纯业, 配色, 配色, 鼠标

相关日志

分类: 其他, 初级
  1. 2016年4月7日12:39 | #1

    No more s***. All posts of this quality from now on

    [回复]

  2. 2016年4月7日18:36 | #2

    Thanks for contributing. It’s helped me understand the issues.

    [回复]

  3. 2016年4月7日19:06 | #3

    It’s great to find an expert who can explain things so well

    [回复]

  4. 2016年4月7日23:58 | #4

    It’s great to read something that’s both enjoyable and provides pragmatisdc solutions.

    [回复]

  5. 2016年9月20日19:02 | #5

    백희나 선생님께,안녕하세요.저는 7살 윤지원 입니다.구름빵책을 너무 좋아했는데,며칠전에 선물로 달샤베트 책을 받아서 읽어보았습니다.너무너무 재미있었습니다.너무너무 좋아요.감사합니다.

    [回复]

  6. 2016年9月26日23:22 | #6

    Grazi for making it nice and EZ.

    [回复]

  7. 2017年4月4日20:06 | #7

    Thanks a lot for giving everyone an exceptionally superb chance to read from this website. It can be so useful and also jam-packed with fun for me personally and my office peers to visit your blog not less than three times in a week to learn the latest stuff you have. And lastly, we are at all times motivated concerning the magnificent opinions you give. Certain two tips on this page are unequivocally the most impressive we have had.

    [回复]

  8. 2017年4月10日13:50 | #8

    Hi to every one, the contents existing at this web page are actually remarkable for people knowledge, well,
    keep up the nice work fellows.

    [回复]

  9. 2017年4月19日20:57 | #9

    My spouse and i have been quite glad Chris managed to finish up his survey because of the precious recommendations he made from your own web pages. It is now and again perplexing to just always be releasing key points some other people could have been trying to sell. And we all figure out we have you to give thanks to for this. The most important explanations you’ve made, the simple site navigation, the friendships your site give support to promote – it’s got mostly terrific, and it’s really assisting our son in addition to our family understand that concept is satisfying, which is particularly important. Thanks for all!

    [回复]

  10. 2017年9月2日20:52 | #10

    I think everything said was actually very logical. But, what about
    this? what if you added a little information? I ain’t saying your content
    isn’t solid, but suppose you added a post title to maybe grab a
    person’s attention? I mean Emacs中鼠标的运用 | Emacs中文网 is a little plain. You ought to
    look at Yahoo’s home page and see how they create news headlines to
    grab people interested. You might try adding a video or a related picture
    or two to get people excited about what you’ve got to say.
    Just my opinion, it might bring your posts a little bit more
    interesting.

    [回复]

评论分页
1 ... 4 5 6 41112
  1. 本文目前尚无任何 trackbacks 和 pingbacks.
:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!: