GNULinux actual combat EMACS

xiaoxiao2021-03-06  41

Copyright (c) http://my9801.51.net This article is published in accordance with GNU Free Document Lience, and anyone can reproduce this article, reproduced, but be sure to keep this statement. The author is not responsible for any result caused by this article. 1. General Software under Linux has the above foundation, you can freely use Linux's console. However, light is relying on these, you can't edit and modify files, you cannot archive and compress (unzip) files, and you cannot enjoy audio and video entertainment and multimedia. Under the console, we can do a lot of things, including listening to music. Let's take a look at the most powerful application under the console --emacs Emacs is a powerful text editing environment under Linux, saying that it is a simple text editor too little to see it. Don't be scared, Emacs can edit files, browse the Internet, access FTP, send and receive emails, use console commands, compile and debug programs, and more. It can simply act as an operating system! However, it is precisely because it has so many features that make people who want to learn to use it must pass a painful course. Emacs is really complicated. Let us come to see the true face of the following Emacs. $ EMACS NewText.txt / * Start Emacs, use it to create a new file newtext.txt * / If you are Emacs in the console, you can ignore the top-line menu bar. It is useless under the console. This is completely different from EDIT under MS-DOS. I am not used to the menu that Alt-f calls when I start. But this does not mean that Emacs has no menu. it has. You press F10 to see (or ESC-`). That is its menu. You can use it according to its prompt. Exit the menu with Ctrl-g or press the ESC (this is a general method of exiting all EMACS commands). We have created a file, you can now enter the text directly. This is not different from the ordinary text editor. The method of saving the file is "ctrl-x ctrl-s"; file saves as "Ctrl-x Ctrl-W"; open new files "CRTL-X Ctrl-f"; exit EMACS is "Ctrl-x Ctrl-C ". Or the old saying - I'm exiting, there is not terrible. There are many commands that use a combination key in Emacs. This is also the complexity of Emacs, and there are too many commands that need back. Can't remember, you can use its menu. In X you can use the mouse and its menu bar (useful when the menu bar is available). Emacs is supported by multi-text multi-window. So you can open multiple files and then switch in different "Windows". - Note that in Emacs uses buffer (buffer) to represent the window in our usual concept, you will be a memory area. We use the menu to see existing buffer: esc-`b See existing Buffer? You can use prompting your button to switch to that buffer. (Buffer list has a shortcut: ctrl-x ctrl-b) Buffer can be turned off, then it can be turned off. When we are suspected of buffer, or when we need some Buffers, we can turn that buffer. The menu is called, select File (CURRENT BUFFER) sequentially. Or you can also press the order button: Esc-`f c I said, Emacs is an integrated editing environment, which can run the shell, this is its great place, and the top of the world loves it. Let us try.

