📄 http:^^www.cs.washington.edu^education^courses^341^spring96^help^emacs.html
字号:
Date: Wed, 08 Jan 1997 21:30:45 GMTServer: NCSA/1.4.2Content-type: text/html<html><head><title>Using Emacs</title></head><body><h1>Using Emacs</h1><h2>a brief introduction</h2><hr><b>Executive Summary:</b> <i>This document is designed to help you getstarted using emacs. It contains a listing of some of emacs' most commonly-used and helpful features, as well as a general overview ofwhat emacs is all about.</i><hr><h3>What is Emacs?</h3>Emacs is an editor, and perhaps the most portable easy-to-use one forUNIX systems. However, it's also one of the most completely flexible,user-programmable, vast programming environments you can imagine. Theengine behind emacs is a Lisp interpreter (it uses a different dialectof Lisp than we learned in class), which allows users to code theirown routines to customize the environment nicely. As such, it can bean intimidating beast, feeling huge and overly complex, and full ofoptions you'll never discover. The key is to just pretend "what Idon't know won't hurt me" and use what you find useful. The more youuse it, the more you'll learn (for example, today I learned how tobind the Control-up arrow key to a specific function in a specificemacs mode). For the purposes of this class, you shouldn't have tolearn too much about it, and I recommend you don't spend too much timetrying to figure out the intricacies of emacs (for example, today Ispent 2 hours figuring out how to bind the Control-up-arrow key to aspecific function in a specific emacs mode) -- if you need to knowsomething and can't figure it out quickly, ask.<p><h3>Notation</h3>When talking about emacs, we'll use the notation <i>C-</i> to indicatethat a key should be pressed while holding down the control key (emacsrequires this a lot). For example <b>C-h</b> means hit H whileholding down the control key. Similarly, <i>M-</i> means use the Metakey. If you don't have a key called "Meta" usually "Alt", "AltFunction", or "Escape" is what you will use. For example <b>M-x</b>means hit X while holding down the Meta key.<p>Lots of emacs functions take two keystrokes to complete. For example,to exit emacs, use <b>C-x C-c</b> (Control-X followed byControl-C).<p><p><h3>Running emacs</h3>Emacs can be run in two ways. One will work on any sort of characterterminal and makes very few assumptions about what your hardwareset-up is. You could run emacs at home on your Vic-20 in this mode,for example. The other assumes that you have an X-terminal, andallows you to do fun stuff like use the arrow keys and the mouse. Thelatter is recommended whenever it's available to you -- it's mucheasier to use.<p>After logging onto your MSCC account, you run emacs by simply typing:<ul><code><b>emacs</b></code><p></ul>If you haven't set up your DISPLAY environment variable, emacs willtake over the terminal window you're typing in and it'll look like alittle text editor. Use <b>C-x C-c</b> to get back out.<p>To run emacs taking advantage of X, you need to do two things. Firsttell your display that it's OK for the machine you're running from touse its display. This is done using <i>xhost +</i> followed by thename of the machine that you'll be running emacs on. For example, ifI'm sitting in 326D at spirit, and wanting to run emacs from an msccmachine, I would type:<p><ul><code><b>xhost + mscc.ms</b></code></ul>Next, you have to tell the machine that you're running from whichdisplay you're at using <i>setenv DISPLAY</i> followed by your displayname and <i>0.0</i>. For example in the above situation, from an msccprompt, I would type:<p><ul><code><b>setenv DISPLAY spirit.cs:0.0</b></code></ul><p>Now when you run emacs, it should show up in its own window on yourdisplay, and you should be able to use the mouse and such. We'llassume this mode of operation for the remainder of this document.<p><h3>Emacs Orientation</h3>When you start up emacs, it will come up with an empty buffer. At thetop of the window are some pull-down menus which contain some of thecommon operations. At the right side is a scroll bar. Near thebottom is a status bar. Just below that is a line called themini-buffer.<p><center><!WA0><img src = "http://www.cs.washington.edu/education/courses/341/spring96/help/emacs.gif"><p><b>Figure 1</b> <i>A small emacs window</i><p></center>The status bar tells you what you about the buffer you're looking at.The double asterisk (**) indicates that the buffer has been modifiedsince it was created or last saved to disk (in this case because Ityped "test" in it). Sometimes, you'll see "%%" there. That meansthe current buffer is read-only, and that you can't type into it.Next, the bar says "Emacs:" and tells the name of the buffer"*scratch*" -- this is the default buffer when starting up. Next, ittells the mode that this buffer is operating in -- Lisp Interactionmode is the default when starting up. Then it tells what part of thebuffer you're looking at. In this case, it contains only the wordtest, so we are seeing "All" of it.<p>The minibuffer is a small buffer which emacs uses to report errorconditions to you, and to prompt you for information whennecessary.<p>The cursor indicates where your text will appear when you type. Youcan reposition it using the mouse.<p>Buffers are the basic unit in emacs. Each file you edit has its ownbuffer. There can also be buffers for other purposes -- for examplethe minibuffer is used for emacs-user interactions; you can have abuffer in which you're running a Minischeme or Lisp interpreter; etc.At any given time, your emacs session will have multiple buffersaround, although only a few may be visible at a given time.<p>Each buffer has an associated mode with it which controls the behaviorof everything you do in it. For example, if you edit a file with the.ml extension, emacs will realize that this is an ML file, and willput you in SML mode, which knows how ML programs should be indented.Similarly, if you open a .c file, or a .cl file, its buffer will be inC-mode or Common Lisp mode, respectively, and know the syntax of thatlanguage. In addition to the indentation rules changing based on thebuffer's mode, Control-key sequences may have different actions,additional pull-down menus will typically be added, and differentsorts of syntax checks will be done for you (like balancingparenthesis in Lisp).<p>The *scratch* buffer is just that -- scratch space for you to typeanything you want without associating a file with it.<p><h3>Cancelling and Exiting</h3>The two most important key sequences to know in Lisp are <b>C-g</b>and <b>C-x C-c</b>. <b>C-g</b> is used to cancel an action thatyou've started, and can be an excellent way to get out of mysteriousfeatures that you accidentally got yourself into by typing the wrongthing. My rule of thumb is: when in doubt, use <b>C-g</b>. SometimesI use it several times in a row, just to make sure. :)<p>The other thing you'll want to know is how to exit. Use <b>C-xC-c</b>. Lisp will prompt you if you haven't saved all of yourbuffers, or if you've left any processes (like a Lisp or MLinterpreter) running.<p><h3>The Pull-down menus</h3>The most recent version of emacs (version 19) came with pull-downmenus, after years of everyone using Control-key sequences to getthings done. The control-key sequences are so engrained in my mind
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -