首页 > 初级, 学习Emacs > Emacs初学者必知必会

Emacs初学者必知必会

2010年1月24日 ahei 发表评论 阅读评论

自己学习Emacs已3年由余, 对Emacs也算有点经验. 随着对Emacs的了解的不断深入, 越来越觉得Emacs是一款非常值得学习的软件. 所以我经常向自己的朋友推荐Emacs. 自己也认识一些Emacs初学者. 从他们经常问的一些问题中感觉, 好多初学者都没有好好的学过Emacs, 也有可能是Emacs的资料不是很多, 好资料更少, 他们没有找到好的学习方法吧. 所以, 我想就我所了解的, 写一些初学者应该知道的东西, 或者说, 初学者掌握了这些知识和方法后, 学习Emacs起来更加容易吧. 另外, 初学者如果有兴趣的话, 可以看看本人另外一篇拙作《致Emacs初学者》, 希望能对你们有所帮助.

知道Emacs的基本概念

  • buffer
    缓冲区. Emacs并不直接对文件进行操作, 它是把文件加载进buffer, 用户直接操作buffer, 只有当用户确定把buffer中所做的修改写人文件时, Emacs才把buffer中的内容写入文件. buffer实际上就是一个内存缓冲区, 这和一般编辑器中都一样, 应该很好理解.
  • window
    窗口. 由于Emacs很早就诞生了, 它的窗口概念和现在基于窗口的操作系统中的窗口概念不是一样的. Emacs中的窗口是用来显示buffer的一个区域. 它并不像操作系统中的窗口拥有自己的标题栏,系统菜单栏.
  • frame
    Emacs中的frame就是操作系统中的窗口.

buffer是文件的内存表示, windows则是显示buffer的区域, 一个frame中可以有多个window, Emacs则可以有多个frame.

  • Emacs Lisp
    Emacs最基础的部分是用c写的,其他部分都是用Emacs Lisp语言写的,Emacs Lisp语言是基于lisp语言的. lisp是LISt Processor的缩写, 即链表处理语言, 所以lisp语言的操作都是基于链表的, 它的语法也是链表结构, 链表第一个元素表示函数名, 其他元素是参数, 比如通常语言中的a+b, 在lisp就是(+ a b)
  • mode
    mode有major mode和minor mode之分, 每个缓冲区对应一个major mode, 也只有一个major mode, 但是可以有多个minor mode. Emacs对每一种文件都有一个mode.
  • 命令
    你对Emacs所有的操作都是对Emacs的命令的调用。比如,你在text-mode里,当你按下任何字母键进行编辑的时候,实际上是调用的emacs的命令self-insert-command.
  • 快捷键
    Emacs中Control键用C表示,Alt键用M表示, 即: C-c表示Control C, M-x表示Alt x.
    除掉以Alt键开头的,比如Alt a,Emacs中的快捷键基本上都有一个前缀,Emacs中最多的快捷键前缀就是C-x,C-c,前缀表示,你不必要一起按下前缀和后缀,可以先按下前缀,Emacs会等待你按下剩余的快捷键,这样Emacs中的快捷键按起来非常的方便。
  • keymap
    键盘映射. Emacs的快捷键是通过keymap来控制的. 有全局和局部的keymap. 每个mode都会有一个自己的局部的keymap, 局部的keymap会覆盖全局的keymap, 另外如果对应的major mode有开启的minor mode, 而且这个minor mode有keymap的话, 这个minor mode的keymap会覆盖major mode的keymap.

学会看文档

Emacs的文档非常丰富, 有Elisp自己的自文档, 还有更详细的info. Elisp中的变量, 函数都有文档. 对于大多数情况都够用了.

  • 查看变量的值和文档
    C-h v (describe-variable)
  • 查看函数的文档
    C-h f (describe-function)
  • 查看face的文档
    M-x describe-face
  • 查看某个mode的文档
    C-h m (describe-mode)
    刚开始学习某个mode的时候, 可以用C-h m看看当前buffer对应的主mode和副mode的文档, 这个文档一般都会包括mode中的命令和快捷键列表.
  • 查看某个快捷键对应的命令
    C-h k (describe-key)
  • 查看某个命令对应的快捷键
    C-h w (where-is)
  • 查看当前buffer所有的快捷键列表
    C-h b (describe-bindings)
  • 查看当前buffer中以某个快捷键序列开头的快捷键列表
    <待查看的快捷键序列> C-h,比如你想查看当前buffer中所有以C-c开头的快捷键列表,按C-c C-h就可以了。
  • 查看函数的代码
    find-function
  • 查看变量的代码
    find-variable
  • 查看face的代码
    find-face-definition
  • M-x apropos
    查看包含某个关键词的函数,变量,face