Alt-x shell Emacs will open a new buffer, and your console prompt is in front of you. Also don't try the various commands in front. However, I have to remember the exit exit (Ctrl-D here). As for the game, I tell you where it is - Tools-> Game. Slowly study slowly, but there is a five daughter chess and checkers. Emacs comes with a very detailed help system. When you need help, press CTRL-H t to call up the help tutorial. Inside the detailed introduction, how to use Emacs, is the official manual of Emacs. Unfortunately, it is in English, and it is difficult for our people who are in English. Emacs is here, for its clearer use, please refer to the tutorial in IBM DeveloperWorks / Linux: "Life in Emacs" can not contact me, I will give you a copy. Experiment: Use Emacs to modify your / etc / fstab and /etc/lilo.conf file. Second, Emacs Advanced Application Introduced Emacs, and some basic UNIX commands. Below we will start touching a scripting language Bash (Bourne Again Shell). Bash is very much like a batch language under DOS, but is much better than batch. Master Bash, you have more capital of UNIX; BASH powerful features, it is enough to let you drive wild Linux. This unit learning requirement: You should at least understand the concept of basic computer programming, knowing the basic terms of programming languages ​​such as variables, constants, cycles, and conditional judgments. This is not that I am in the piano, and I don't have to waste your precious time. Today we have to "not leave home" in the Emacs environment, and you can listen to wonderful music. Advanced in advance - how to install software. For those who have just contacted Linux, their headache is the most pile of commands and parameters, but there is no software you are familiar with. Good system, there is no large amount of software to support, and it is not survived (IBM's OS / 2 is a typical example). But now, GNU / Linux can use software is rich, you can search for search, you will find a few major professional Linux software collections download sites, and the software reserves inside are rich. Download the package you need, install the software according to the following method. 1. Compilation and installation source code package is actually, most UNIX software is published in the form of source code, the advantage of doing this is that users can modify software according to their own system. Let's take a look at how to install the source package. Target software: zhcon-0.2.3.tar.gz Linux console chinese system #mkdir Temp / * Create a temporary directory * / #cp zhcon-0.2.3.tar.gz Temp / / * will be copied to the temporary directory * / #CD Temp #tar vxzf zhcon-0.2.3.tar.gz / * decompressed, archive one step in place, then generate a new directory * / #cd zhou-0.2.3 #. / configure / * Configure compilation environment * / #make / * Start Compile * / #make install / * installation * / to this, ENCON is installed. The last step is to install the standard operation of the source code package. After execution ./configure after the installer tells you the program after the program is installed. To uninstall the software, you can delete the directory directly (don't forget to delete the execution command in / usr / local / bin).

2, install the.rpm package with rpm, .src.rpm package RPM is Redhat Package Manager, which is the automation installation tool made by Redhat. We use it to install a MPEG player: candyplayer #cp CandyPlayer-0.1.1-1.i386.rpm temp / #cd Temp # rpm -ivh CandyPlayer-0.1.1-1.i386.rpm / * Here is a package A full name * / installation will display a progress bar and tell you the installation process. The system's integrity will be detected before the RPM installation is to see if the file is missing. If the required file is missing, the installation is refused to install it. Sometimes we will encounter the source code .SRC.RPM, which needs us to compile it yourself. Installing such a package only needs to change the parameters of the RPM command. # rpm --rebuilddb target.src.rpm / * Assume the software package called target.src.rpm * / To delete the installed software, just the following command # rpm -e calandyPlayer / * Here is the name of the software * / RPM is as simple as. 3. Installation binary procedures Some software companies do not want to publish source code, so they directly make software into a large installation file. Let's take a such thing below. MusicMatch Jukebox wants everyone to be unfamiliar? Very excellent music play software. It has a Linux version, a single binary installation file -Install-mmjb-1.43.sh. Let's pack it. Since it must be installed in X, we assume that there is already a window environment. Open a console window. #CD / TEMP #. / Install-mmjb-1.43.sh then start installation, similar to the process of installing software under Windows. It is important to note that this software allows ordinary users to install, but they cannot add links to the / var directory, which can only be installed in their home directory. The above is a method of installing various software installed in the Linux system. Let's go to today's topic. First download the two packages from www.mpg123.de. Start Emacs, create a new shell buffer, the SU rise becomes root, install these two packages described above, and restore to ordinary users. The installation order is first MPG123-0.59R.Tar.gz, and then put PlayMP3List.tar.gz. Create a Bash script addMP3 CX CF AddMP3 / * CX is Ctrl-x, the same MX is Alt-x or ESC-X, the following * / in the new buffer enters the following command #! / Bin / bash # add MP3 files to my playlist file ~ / playlist.m3u find ~ / music / -iname * .mp3 >> ~ / playlist.m3u storage CX CS, there is our first Bash program - ADDMP3. It will search for files in the MP3 format in your master folder, and then generate playlist PlayList.m3u. Sliced ​​back to the shell, perform addMP3 $ chmod x addMP3 / * to become executable * / $. / AddMp3 / * running * / this generates a playlist. Put it in / usr / local / bin, you can run AddMP3 in any directory later. When you add a new MP3 file, run this program in that directory, which will add new files to the playlist. Next we go to another console to run PlayMP3LIST. ALT-F2 / * Switch to TTY2, log in.

* / $ playmp3list playlist.m3u Why don't I run Playmp3List under Emacs? Because the Playmp3List program is used to use the ncourse library, generate a pseudo graphics interface, which is difficult in Emacs, so I will not use it in Emacs. Moreover Linux is a multi-user operating system, you can perform different programs under different console, just like more windows. And each console does not interfere with each other, so you can perform playmp3list under another console, listen to music. Use ALT-F1 to cut back and continue our work. Third, Bash syntax after reading the simple shell program last time, we will study the powerful programming capabilities of the shell. Shell is a programming language that is easy to learn, at least because it is easy to perform interactive tests respectively before combining each small program into a large program. With the modern UNIX operating system, we can write a fairly huge structured program. In the next few sections, we will learn: • Variables: strings, numbers, environment and parameters • Conditions: Boolean, Program Control in Shell: IF, Elif, For, While, UnTIL, CASE · Function · Notes In order to ensure the stringency and interest of Bash programming, I directly reference the "Linux program design" of the Wrox Press, the second chapter of the second chapter of the second chapter. I want to learn the name, I should not be pirated here, at least its source code is based on GPL. 1. Variables in the shell, do not need to make a statement in advance before using variables. We can create and use variables directly at any need. By default, the variable type is a string, even if it saves a value. SHELL and some other tools automatically identify the "value" string and operate it according to the correct method. Variable names are case sensitive, which is consistent with UNIX systems. Therefore, variables var and var and var are different variables. The variable naming principle is the same as the principle of UNIX file naming, but no space is allowed, and it is more unable to reintegrate with existing system commands. In the shell, the variable name adds a "$" character in front, you can get its content. Just use the variable, we must add "$" in front of it, unless it is assigned. Assignment variables can be used directly, or the user's input will be assigned to the variable. Please see below: $ String = Hello $ String Hello $ String = "GUTEN TAG" $ STRING GUTEN TAG $ STRING = 1 2 3 $ Echo $ String 1 2 3 $ Read String i Love YOU / * User Enter, End of Enter * / $ Echo $ String I Love You / * Read Variable Content * / * Note that if the string contains space, you must have quotation points. Also note that there is no space on both sides of the equal sign. ** I said that the numbers are also saved as a string, so the result of "String = 1 2 3" is still "1 2 3", not "6". *** Read reads the string input by the user to the end of the carriage return. 1.1, the usage of quotation marks is in general, and the parameters are separated by a blank character, such as a space, a tab or a newline, if you want to contain one or more such blank characters in one one parameter, The quotation marks must be added to the parameters. Quotation marks are also different.

If you contain variables in double quotes, you will cause "name-value replacement", and it will not be in single quotes. We can also add "/" to "/" in "$" to cancel its special meaning. Let's take a look at the role of quotation marks in the variable output: #! / Bin / sh myvar = "hi there" Echo $ myvar echo "$ myvar" echo '$ myvar' echo / $ myvar echo enter some text ievar echo ' $ myvar 'now Equals $ myvar exit 0 output results: hi there hi there $ myvar $ myvar Enter Some Text Hello World $ myvar now Equals Hello World 1.2, environment variable script is executed, some variables are set according to the system environment Declarge in initialization. These environment variables typically use uppercase to distinguish between user-defined variables, the latter typically use lowercase. Here is some common environment variables: Environment Variable Description $ Home Current User's Login Subdirectory $ PATH Separated Subscriber Subscriber Subscriber List $ PS1 Command Board Prompt, usually "$" Character $ PS2 The auxiliary prompt is used to prompt subsequent input, usually the separator of the ">" character $ IFS input area. When the shell reads the input data, a set of characters will be used as a separated character between words, which is usually spaces, tabs, and newlines $ 0 shell script name $ # Parameters to the script. $$ The SHELL Script Process ID, script generally uses it to create unique temporary files, such as / TMP / TMPFILE _ $$ 1.3, parameter variable If your scriptor also has parameters when calling, Generate additional variables. Even if you don't pass anything, "$ #" above still exists, but the value is 0.

Parameter Variable Description $ 1, $ 2 ... Script parameter $ * A list of all parameters, this is a separate variable, and the first character in each parameter is separated from the first character in the environment variable IFS $ @ "$" * "A variable that does not use the IFS environment variable is an example of using environment variables and parameter variables: #! / Bin / sh saltation =" Hello "Echo $ SALUTATION Echo" The Program $ 0 is now Running "echo" The second parameter was $ 2 "echo" The first parameter was $ 1 "echo" The parameter list was $ * "echo" The user's home directory is $ HOME "echo" Please enter a new greeting "read salutation echo $ salutation echo" The script is now complete "exit 0 output is: Hello The program ./try_var is now running The second parameter was The first parameter was The parameter list was The user's home directory is / home / yea Please enter a new greeting Sire Sire The script is Now Complete 2, Condition Test In actual work, most scripts use the "[]" or "TEST" command in the actual work - the Boolean judgment command of the shell. Note, "[]" and the space between the conditions to be checked. Because "[" and "Test" are actually the same, the "Test" command is subject to the space, so "[" will naturally have space. For the use of the "Test" command, please refer to the "Test" man page. I don't have to go out. 3. Control Structure - IF, Elif, For, While, UnTil, Case Shell has a range of control structures, and they are also similar to other programming languages. For some structures (such as a CASE statement), the shell provides a stronger function. In order to reduce the space, and let everyone look at it, I will directly list the grammatical structure and routines of each control structure, so that I don't add difficulty in understanding.

3.1, if the IF CONDITION THENTENTS ELSE STATEments #! / Bin / sh echo "is it Morning? Please answer yes or no" r t f "=" yes "]; then"]; the echo " Good morning "else echo" Good afternoon "fi exit 0 3.2, elif statements if condition then statements elif condition then statements else statements fi elif statement example #! / bin / sh echo" is it morning? Please answer yes or no "read TimeOfday IF [$ TIMEOFDAY = "YES"] THEN Echo "Good Morning" Elif [$ TIMEOFDAY = "no"]; the echo "Good afternoon" else echo "Sorry, $ TIMEOFDAY NOT Recognized. Enter Yes or no" EXIT 1 FI Exit 0 3.3, for statement for Variable in VALUES Do Statements Done for statement example #! / bin / sh for foo in bar ful 43 do echo $ foo done exit 0 3.4, while statement, if we have to loop 100 times, use for words I have to write from 1 to 100, so too tired. It does not have the convenience in Basic --for i = 1 to 100 Step 1, but it has its advantage, here is not talking. For the above situation, we can use the While structure and numerical replacement. While's grammatical structure is the example of the following case #! / bin / sh foo = 1 While ["$ foo" -le 20] do echo "here we go again" foo = $ ($ foo 1 )) DONE EXIT 0 shows the usage of $ (Command) structure. 3.5, unsil statements Until and while are very similar, just test the condition test. In other words, the loop will be repeated until the condition is really stop, not when the condition is true. Until's syntax for the unsle Condition Do Statements Done UnTil statement example #! / bin / sh until who | grep "$ 1"> / dev / null do sleep 60 done # now Ring the Bell and Announce the Unexpected User. Echo -e / / a echo "***** $ 1 HAS Just logged in *****" exit 0 3.6, the CASE statement Case structure is slightly more complicated than the other statements you have seen in front.

Its syntax is as follows: Case Variable in Patten [| Patten] ...) Statements ;; Patten [| Patten] ...) Statements ;; ... ESAC actually this syntax structure is generally seen The CASE structure is simple (such as a C / C Switch ~ CASE structure), which can be written together in multiple options (ie []). It should be noted that the statement should be used to use two semicolons ";;" instead of a semicolon. In STATEMENTS, it can be a statement and can be several statements. The following is an example of several statements: #! / Bin / sh echo "Is it MORNING? PLEASE ANSWER YES ORN" Read TimeOfDay Case "$ TIMEOFDAY" IN YES | Y | YES | YES Echo "Good Morning" Echo "UP Bright and Early this Morning? ";; [nn] *) echo" good aftern ";; *) Echo" Sorry, Answer Not Recognosed "Echo" please answer yes or no "exit 1 ;; esac exit 0 4, function shell Allows the user to define functions to include some system commands to form an execution module. In the shell, the function is very simple, write its name, plus a pair of empty "()", in a pair of curly bracket "{}", as follows: function_name () { The execution order of the Statements} shell script is the top down, so all the function declarations must appear before him execute, otherwise the shell will not find the function. 5. Comment Shell scripts use the "#" symbol to comment on the statement after it until the end. This is a bit like "//" comment in C . But all scripts, the first row is started by "#" and specifies the program that executes this script. Here is another function of "#". This is only. Fourth, instance - MINI MUSIC JUKEBOX Using the basic elements above, we can build Bash scripts. In theory, Bash scripts can also write large, complex procedures. However, this is definitely not as high as C / C , Java and other compilation types. Our purpose of learning Bash is also to reduce the work efficiency of administrators by constructing the burden on system management by constructing shell scripts. So our goal is not a large program, but a short application of short dryness. I wrote the following things with BASH and used to play my music library.

! # / Bin / bash # This is very simple Bash script.It just help us enjoy music # Copyright (C) 2003, Free Software Library # filename:. Play_music # To run this script, simply type follow command # chmod x. play_music # ./play_music # This program is free software; you can redistribute it and / or modify it # under the terms of the GNU General Public License as published by the # Free Software Foundation; either version 2 of the License, or (at . your # option) any later version # This program is distributed in the hopes that it will be useful, but # WITHOUT ANY WARRANTY;. without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE See the GNU General # Public License . for more details # You should have received a copy of the GNU General Public License along # with this program; if not, write to the Free Software Foundation, Inc. # 675 Mass Ave, Cambridge, MA 02139, USA # The first. Thing to do is to ensure That Some Global Variables That We'll Be Using # throug hout the script are set up. We set the title and track files and a temporary file. # We also trap Ctrl-C, so our temporary file is removed if the user interrupts the script. # First, define some globle variables. choice = "" Menu_choice = "" Quit = N # second, define some functions. add_mp3 () {echo "Add MP3 Files from $ home / music / mp3 to playlist file /" mp3list / "." Find $ home / music / mp3 / -iname * .mp3 >> $ home / music / mp3list} add_ogg () {echo "Add Ogg Files from $ home / music / ogg to playlist file /" oGGLIST / "." Find $ home / music / ogg / -iname * .ogg >> $ homen / music / oglist} play_mp3 () {Clear Echo "Playing MP3 files with mpg123." echo "Control Key:"

Echo "s => stop, p => pause, f => forward, b => backward, q = quit (directly)" echo "also" echo "Press Ctrl-c for next song, and Press Ctrl-C Twice Within A Short While to Quit. "MPG123 -C --List $ home / music / mp3list return} Play_ogG () {Clear Echo" Playing Ogg Files with Ogg123. "Echo" Control Key: "Echo" Press Ctrl-c for Next Song And Press Ctrl-C TWICE WITHIN A Short While To Quit. "Echo Ogg123 $ Home / Music / Ogg # as The Ogg123 Do Not Support Playlist, We Never Use The Ogglist File. Return} Welcome_MSG () {Clear Echo Echo" MINI Music Jukwbox - A very simple program written in Bash script "echo echo" Before using it, you should at least have the following two program on your system:.. "echo" ogg123 - needed for playing Ogg files "echo" mpg123 - Needed for playing mp3 files. "echo echo" do you have eachse software? (y / n): "read choice} set_menu () {Clear Echo" mini Music jukwbox. "echo echo" options: "echo echo" 1) Add MP3 Files to Playlist " Echo "2) Add Ogg Files to Playlist" Echo "3) Play MP3" Echo "4) Play Ogg" Echo "q) Quit" Echo echo "please enter you kice and kil" read menu_choice} # firm, The Application Proper Welcome_MSG IF ["$ Choice" = "y"] Then While ["$ qIT"! = "y"] do set_menu case "$ menu_choice" in 1) add_mp3 ;; 2) add_ogg ;; 3) Play_MP3 ;; 4 Play_ogg ;; q | q) QUT = Y ;; *) Echo "Sorry, Choice Not Recognized" ;; ESAC DONE ELSE EXIT 0 FI ECHO "

THANKS for using. Bye! :) "EXIT 0 5. Customize your Emacs. In fact, there is no stop. Some people insist on Emacs is a huge prehistoric organism, and some people insist on Emacs to be made. In short, Everything is around its complexity. Undoubtedly, as a text editor, Emacs is indeed too large (it has more than 70 megabits!). However, if Emacs treat Emacs as an environment (It is indeed an environment), it is very good, 70 megabytes are nothing. As ordinary users, I don't recommend you to use Emacs, VI is ok, I am not not. In devalue VI, in contrast, VI is also a good editor to respect our respect - it will hide complexity behind the scenes, through various commands, and these orders we may never use, so we don't have to go睬 睬 睬, it is a small, concise and intuitive text editor. But if you are a programmer, or a system administrator, you can't care about the brilliant interface, but powerful features and work Efficiency. This is that Emacs can bring you. Flathearted, Emacs is not more than the other editor we usually usually used, such as UltraEdit, TextPad, Emeditor, etc. The shortcuts are all. That is this, giving a lot of people in front of the people who are discouraged, they also promote the "complex" of Emacs. In fact, once you are familiar with its shortcuts, You can be as free as other software. (If you just write a few words, will you stubbornly use Word? If you want to write a C / C program, would you use Word? If you, I, I would like to use Notepad. When I first touched the computer, I was still in the Black Holder DOS era. I have been amazed for the IDE environment in Turbo C. At that time, the cliptime was pasted, and the paste is Ctrl-Ins, Shift-Ins. Deleting a row is Ctrl-y, until now I can't help but want to use Ctrl-y to delete a line. In fact, the unified software shortcut key is not MS, but WordPerfect, is because of its popularity, so that the software has followed It increases the affinity. F1 represents "Help" is it first. So don't complain about the shortcuts of Emacs. Permacs can work in excellent work in the terminal environment without graphics, and it is exactly the same below .ultraEdit Can you say nonsense? Our goal is to customize our work environment, so that we must first clarify some concepts first. Buffer buffer (Buffer) The concept sounds very high, it is actually a memory area used to save the things we entered, you can understand it as a file. In Emacs, everything is carried out in memory until you press C-X C-S to save, your file will be changed. This is a universal text preservation strategy, almost all text editors work this. The window (frame) window is not Window, which refers to the area where the text you edited is displayed. This is similar to the small window where you open each file in UltraEdit.

