The first introduction of emacs-shell mode
Shell mode is an interesting mode in Emacs. Generally, there are three main ways to run shell in Emacs. One is to use Emacs terminal emulator. This mode basically simulates a terminal in Emacs and then runs the subshell in the terminal. From the perspective of user experience, how to say? He is a terminal, right. Another way is to use shell mode. In this mode, the user interacts with the shell in an indirect way. Some people may feel uncomfortable about the word "indirect. In fact, aren't you just mixing your machine through the operating system or even applications? (If you look around, the guy who has played ENIAC hasn't come over and hit the scene ?)
Institute
In other words, indirect is a kind of beauty. In the Emacs shell mode, directly interacting with users is actually a shell
Buffer. The user just enters the command into the shell buffer, and then comint. El is responsible for transferring it to the actual
Shell; the command output is then received by comint. El and inserted into the shell buffer. What are the benefits of doing so? Didn't you see it? We have said
Shell Buffer, which is a buffer, a common buffer, and a buffer without any low-level interests! Do know Emacs
The biggest skill is to operate the buffer. That is to say, emacs can be in a buffer
Any function used in it may directly greet this place! In addition, you must add the proprietary commands provided by comint. El. So in this mode, What you face is no longer a standalone
You can change the entire mode.
Emacs. From the perspective of bragging, there is almost nothing that the guy can't do... Right? Except... Run full-screen applications, such
Vim... In other words, you can use terminal mode.
Okay, no more. Let's look at a few small cases and get a preliminary understanding of what changes have taken place in the indirect work model.
The second half-pull command in emacs-shell mode is a headache.
Don't say you never have a headache. Be honest.
In such an afternoon, when you are confident in the shell
Enter a line of command before the prompt. When it is about to end, there is another parameter... I'm not sure what he should be? It seems that you have to execute another command to confirm it... Er... What do you think should you do at this time? Tell the truth, say it right away, don't think about it!
Do you want to use ctrl C to kill the input line and then enter the command for confirmation. Then, re-enter the command you just entered... Then, let's look at the dazzling half-pull command on the screen and tell me that you must have thought about such a thing-"Well, didn't I just lose the command line ?!" (The wind outside is tight again ...) Alas, forget it. If you lose it, you lose it. What's so amazing? Let me hurry up and do the work. I have to get off work early and close the window at home. However, another damn Command was half done! Who can tell me what another command parameter should be? Why is there more trouble when you are in a hurry? (The rain has been getting off, and the wind has not stopped at all ...) At this moment, our hero finally felt intolerable: "I want to defend my labor achievements! Never waste my precious life in endless Input !" (The platform is filled with a high-definition voice, and the audience is preparing for tomato and eggs)
What? Are you switching servers? Okay, okay. Let's talk about the subject. As we mentioned before, One of the notable features of Emacs shell mode is this indirect way of working. All you do is input a line of text into the shell buffer, and then the comint. El is transferred to the shell process in the background. This means that if you didn't tell comint. el transfers your text to shell, and the shell process in the background will not know that you have come up with hundreds of ideas just waiting to calculate it. (Look back, it's still fun)
Now you can switch the lens. In this new scenario, our hero works in shell mode. Now the hero entered a half-pull command, and then suddenly remembered that a strange parameter needs to be confirmed... Now the hero does not have to shout in the arm. His face swept through an imperceptible smile, then he moved his cursor up and looked for a blank place on the screen. Unfortunately, the screen is quite full now. We can only see that our hero enters the c-o key combination in a hurry and generates a blank line by himself, then, in the blank area, quickly tap the command for confirmation, and then press enter, comint. el sends the Command confirmed in this line to shell for execution and returns the command output to Shell Buffer. At this time, what is guess? The half-left command just now is still in the original place, waiting for you there. Let's go. (The audience began to applaud. All those who applaud, after a while, they followed me to the backend to receive popsicles .)
This is indirect charm. The command must be input at the shell prompt. That is the shell rule. Why? I am not happy to deal with such shell. Now we are in a buffer. Here, I will write what I like. When I finish writing, I will tell our neighbors that comint will be happy to look for shell and I will let them deal with each other. We feel comfortable here. Let's play with ourselves here. This is cool.
In the case of emacs-shell mode, the third time I call your name, do you dare to say yes?
In travel to the West, there is such a set. It is about the king of the Golden Horn. The king of the Silver horn stole the treasure gourd of the old king. As long as it is called the name of Sun walker, then the monkey immediately ran into the gourd and turned it into a pus.
. Later, in order to escape the treasure gourd of the old gentleman, Sun Walker gave him countless names, such as "Xing sun", "Walker sun", and "Xing Guan, as long as the King of the Kingdom calls his name, Sun Wukong
Will not be able to suppress the people to go inside the treasure gourd.
Okay, okay. I only want to talk about this little Journey to the West. I promise that this section only focuses on the subject, and there must be code in it. In fact, you will surely hear that the plot in Journey to the West is definitely not nonsense. I have a name like "My name is yours. Do you agree ?" Treasure gourd.
June
Have you ever said this before? Emacs shell mode interacts with users through a shell buffer. Because this is
Buffer, so you can almost make a buffer as needed
Anything you can do. Including where to write, where to delete, and where to save and search. Here we can also use more complicated ones, or even through the buffer
To automatically generate the required commands.
Here is an example. Log on to one of our machines and check which WebSphere MQ queue managers are available?
View
There are 10 queue mananger. Now I need to start them all. The command to start queue manager is strmqm,
This command only accepts one queue manager at a time.
Name as a parameter. I need to start 10 instances. And every one is slow. I don't want to be a dumb. I have to wait until I enter these 10 commands. All these names are different.
It is not convenient to use loops. What should we do? In fact, I can ask Emacs to help me construct these 10 commands. It's easy to do, because we are in Shell
In the buffer, I only need to select the above output, press the M-| key combination, or use the shell-command-on-Region Command to use a line
Sed command to process the selected area.
sed -n -e '/Ended/s/QMNAME(\([^)]*\)).*/strmqm \1/p'
After you press enter, you will see such a buffer. This is actually a temporary buffer of \ * shell command output * \, displaying the execution result of the SED just now. This result is exactly the 10 constructed startup commands we want.
What
? You said sed.
It's so complicated to write and write. The next time I write it wrong, I will try again... Right? Too many delays? That's it. Why do we need to write this complicated stuff every time? I don't even want to install the product directory every time
Write it all. I can define it as a command abbreviation called sedstrmqm. Is this name much easier to remember? The method is also very simple. Because this is a very long command, use M-B first.
Command count: the total number of so-called word contained in this line of commands. That is to say, how many times can I press the M-B key combination to move the cursor from behind p' to the front of SED? Here is
10 times. Enter the c-u 10 m-X Add-global-abbrev command and use sedstrmqm as the abbreviation.
Description
After that, we just got the 10 commands and stayed in the next room. Someone has to get them. Of course, copying and pasting is useless. Get
Buffer, and then the buffer... Mm in the next shift has long been impatient. Since there are mm
You must show off some dazzling things. Enter M-X come-here in minibuffer, and then
Said: I called your name. Do you dare to say yes? After you press enter, an input buffer name: prompt will appear in the minibuffer prompt area. The default value is
Name is the * shell command output * buffer we want. Press enter to view the buffer.
The content is automatically included in our treasure gourd.
How
? Okay? Will it be fun? Have you ever played? (Well, it seems like the word in Chen pest's sketch.) In fact, this come-Here
It is also very simple. There are two lines of code in total. However, it's really interesting. I have a pretty good idea in my own Emacs extension.
Jump, which is used in multi-window mode. I usually open four shell modes in Emacs.
Log on to multiple working machines in the window. When I finish a command line in a window, this command usually needs to be run on another machine. At this time, I will tell him
Jump! It automatically jumps to another window, saving me the trouble of copying and pasting it. The jump code is also very simple, and it takes effect in two or three lines. Next, let's talk about multiple windows.
Now, today's commentary program is over. Audience, please follow our program notice next time. Let's say that our slogan is, let's make all our work a game !!! (All the actors clapped on stage, bowed, and took the Popsicle to the backend ....)
(defun come-here (&optional arg) "Bring content from specific buffer to current buffer" (interactive (list (let (( arg (read-buffer "Input buffer Name: " "*Shell Command Output*") )) (insert-buffer-substring (get-buffer arg)) )) ))