emacs

Introduction

Learn It

  • When on a computer system, users will need to be able to edit files.
  • Most files contain plain text with no images of video embedded in them (e.g. HTML files, .txt files, .py files). These can be modified by programs called text editors.
  • There are various text editors available on Linux systems, and hackers typically have strong feelings about their favourite.
  • Some examples are:
    • Nano
    • vim
    • emacs (always with a lower case e)
    • gedit
  • The Internet community is divided as to whether emacs or vim is better.
  • You can make your own mind up on this. We use emacs to author everything you see on BourneToCode.com and BourneToInvent.com though.
  • Although originally written for UNIX-like systems, most of the above editors are also availale for other operating systems, like Windows.

Learn It

  • emacs was written back in 1976 by a software engineer called Richard Stallman. He's quite the character in his own right; you can read more about him on his Wikipedia page.

Emacs_Dired_buffers.png

  • Despite being nearly 40 years old, emacs continues to be actively developed by the online community, and is one of the oldest computer applications in the World still in active use.

Learn It

  • emacs was written for an era in computer science where the keyboard was the only way to enter commands onto a computer and graphics consisted of text appearing on a text-only terminal.
  • While superficially, it might seem daunting to enter text without a mouse, but many professional developers find that when one works without ever having to take their hands off the keyboard, they are able to work far more quickly.
  • In emacs, shortcuts are either achieved by holding the Control key and pressing another key, or holding the meta key (Alt) and tapping another key.
  • The shorthand for this looks like this: C-x C-f.
  • This would mean to Hold Control and tap x, then to hold Control and tap f. You don't need to release the control key each time, but you can if you want to.
  • M-f means to hold the Alt key and tap the f key.
  • Factoid: Instead of holding Alt, you could hit Esc once then tap the f, just like in the 1980s.

Try It

  • We're actually going to work on a different computer today. A web-server that you can create pages on which your friends can see while they are in school.
  • To connect to it, you will need to go to open drive, then computing. Double click on the SSH Terminal.
  • Once the session has started, log in with your standard network username and password.
  • Note: As you type your password, you won't see anything. This is normal; just don't look at the screen and you won't notice.

Learn It

  • One of the great things about using Linux is the ability to work on other machines around the World easily. This is often achieved using a program called SSH, short for 'secure shell'. It's remarkably easy to connect to another computer.
  • In the terminal window you just connected to, type:
ssh 00zz11@studentweb
  • Replace the 00zz11 with your network username.
  • After a moment, you'll be asked for your password again.
  • If you type it correctly, you'll have a new terminal prompt, along the lines of:
  • 00zz11@brgrastudentweb:~/
    • The 00zz11 lets you know who you're logged in as.
    • The @brgrastudentweb tells you the name of the server you're connected to.
    • ~/ tells you that you're in your 'home' directory (~ is used as shorthand)
  • If you type ls, you'll see that there is one file and one directory available to you.
  • Use cd to change into the www directory.
  • Anything you put in here can be seen by any other student or staff member. It's not visible from outside School; this is known as an Intranet.
  • The address for your published content will be: http://studentweb/~yourusername
  • Note: Everything you do on this computer is logged, and everything can be traced back to you. You are solely responsible for what is published in your Intranet space. Do not publish anything onto the pages that you would not be happy for your parents and/or the Headteacher to see, and do not publish images of other people without their permission. Do not publish remarks about other students or staff, anything hateful, use the service to do anything illegal or publish anything likely to cause offence. Any content can be removed at any time without notice.

Try It

  • Having typed cd www you can type ls to see what's in your web directory.
  • You'll see a single file which has been automatically created for you, called index.html
  • We'll edit this file to create our pages, using the emacs editor.

3_1.png

  • Load up emacs by typing emacs in the terminal. The screen will look like the image above.
  • emacs uses (about 2000) keyboard shortcuts to allow users to achieve all manner of activities. We'll only need a tiny number of these to get some productive work done.
  • Type C-x, C-f which is the combination to open a new file.

3_2.png

  • At the bottom of the screen, the computer will show you the ~/www/ prompt, which is inviting you to enter the name of the file you'd like to open or create.
  • Type index.html and hit enter to load the file.
  • Use the arrow keys to the section that says, 'this page is under construction' and change the text to say something else.
  • Save the work with C-x, C-s.
  • Quit out of emacs using C-x, C-c.
  • Load the Firefox web browser (Look in 'Activities' in the top-left again) and view your page on the Intranet. Try some of your friends pages too.
  • For a taste of the 1970s, you can also use a terminal web browser called 'lynx' to browse the web. Type things liks lynx google.co.uk to get started, and type q to quit when done.
  • Task: Try opening your file again, changing the file a little and saving it without looking at your notes.
  • Users on Linux machines all around the World run web servers in a similar way to build the World Wide Web.

Try It

  • If you were coding a large program or using emacs to read a large document, you might end up with hundreds of lines you've need to be able to quickly get through. The following commands are useful for navigating through a document without needing to take your hands off the keyboard:
    C-v Scroll down a page
    M-v Scroll up a page
    M-f Move forward one word
    M-b Move backwards one word

Try It

  • The emacs community also include several games within emacs.
  • Try typing some of the following:
  • Note: You can type q to exit them.
    • M-x tetris
    • M-x pong
    • M-x snake
    • M-x bubbles
    • M-x dunnet
    • M-x hanoi
    • M-x doctor

Badge It

  • You should now be able to attempt the badge tasks. If you're unsure, the video tutorial below demonstrates using emacs to edit a webpage that you can see anywhere in school when you're connected to our WiFi network.
  • Silver: Using emacs write a tutorial for someone who's never used emacs before to explain how to make a new file, change it, save it and quit emacs.
  • Gold: Research how to cut, copy and paste in emacs. Write this on the bottom of your answer to the silver badge. Note: It's not called cut, copy and paste in UNIX-like systems (for example, linux).
  • Platinum: The other popular text editor is vi. Find out how to edit a file, save it and quit. Give your teacher a demonstration (or add it to your silver/gold notes to collect this badge).