Mode mode (MODE) is the most important concept in EMACS, and the powerful feature of Emacs is basically provided by various modes. Commonly used C / C modes, Shell mode, Perl mode, SGML / HTML mode, etc. Based on the above concept, let us gradually study Emacs's IDE environment 1, files, buffers, and windows First, we can edit multiple files simultaneously in Emacs. You can use C-X C-F to open (or create) files at any time. But by default, the editor automatically enters the new file window (all editors are like this). If we want to see two files at the same time (such as two files), we must first split the window. Use C-X 2 to grace the window. After the segmentation, you will be disappointed, and the content in the two windows is exactly the same (including your changes to either window, will be displayed in another window)! Yes, we just split the window, but there is no switching buffer, so it is still showing the contents of the original buffer. Use C-X o to switch to the window you want, then select the target file in the buffer list (C-X C-B). This way you can take two files in the same screen. You can also split the screen with a C-X 3 vertical, divided into two regions. The window can be divided in theory, as long as you feel that there are so many small windows meaningful (try to see, even Emacs will feel that you are so stupid), so you can divide the screen into a "product" shape, just press Press CX 2, CX 3. The concept of windows and buffers is completely different, so we can "close" windows, not "off" buffer, let it disappear from our sight. This is equivalent to the "minimal window" in the graphical environment. Use C-X 0 to close the current window, use C-X 1 to close other windows other than the current window. The following list is very intuitive to show the keyboard operation of the window and buffer: ------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------------- ---------------------- Window Operation: Function Key Function CX 0 Deletes the current window and has no effect on the buffer. Note that this is a number 0. (Minimize Current Window) C-X 1 Delete all the windows other than the current, there is no impact on the buffer. (Minimize other windows) C-X 2 level segmentation of the current window. C-X 3 Segment the current window vertically. The C-X o switches the window (when there is only more than one window). Note that this is the letter O. Buffer Action: Function Key Function C-X C-F opens (created) files, create a new buffer. C-X C-S saves the current buffer to the file. C-X C-W Save the current buffer to another file (file saved as). C-X k off the current buffer. A list of C-X C-B buffers. You can use the arrow keys to select the buffer to switch. C-X C-C turns off all buffers and exits Emacs. -------------------------------------------------- -------------------------------------------------- ---- 2, mode Next Let's take a look at the mode in Emacs (MODE).

In Emacs, use a specific mode (Mode) whenever you edit a file. "Mode" in Emacs is different from "Mode" in VI. VI in the "command" and "editing" two modes, and only one mode in Emacs is the editing mode, and the commands in the emacs are completely completed. But what I said "mode" does not refer to this mode, but refers to various auxiliary environments in EMACS. When we edit normal text, use "TXT Mode", and when we write programs, such as the "SHELL (BASH) mode." When we start a file, Emacs will determine the type of file to automatically select the corresponding mode. Of course, we can also start various modes manually. Press M-X before entering the name of the mode. For example, start "C Mode", that is, M-X C-MODE. Press M-X directly, then press the two tab keys, you will get all the executable commands, which of course includes all modes. Therefore, you can't think of the name of a command, use this method. 2.1, C Mode In powerful C mode, we have powerful features such as "automatic indentation", "comments", "pre-processing extensions", "automatic status". When we edit the code under "C Mode", you can use the Tab key to generate appropriate indentation, so that the code structure is clear and beautiful. We can also specify the rules of indentation. Emacs supported indentation rules include: BSD, CC-Mode, Ellemtel, GNU, Java, K & R, Linux, Python, Stroustrup, User, Whitesmith, specified by m-x c-set-style command. The source code must be well readable and must have a good comment. Use m-; you can generate a right indent annotation. In the form of "/ * comments * /" form, C-mode is a comment in the "// Comments" form in C mode. When we highlight a certain piece of text, press C-C C-C to comment out. Emacs can use C to preprocessing part of its running code to allow programmers to detect macro, conditional compilation, and the effect of include statements. For example, I imagine the following situation: 1. Enter the code you see at the top window. 2, highlighting a zone. 3. Press C-C C-E to call macro extension. Macro Expand Region can also be selected from the menu C. Emacs will create a spy hot window to display the result of macro extension. There is still a lot of features in the C environment in Emacs, which can help programmers accelerate the development process. When running in automatic state, and when the programmer enters the code, the C environment will automatically insert a new line, process indentation and complete other relevant tasks. In many cases, do not press Enter when programming, the system will automatically process. Press C-C C-a or run M-X C-Toggle-Auto-Stat to turn on the auto mode. When tapping the keyboard in this mode, the programmer will notice that whenever you enter the semicolon, the editor will automatically position the cursor to the next line and automatically indent. The final code seems to have no use of automatic mode; it just reduces the number of programmers to create file tap keyboard. If you want to turn off the automatic mode, you only need to press C-C C-a or run M-X C-Toggle-Auto-State, the system will restore the general state. 2.2, Compiler Emacs allows programmers to compile their own software in the Emacs environment. When doing this, the editor connects the compiler's output and program code.

This means that programmers only need to click the error command (by pressing a carriage return), you can immediately locate those warnings and error messages. These options can be found in the Tools menu. When selecting Compile from the menu, Emacs requires the input to compile commands. If there is an Make file, you can accept the default settings. Otherwise, the programmer must fill in the compile command line for the correct compiler. If you encounter an error or warning at compile, Emacs will display them in separate windows. At this point, use Enter Click Error message to jump directly to the source code of the error. Sometimes, there will be hundreds of warning information in the output window; directly jump to the wrong place, can save a lot of time. As you can see, the default editorial command is called for an MAKE. Emacs can perfectly use Make and handle a lot of files, whether Emacs can support large projects, is completely unnecessary. 2.3, debugging many integrated development environments provide a debugger. Although most is just a limited debugger, Emacs provides a fully equipped excuse for the GDB debugger. When using GDB in Emacs, programmers can get all the standard features that GDBs are running at any other way. But it also includes some other properties obtained by interface enhancement. Using a GDB debugger in Emacs, you can observe how your code is running from beginning to end. This option is easier than the default GDB operation, and the default operation is just the command displayed. In addition, since the code can be re-compiled directly in the EMACS to run in the buffer, the code is changed to the code, recompile and run is a simple method. In order to adjust the debugger in the EMACS, select GDB in the Tools menu, the system prompt will appear, and enter the input to run files for debugging. When the name is entered, the GDB is called. I will see the same window as a standard GDB. When you place a breakpoint after the program's proper place, the source code window will have => tag points to point to the code of the breakpoint and highlight. The GDB window will no longer display the code. In the GDB window, you can use all common GDB commands. Using GDB in Emacs, programmers must learn any new commands. 10.2.3, another powerful function using tag Emacs is to use the ability to use the tag (TAG). According to the tag, the editor can distinguish which files belong to the same item. More importantly, the tag can also accurately point out what each file contains. For example, in the C program, the tag indicates that the file contains a specific function. When compiling files, you can jump directly to any function - regardless of the path of the file. In addition, you can use a set of files not just the current file. For example, a search command can work on a set of files. In order to provide this feature, Emacs needs to analyze files and saves tag information to be used. In general, implement this feature to use a file called Tags. Run the ETags program in the command line to create this file and give it the file name that you need index. For example: $ etags * .c etcus program analyzing source code and generating a tags file for easy use in Emacs later. Now you can use the TAGS option in the Tools menu to operate the files. You can use the find tag (m-.) To see what happened. For example, enter a function name, Emacs will jump directly to a file containing the function, and open this file, and locate the first row of the function; if the function appears in more than one file, You can use m- to continue to search for other files. 3, in Emacs, unique place in Emacs is that it can run the shell internally.

转载请注明原文地址:https://www.9cbs.com/read-75544.html

New Post(0)