Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to EMACS and XEMACS CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.

Similar presentations


Presentation on theme: "Introduction to EMACS and XEMACS CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes."— Presentation transcript:

1 Introduction to EMACS and XEMACS CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.

2 Emacs Background Emacs is a powerful and extensible text editor. Emacs is a powerful and extensible text editor. Emacs originally was an acronym for Editor MACroS. Emacs originally was an acronym for Editor MACroS. The first Emacs was a set of macros written in 1976 at MIT by Richard M Stallman. The first Emacs was a set of macros written in 1976 at MIT by Richard M Stallman. Emacs has become a standard editor used by programmers worldwide. Emacs has become a standard editor used by programmers worldwide. There are several varieties of Emacs, by typing emacs at the command prompt, you are throw into one of two modes: There are several varieties of Emacs, by typing emacs at the command prompt, you are throw into one of two modes: The terminal-mode (from an ssh connection or without X Window): The terminal-mode (from an ssh connection or without X Window): This mode has no toolbars, and all commands are given via keyboard. This mode has no toolbars, and all commands are given via keyboard. Do not think that this is a useless mode, as sometimes the only connection that you may have to a machine is remote. Do not think that this is a useless mode, as sometimes the only connection that you may have to a machine is remote. The graphical-mode (requires X Window): The graphical-mode (requires X Window): It looks similar to the terminal-mode, but with some added features for X. It looks similar to the terminal-mode, but with some added features for X. There is a toolbar across the top of the window, from which many common tasks can be accessed. There is a toolbar across the top of the window, from which many common tasks can be accessed. You may wish to type emacs& (note the &), as this will free up the shell for other tasks (such as compiling). You may wish to type emacs& (note the &), as this will free up the shell for other tasks (such as compiling).

3 XEmacs This version of Emacs that has many enhancements specifically for X Window and should be launched locally. This version of Emacs that has many enhancements specifically for X Window and should be launched locally. There is a graphical toolbar (like MS Word) for basic options as well as a text driven toolbar for other options. There is a graphical toolbar (like MS Word) for basic options as well as a text driven toolbar for other options. To invoke XEmacs just type xemacs. If you do not want to tie up the shell, use xemacs&. To invoke XEmacs just type xemacs. If you do not want to tie up the shell, use xemacs&.

4 Creating and Opening Files To create a file, type the name of the file that you wish to create after the emacs command. Example: emacs foo.c & or xemacs foo.c & (& optional). To create a file, type the name of the file that you wish to create after the emacs command. Example: emacs foo.c & or xemacs foo.c & (& optional). To open a file, type the name after the command, just as above. To open a file, type the name after the command, just as above.

5 Tutorial and References Emacs comes with a built in tutorial. Emacs comes with a built in tutorial. To access it type F1 then T. To access it type F1 then T. The tutorial covers many of the basic tasks, such as cursor movement to more advanced skills such as searching and replacing text. The tutorial covers many of the basic tasks, such as cursor movement to more advanced skills such as searching and replacing text. References - from basic commands to the full manual References - from basic commands to the full manual A BASIC EMACS Reference Card A BASIC EMACS Reference Card A BASIC EMACS Reference Card A BASIC EMACS Reference Card A much more EXTENSIVE EMACS Reference Card A much more EXTENSIVE EMACS Reference Card A much more EXTENSIVE EMACS Reference Card A much more EXTENSIVE EMACS Reference Card The Complete Manual Online - at GNU.org The Complete Manual Online - at GNU.org The Complete Manual Online The Complete Manual Online