会些简单的配置

  • 执行Elisp代码
    1. 在某条语句后面按C-x C-e (eval-last-sexp)可以执行那条语句
    2. M-x eval-buffer 可以执行当前buffer内的Elisp代码
    3. 选中一个region后, M-x eval-region可以执行这个region内的代码
  • 安装插件
    Emacs的插件一般都是一个以el为后缀名的文件, 把这个文件下载下来后放到一个目录, 比如~/emacs/lisps, 然后执行下面这两条语句:

    1
    2
    
    (add-to-list 'load-path "~/emacs/lisps")
    (require 'pluginname)
  • 快捷键定制
    全局绑定global-set-key, 绑定某个mode的快捷键用define-key. global-set-key的定义为:

    (global-set-key key command)

    比如想把C-j绑定到”到达指定行上”(goto-line), 这样就可以了:

    (global-set-key (kbd "C-j") 'goto-line)

    kbd是Emacs的宏, 把快捷键转换为Emacs的内部按键表示. 然后执行上面那条语句, 就会使你的配置生效. 然后你可以用C-h k检查一下你的定制是否成功了.
    如果对于比较复杂的快捷键, 比如Control x F3, 改怎么写呢? 按C-h k(describe-key), 然后再按下Control x F3, Emacs会出现一个”C-x “, 这个就是你要写到kbd宏里面的内容.
    如果你想对某个特定模式比如c++-mode进行快捷键定制, 用define-key即可, 对于上面的例子这样写:

    (define-key c++-mode-map (kbd "C-j") 'goto-line)

    define-key第一个参数map一般为mode后面直接加”-map”

  • 简单的颜色定制
    1
    2
    3
    4
    5
    
    (set-background-color "black") ;; 使用黑色背景
    (set-foreground-color "white") ;; 使用白色前景
     
    (set-face-foreground 'region "red")  ;; 区域前景颜色设为红色
    (set-face-background 'region "blue") ;; 区域背景色设为蓝色
分享家:Addthis中国
GD Star Rating
loading...
Emacs初学者必知必会, 9.4 out of 10 based on 56 ratings 标签:ahei, buffer, C/C++, caps lock, control, eclipse, Elisp, Emacs, emacser, face, IDE, keymap, lisp, mode, org, plugin, pluskid, se, snippet, text, theme, windows, yasnippet, 二分调试法, 代码补全, 光标, 叶文斌, 安装, , 定制, 按键, 插件, 王垠, 王纯业, 看文档, 补全, 配置, 配色, 配色, 颜色, 鼠标

相关日志

分类: 初级, 学习Emacs
  1. 2016年4月7日20:03 | #1

    Johann Strauss II’s delectable operetta is given an exuberant and bubbly production at the Mahalia Jackson Theater for the Performing Arts this weekend (the closing performance is Sunday, Nov. 15), showing why the tuneful confection is the most performed operetta in the standard repertoire. coach factory outlet measures are not consistent with Washington’s previous commitments to accept services from other countries. l coach outlet store online
    A similar rationale applies to cold weather clothing, such as ski parkas http://www.raybansunglassesbuy.co.uk But many producers have fought the concept, arguing that actors already undergo health screening and audiences are turned off by condoms.
    Montreal defenseman Nathan Beaulieu got a match penalty and game misconduct with 17 seconds left for a cross-check on Boston’s Zac Rinaldo. Rinaldo was skating in for a bodycheck when Beaulieu lifted his stick and appeared to get him in the neck or the head. ray ban glasses Initially, in 1991, he received a sentence of 66 years to life in prison, with two convictions for murder and another for rape. k ray ban sunglasses outlet
    What that also leads to is a shortage of qualified teachers. cheap jordan shoes Fishing was a significant part of my life and is intertwined with so many of my childhood memories.
    q The 813-acre park’s population booms to more than 15,000 people during summer holiday weekends, says Gene Van Koevering, the park’s president for the past three years. Most members live within an hour of the park, he says. coach outlet online “Lawmakers can expect a robust effort by the grassroots to steer them away from expanding Medicaid and placing Arkansas on a path to fiscal ruin. coach factory outlet
    “I was nervous coming here thinking this is going to be my one job for a very long time even though it’s like the coolest job I could possibly imagine. coach outlet online We did not make these decisions lightly and these changes are difficult for us all, but these staffing reductions will allow us to operate more efficiently and position the network for the future. http://www.michaelkorshandbagsoutletup.us.com
    Larkin scored in his fourth straight game – the first time a Red Wings teenager has done so since Steve Yzerman in 1984-85 – giving Detroit a 3-2 lead in the second period and helping force overtime to set the stage for Pulkkinen’s heroics. michael kors outlet online Two teams from southern Minnesota left it all on the court Thursday night. m michael kors outlet store
    He was among four Phoenix Symphony musicians to recently earntenure, according to a news release from the orchestra. louis vuitton handbags Arizona State pays coach Charli Turner Thorne $464,000 a year.
    After 30 years of Republican control, we spend less than all other states on students and we remain at the bottom of national rankings. http://www.cheapjordanshoes.us.org Established in 2005 in memory of Graves’ firstborn son, the Jackson L.
    Nice pop for the position. michael kors handbags I can think back to a year a half ago when I came here and how I got my head kicked in, and I’m pretty glad I came.
    Though far from amazing, they’re still louder and crisper than most single-speaker setups. cheap ray bans Still, the season included a 7AWest conference title, .
    s And nearly nine out of ten see the health of the Gulf as important to their states’ economies. ray ban sunglasses The darkness can never overcome the light.
    Forest Service reported more than twice the number of incidents than the other five agencies combined, but they have been lobbying for arms for years and one way to lobby is to document a lot of incidents, even small ones. coach factory outlet Doug Martin remained in Tampa. n michael kors outlet online
    The Panthers were unable to get closer than seven the remainder of the contest http://www.louisvuitton-outlet.us.org Everything went as planned the old-fashioned way in a hospital bed – no bath tub, no home birth or anything like that, which seems to be popular in Denmark these days.
    b Mariota provided a glimpse of what could happen during his against Jacksonville Nov. 19. Mariota took off on a read option play and sprinted to the end zone. coach online store It’s a bareknuckles business in which rivals try to beat each other to the doorsteps of residents who may have no idea of the wealth beneath their land. s
    Islanders CFOEric Pettis reestablished his commitment to staying in central Pennsylvania after considering a move to Nashvilleor the Lehigh Valley. cheap nfl jerseys What the experience did, he said, is provide a strong connection between the players, coaches and parents. michael kors online
    So one of my pleasures has been taken from me. If I divorce him it will still be single cooking, but I won’t have to pretend I am part of a household. Do you think vegetarianism should be grounds for divorce? michael kors outlet Daw, who is also a software engineer, said he’s never been a fan of the state’s computer voting machines they require a lot of equipment and their operating systems are easy to hack, he said. t michael kors bags
    With Taron Egerton, Hugh Jackman and Christopher Walken oakley sunglasses I am lucky to have known them.
    Dr. Louis Picker The Oregonian/OregonLive coach outlet online I’d pull into a spot, and there’d be a boat fishing it. y oakley glasses
    Did McConnell feel that way when GOP icon former President Ronald Reagan nominated Supreme Court Justice Anthony Kennedy late in his term? No, and he actually he voted for Kennedy. coach outlet store online The result is a simple drop cookie that is simultaneously delicate and fudgy with a heady punch of mint.

    [回复]

评论分页
1 2 40639
  1. 2011年11月10日09:25 | #1
  2. 2012年5月16日20:17 | #2
  3. 2012年6月15日16:06 | #3
  4. 2014年6月3日05:12 | #4
  5. 2014年6月3日06:45 | #5
  6. 2014年6月3日14:29 | #6
  7. 2014年7月2日19:52 | #7
:wink: :-| :-x :twisted: :) 8-O :( :roll: :-P :oops: :-o :mrgreen: :lol: :idea: :-D :evil: :cry: 8) :arrow: :-? :?: :!: