[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
slackbook:emacs [2012/08/22 02:33 (UTC)] vharishankarslackbook:emacs [2012/09/16 16:35 (UTC)] – [Calling Functions] Added original content and formatting mfillpot
Line 1: Line 1:
 ====== Emacs ====== ====== Emacs ======
 +===== What is Emacs? =====
 +
 +**//vi//** and its clones are very functional
 +and powerful editors.  However, they are often considered not
 +particularly extensible.  **//vim//** is a
 +successful and powerful
 +**//vi//** variant that shrugs this trend,
 +being both extremely extensible and lightweight.  However, many
 +users prefer a more //"heavy"// and extensible editor.  This is why
 +many people (including the author of this chapter) prefer
 +**//Emacs//**.
 +
 +
 +Emacs takes extensibility up to eleven.  Outside of a core of C,
 +the rest of **//Emacs//** is written in a
 +Lisp variant, nearly all of which is exposed to you, so that you
 +may configure it or even extend it at will (many good Emacs Lisp
 +tutorials can be found on the Internet).  People have written
 +all sorts of extensions in Emacs Lisp, from syntax highlighting
 +for an obscure language, to a built-in terminal.  In fact,
 +there's even a **//vi//** emulation mode
 +within **//Emacs//** (called viper), so you
 +can still get the modal editing that comes with vi, while having
 +access to the power of the **//Emacs//**
 +core.
 +
 +
 +Like **//vi//**, there are many variants of
 +**//Emacs//** (termed //"emacsen"//).  However,
 +the one most commonly used (and the only one in Slackware) is
 +GNU Emacs.  When people reference //"Emacs"// directly, they almost
 +always mean GNU Emacs.
 +
 +
 +Unlike **//vi//**,
 +**//Emacs//** operates more like a
 +traditional editor by default.  This means that most keyboard
 +shortcuts can be performed without repeatedly changing modes.
 +You can open up a file and start typing away without having to
 +learn what the modes do, or forgetting which one you are
 +currently using.
 +===== Starting Out =====
 +
 +**//Emacs//** can be started simply by
 +running the **//emacs//** command in your
 +terminal.  When
 +you first start it in a console without arguments, you will see
 +something that resembles this:
 +
 +    
 +[[emacs-startup.png|Starting Out]]
 +
 +If you are in X windows, **//Emacs//** may
 +start a GUI instead of running in your console.  If this is the
 +case and you don't want a GUI, you can invoke it with the flag
 +//'-nw'//.
 +
 +
 +While here, you can browse around using the
 +keyboard arrow keys.
 +Underlined elements are links, and you can activate them by
 +moving over them and pressing <key>'Enter'</key> The documentation
 +mentioned is very good, and can help you get your bearings
 +should you have any problems.  Also note how they describe key
 +sequences such as <key>C-h</key>, meaning press the
 +<key>'h'</key>
 +key while holding down the <key>'CTRL'</key> key.  Same deal
 +with **M-`**, meaning to hold the the
 +**Meta** key (usually <key>'Alt'</key>) and
 +press the backtick <key>'`'</key> key.  When they say (e.g.)  <key>C-x</key> <key>C-c</key>, this means to press the <key>'x'</key> key while holding down
 +the <key>'CTRL'</key> key, then press the <key>'x'</key> key while also
 +holding down the <key>'CTRL'</key> key.  Conveniently, this
 +is also one of the more important commands in
 +**//Emacs//**: to close it.
 +
 +
 +Alternatively, if you call **//emacs//** with a
 +file name as an argument, it will open that file, just like
 +**//vi//**.  Upon doing this, you will be
 +presented with the contents of the file in question.  Here, you can
 +navigate the document using traditional arrow keys and type in
 +information at will without any issues.
 +
 +
 +Say you make some edits, and you now want to save your file.
 +The following key sequence will do that: <key>C-x</key><key>C-s</key>.
 +If you made a new file, you will be prompted for this in what is
 +called the //"minibuffer"//, the blank line below the gray line at
 +the bottom of the screen.  Type in the file name of your choice,
 +then hit <key>'Enter'</key>. If you don't want to
 +save the file, you can press <key>C-g</key>, which aborts
 +operations that ask for input.  Do note that tab-completion is
 +usually available for operations that use the minibuffer.
 +
 +
 +Should you want to open a new file within your same
 +**//Emacs//** session, type in <key>C-x</key><key>C-f</key> You will be prompted for a file name in the
 +minibuffer.  **//Emacs//** doesn't care
 +whether it exists or not.  If it doesn't exist, a new buffer
 +will be created for it (the file will be created upon saving
 +with <key>C-x</key><key>C-s</key>), or it will be opened as
 +expected.  However, the old file will still be open!  You can
 +switch back to it using <key>C-x</key><key>C-b</key>, entering in
 +the file's name (or more technically, the buffer's name), then
 +hitting <key>'Enter'</key>.
 +===== How to Move Around =====
 +
 +Like **//vi//**,
 +**//Emacs//** is also older than the arrow
 +keys on your keyboard.  Also, like in
 +**//vi//**, using the arrow keys to navigate
 +files is also supported.  While the
 +**//vi//** movement keys are more ergonomic,
 +**//emacs//**'s are more //"mnemonic"//.
 +However, it is still very possible to operate using the main
 +**//Emacs//** keybindings quickly and
 +efficiently.  Here is a table of the basic movement keybindings:
 +
 +    
 +**Emacs Cursor Movement**
 +^Command^Result|
 +|<key>C-f</key>|Move the cursor one character to the right (forward)|
 +|<key>C-b</key>|Move the cursor one character to the left (backward)|
 +|<key>C-n</key>|Move the cursor one line down (next)|
 +|<key>C-p</key>|Move the cursor one line up (previous)|
 +
 +Of course, like with **//vi//** it is also
 +possible to repeat these commands with a numeric argument.  If you
 +type in **M-1** **M-0** <key>C-p</key>, or <key>C-u</key> 10
 +<key>C-p</key>, the cursor will move ten lines up.  If you type in
 +**M-5** <key>C-f</key> or <key>C-u</key> 5 <key>C-f</key>, the cursor
 +will move five characters to the right.
 +===== Getting Help =====
 +
 +**//Emacs//** contains a great deal of
 +documentation, to the point that it is often called a
 +//"self-documenting"// editor. This is because it provides
 +mechanisms for providing users with documentation while you are
 +using it.
 +
 +Here are some useful functions that display documentation (they
 +all start with <key>C-h</key>):
 +
 +
 +**Accessing Emacs Documentation**
 +^Command^Result|
 +|<key>C-h</key> f FUNCTION-NAME <key>Enter</key>|Show documentation for function FUNCTION-NAME|
 +|<key>C-h</key> k <key>C-x</key> <key>C-c</key>|Show documentation for the function bound to the keys<key>C-x</key> <key>C-c</key>|
 +|<key>C-h</key> t|Show the Emacs tutorial|
 +|<key>C-h</key> ?|Show all help-related functions|
 +
 +    
 +<key>C-h</key> **t** is especially useful if you want or need practice using **//Emacs//**.
 +===== Calling Functions =====
 +
 +As noted earlier, **//Emacs//** exports a
 +large number of functions to for interactive use.  Some of
 +these, like those opening and saving files, are mapped to keys.
 +Others (like the ones for moving to the beginning and end of
 +lines) are not.  To call them, you have to invoke them.  Say we
 +want to call the function //"end-of-line"// We would do
 +this:
 +
 +
 +**M-x** end-of-line <key>Enter</key>
 +
 +
 +And the cursor would move to the end of the line, as the function name
 +suggests.
 +===== Emacs Cheat Sheet =====
 +
 +
  
 While [[slackbook:vi|vi]] (with its clones) is without a doubt the most ubiquitous editor on Unix-like systems, emacs(1) comes in a good second. Instead of using different "modes", like vi does, it uses <key>Ctrl</key> and <key>Alt</key> key combinations to enter commands, in much the same way that you can use <key>Ctrl</key> and <key>Alt</key> key combinations in a word processor and indeed in many other applications to execute certain functions. (Though it should be noted that the commands rarely correspond; so while many modern applications use <key>Ctrl+C/X/V</key> for copying, cutting and pasting, emacs uses different keys and actually a somewhat different mechanism for this.) While [[slackbook:vi|vi]] (with its clones) is without a doubt the most ubiquitous editor on Unix-like systems, emacs(1) comes in a good second. Instead of using different "modes", like vi does, it uses <key>Ctrl</key> and <key>Alt</key> key combinations to enter commands, in much the same way that you can use <key>Ctrl</key> and <key>Alt</key> key combinations in a word processor and indeed in many other applications to execute certain functions. (Though it should be noted that the commands rarely correspond; so while many modern applications use <key>Ctrl+C/X/V</key> for copying, cutting and pasting, emacs uses different keys and actually a somewhat different mechanism for this.)
Line 121: Line 293:
 This quits emacs. If you have any unsaved files, emacs will tell you so, and ask if you want to save them each in turn. If you answer no to any of these, emacs will ask for one final confirmation and then quit.  This quits emacs. If you have any unsaved files, emacs will tell you so, and ask if you want to save them each in turn. If you answer no to any of these, emacs will ask for one final confirmation and then quit. 
  
-=====Sources===== +====== Chapter Navigation ====== 
-  + 
 +**Previous Chapter: [[slackbook:vi|vi]]** 
 + 
 +**Next Chapter: [[slackbook:network|Networking]]** 
 +======Sources======
   * Original source: http://slackbook.org/beta/#ch_emacs (authors: Alan Hicks, Chris Lumens, David Cantrell, Logan Johnson)   * Original source: http://slackbook.org/beta/#ch_emacs (authors: Alan Hicks, Chris Lumens, David Cantrell, Logan Johnson)
 slackbook:emacs ()