6 XEmacs XEmacs is a graphical variant of Emacs. XEmacs is a graphical variant of Emacs. It too is freely available for download (http://www.xemacs.org/) and is also licensed under the GPL license (http://www.gnu.org/licenses/licenses.html#GPL). It too is freely available for download (http://www.xemacs.org/) and is also licensed under the GPL license (http://www.gnu.org/licenses/licenses.html#GPL).http://www.xemacs.org/http://www.gnu.org/licenses/licenses.html#GPLhttp://www.xemacs.org/http://www.gnu.org/licenses/licenses.html#GPL XEmacs for Windows XEmacs for Windows For those of you who use Windows, that there are MS Windows ports of XEmacs. For those of you who use Windows, that there are MS Windows ports of XEmacs. XEmacs Commands XEmacs Commands Mostly all of the Emacs commands are available to you under XEmacs Mostly all of the Emacs commands are available to you under XEmacs One useful XEmacs command: One useful XEmacs command: Alt-G - Goto Line number Alt-G - Goto Line number

7 .emacs Configuration File When Emacs (or XEmacs) begins, it looks for and reads a file named.emacs in your home directory to obtain configuration information. When Emacs (or XEmacs) begins, it looks for and reads a file named.emacs in your home directory to obtain configuration information. Save this.emacs file (note the leading "dot") in your UNIX home directory to get the following features (you will need to restart emacs to invoke these options): Save this.emacs file (note the leading "dot") in your UNIX home directory to get the following features (you will need to restart emacs to invoke these options):.emacs file.emacs file Automatic formatting - in accordance with coding style standards of many CMSC classes - (ALWAYS check with your instructor as to specific standards) Automatic formatting - in accordance with coding style standards of many CMSC classes - (ALWAYS check with your instructor as to specific standards) A working backspace key - backspace will now delete to the left of the cursor instead of invoking "help". A working backspace key - backspace will now delete to the left of the cursor instead of invoking "help". A more logical help key - It remaps CTRL-X? to be the new "help" key. A more logical help key - It remaps CTRL-X? to be the new "help" key.

8 Customizing Emacs The.emacs file contains user specific information and customizations to the XEmacs/Emacs editors. You can set up this file to do all sorts of customizations from building additional menu bars, to highlighting, to utility functionality. The.emacs file contains user specific information and customizations to the XEmacs/Emacs editors. You can set up this file to do all sorts of customizations from building additional menu bars, to highlighting, to utility functionality. There are 2 ways of going about customizing XEmacs/Emacs: There are 2 ways of going about customizing XEmacs/Emacs: Manually edit this configuration file - this requires some knowledge of the language used to configure the editor and requires the user to manually edit the ".emacs" file. Manually edit this configuration file - this requires some knowledge of the language used to configure the editor and requires the user to manually edit the ".emacs" file. Save configuration changes from within the editor - or you can save the changes from within the editor itself, and it writes out settings automatically to the ".emacs" file. Save configuration changes from within the editor - or you can save the changes from within the editor itself, and it writes out settings automatically to the ".emacs" file. I find that I tend to use a mixture of both manual and automatic editing of the ".emacs" file. I find that I tend to use a mixture of both manual and automatic editing of the ".emacs" file.

9 Sample CMSC 201.emacs File (custom-set-faces) (global-set-key "\C-h" 'delete-backward-char) (global-set-key "\C-x?" 'help-command) ;; set style to "Ellemtel" for C++ (add-hook 'c++-mode-hook '(lambda () (c-set-style "ellemtel"))) ;; set style to "Ellemtel" for C (add-hook 'c-mode-hook '(lambda () (c-set-style "ellemtel"))) ;; special effects for 'C‘ (add-hook 'c-mode-hook 'turn-on-font-lock)

10 Another.emacs File ;; no tabs please (setq-default indent-tabs-mode nil) (setq default-tab-width 4) ;; line & col nums (setq line-number-mode t) (setq column-number-mode t) ;; font coloring (setq font-lock-auto-fontify t) (setq font-lock-mode-maximum-decoration t) (require 'font-lock) ;; my email (custom-set-variables '(user-mail-address "your_username_here@umbc.edu" t) '(query-user-mail-address nil)) ;; some key bindings (global-set-key [(f1)] (lambda () (interactive) (manual-entry (current-word)))) (global-set-key [f2] 'ispell-word) ;; map that mouse wheel (global-set-key [button4] 'scroll-down) (global-set-key [button5] 'scroll-up) ;; automatic indentation upon return (global-set-key [(return)] 'newline-and- indent) ;; stop beeping (setq visible-bell 1) ;; make sure that every file has a newline (setq require-final-newline t)

11 Emacs Modes C Mode: Emacs supports C programming with a variety of options in C mode. C Mode: Emacs supports C programming with a variety of options in C mode. C -> Comment Out Region C -> Comment Out Region C -> Uncomment Region C -> Uncomment Region C -> Indent Line or Region C -> Indent Line or Region C -> Foreword Statement C -> Foreword Statement C -> Backward Statement C -> Backward Statement C++ Mode: C++ mode also supports the same functions as under C mode, but under the C++ menu. C++ Mode: C++ mode also supports the same functions as under C mode, but under the C++ menu. HTML Mode HTML Mode Lisp Mode Lisp Mode

12 Compiling in XEmacs One of the nice features of XEmacs is the ability to compile source code from within it. One of the nice features of XEmacs is the ability to compile source code from within it. Do the following to compile code from within XEmacs: Do the following to compile code from within XEmacs: Click on the Compile button Click on the Compile button Edit the prompt in the window that appears that shows you what the current command is to compile. Edit the prompt in the window that appears that shows you what the current command is to compile. By default XEmacs suggests the command "make -k". By default XEmacs suggests the command "make -k". This may or may not be what you want. This may or may not be what you want. If you do not have a makefile (or don't know what one is) then you can change the command to something like "gcc -Wall -ansi *.c" by clicking on "Edit command". If you do not have a makefile (or don't know what one is) then you can change the command to something like "gcc -Wall -ansi *.c" by clicking on "Edit command". The Compilation Output – this is where XEmacs is really useful. The Compilation Output – this is where XEmacs is really useful. If you have errors, gcc (for example) will report file and line numbers that the errors occurred on. If you have errors, gcc (for example) will report file and line numbers that the errors occurred on. XEmacs goes a step further and hyperlinks that error containing the file and line number. XEmacs goes a step further and hyperlinks that error containing the file and line number. So when you click on it, it will open that file in the current buffer and jump to that line number. So when you click on it, it will open that file in the current buffer and jump to that line number. XEmacs will also make sure that you saved all open files, to avoid compiling the sources without compiling them first. XEmacs will also make sure that you saved all open files, to avoid compiling the sources without compiling them first.

13 Wildcards Wildcards allow a single command to act upon multiple files with a name that matches a pattern. Wildcards allow a single command to act upon multiple files with a name that matches a pattern. Primarily, wildcards reduce typing and make commands more reusable. Primarily, wildcards reduce typing and make commands more reusable. * – Matches any sequence of characters. * – Matches any sequence of characters. ? – Matches any single character. ? – Matches any single character.

14 [ ] - Match Single Character [ ] – Matches any single character included in the list. [ ] – Matches any single character included in the list. The list may contain ranges, specified by a dash. E.g. [a-z] The list may contain ranges, specified by a dash. E.g. [a-z] An exclamation point ! matches any character not in the list. E.g. [!a-z] An exclamation point ! matches any character not in the list. E.g. [!a-z] Example: Example: linux3 [6]# ls file.a file.cgi file.html file.lib file.tk file.z file.c file.h file.l file.pl file.txt To list just the *.c and *.h files: To list just the *.c and *.h files: linux3 [8]# ls *.[c,h] file.c file.h Or you can specify ranges of values, such as... Or you can specify ranges of values, such as... linux3 [10]# ls *.[a-z] file.a file.c file.h file.l file.z

15 { } - Match Multiple Characters We can also denote multiple files by using the "{" and "}" characters. We can also denote multiple files by using the "{" and "}" characters. This is the multiple character version of the previous example. This is the multiple character version of the previous example. Given the following directory listing: Given the following directory listing: linux3 [11]# ls file.a file.cgi file.html file.lib file.tk file.z file.c file.h file.l file.pl file.txt To list just the *.cgi, *.pl and *.tk files: To list just the *.cgi, *.pl and *.tk files: linux3 [12]# ls *.{cgi,pl,tk} file.cgi file.pl file.tk This could be very helpful when trying to open up an entire project that consists of multiple files in emacs. This could be very helpful when trying to open up an entire project that consists of multiple files in emacs. For example: emacs *.{c,h,txt} &


Download ppt "Introduction to EMACS and XEMACS CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes."

Similar presentations


Ads by Google