The last introduction of how to insert a simple operation to delete text in Emacs, as well as some assorted commands, is pretty easy. This time skip editing this part, introduce the minibuffer in Emacs, er, translate come to call mini buffer, listen to more uncomfortable, behind still use e text bar.
First, the initial knowledge minibuffer
Minibuffer is the location of the Emacs command to read complex parameters. such as filenames, buffer names, command names, and Lisp expressions. Minibuffer is displayed in the Echo area, when Minibuffer is in use, a colored prompt appears and ends with a colon, entering parameters according to the prompt information, to enter the submission. Cancel Minibuffer using C-g, which is the cancellation command described in the previous section.
In fact, Minibuffer is not too mysterious, the most common place is to open the file when prompted us to enter the filename:
When you press C-x c-f, the echo zone will look like this, where find file is the Minibuffer prompt, because it is blue. The following path is the default value that Minibuffer automatically adds, and we can set the parameter option Insert-default-directory to nil to close the default path.
Here insert how to set the Emacs parameter option, we type M-x set-variable ret insert-default-directory ret After input nil can, here's RET representative return. Change back to default, enter T as last input. In fact we press M-x set-variable also activated minibuffer.
Ii. editing in the Minibuffer
We can consider minibuffer as a buffer similar to the main input area, and there is a buffer in the minibuffer, which means that some command minibuffer in the main input area can also be used. Also we look at the above picture, using C-A can move the cursor to the position of the D character, and then press C-E cursor back to the end, you can also use m-backspace delete "info/" back to the parent directory. However, it is important to note that RET is a minibuffer terminator instead of a newline character, so if we need to insert a new row we cannot use a carriage return, but we use C-o. Also for the tab, SPC,? (the first two tabs and the space bar respectively) in the Minibuffer is often used for auto-completion, so it is not directly input, we need to use C-Q to insert, such as tab, with C-q tab to replace. It can be said that Minibuffer and the main input area basically the same, the same shortcut keys, the same operation, copy and paste functions are readily available.
Typically, Minibuffer has only one row in the screen, and as you enter, Minibuffer automatically resizes to fit. Variable resize-mini-windows is used to control the size change of the Minibuffer, its default value is Grow-only, the size is only increased, set to T, if you delete a row will automatically shrink, set to nil, will not move. The variable max-mini-window-height controls the maximum value of the minibuffer height, which is set to a floating-point number that represents the percentage of the entire window, and an integer that indicates how many rows can be. The default value is 0.25.
When we operate Minibuffer can also control another window, C-m-v command is used to scroll the text of another window, this is the page down, C-m-s-v is to page up, we have to see clearly, this is not four keys together, if you accidentally pressed the S key, You will find out is QQ Chat window, so out of China's vast number of QQ users to consider, Emacs changed it to uppercase S, that is, plus Shift key, er, this is the longest I have seen the keys and more perverted. In fact, there is a concise way, m-pageup and M-pagedown, but these two keys are not in the main keyboard area, see you mood.
Minibuffer The general situation is not allow recursive call, that is, we can not double-press two times C-x c-f, it will prompt minibuffer is in use, we may also set the variable enable-recursive-minibuffers as T to activate the recursive call, But it's easy to make mistakes, so try to avoid them.
Third, automatic completion
Emacs in the command there are so many, we can not remember each of the live, the computer path is also very long, remember a few characters are also very normal, this time the automatic completion is very important. There are four key tabs, SPC, ret, and/or auto-completion. Let's look at the exact definition of them.
TAB as many characters as possible in the Minibuffer, and if not, list all possible complements. The corresponding command minibuffer-complete.
SPC a word in up to minibuffer, if not met, lists all possible complements, and SPC is not available when the path is entered. The corresponding command Minibuffer-complete-word.
RET submits the text in the Minibuffer, or selects the first possible complete commit. The corresponding command minibuffer-complete-and-exit.
? List all possible complements. The corresponding command minibuffer-completion-help.
Is the example of auto-completion when we Press INS tab tab:
The first tab complements "ert-", and the second tab lists all possible complements.
Again carefully read these keys, tab is the most automatic completion, you can say that each operating system shell Support tab Auto-completion, its design goals are as much as possible to complement our input, and a complete need to meet the following three criteria:
- The text in the Minibuffer before the cursor must match the content at the beginning of the completion candidate, and if there is text after the cursor, it needs to be the string for the remainder of the fallback.
- If the previous condition is not satisfied, partial match completion is used, and the text in the Minibuffer is separated by a "-" or a space, respectively. For example, enter "Em-l-m", and then press TAB, it will be complete to "Emacs-list-mode".
- If there are still no satisfied candidates, the first guideline continues to be used, but the text after the cursor is ignored.
The space bar matching mode is similar to tab, but it only matches to the next "-" or space, such as the input auto-f after the space will be completed auto-fill-, you need to press a space will be fully complete for auto-fill-mode. In addition, you can use the wildcard character "*" in the tab and SPC matches to represent any one or more characters.
In the absence of an exact match, Emacs lists all matches that meet the criteria, and we can use several methods to select an item.
Mouse-1, Mouse-2, is the mouse around the key.
or by pressing M-V in Minibuffer, you switch to the Completion candidate window, and we can use RET to select the item (choose-completion) at the cursor position. Or use the left and RIGHT arrow keys to move the cursor (next-completion, previous-completion). Unfortunately, there is no faster way to move up or down, m-f and M-b are moved to the "-" character position. Again, if you want to use some of the above commands, you must open the Minibuffer recursive call.
When we submit input using RET, there are three different cases of auto-completion, and three cases are differentiated according to the usage of the submitted content.
- Strict matching, so the name of meaning, that is, the input content to exactly match an item before the line. When we use C-x K to close a buffer, we are prompted to enter the buffer name, which is the exact match to use. If you cannot find the buffer command, it will not execute.
- Careful matching, this is similar to the strict match, the difference is that if you do not find an exact match after the entry Minibuffer does not exit, but the automatic completion, and then press RET to submit the input, and then exit Minibuffer. Careful matching is used when reading a file that must exist.
- Loose match, C-x c-f is a typical loose match, there is a consistent open this file, no one to create a new file.
Auto-Complete also has a icomplete mode, using M-x icomplete-mode Start, the role is to automatically update the possible completion.
Next, we will introduce some auto-completion variables.
Completion-auto-help, when set to nil, there is no completion candidate list, must be used? Manual recall. Set to lazy, a complete list of candidates appears when you press the Second tab.
Completion-ignored-extensions, its value contains some strings, including such as ". O", ". Elc", "~" and so on, when the input file name auto-completion will not select the end of the file, However, when all possible candidates are ignoring the suffix, all of the ignores are invalid. For example, there are foo.c and foo.elc two files, Input Foo tab, will get foo.c, but you enter FOO.E TAB or will appear foo.elc. In addition, if a value of one of its items ends with a "/", it represents a folder.
Read-file-name-completion-ignored-case, a value of Non-nil indicates that case is ignored and nil is not ignored.
Iv. History of Minibuffer
Each input in Minibuffer is saved in the history of Minibuffer, and we can easily recall one of the commands we entered earlier.
M-p moved to the previous bar in Minibuffer history, previous-history-element.
M-n moves to the next next-history-element in Minibuffer history.
M-r regexp RET moves to the previous bar in Minibuffer history, using regular expressions, previous-matching-history-element.
M-s regexp RET moves to the next bar in Minibuffer history, using regular expressions, next-matching-history-element.
As a reminder, these are minibuffer active to use. The history that is removed after each move replaces the current input, and when we continue to use M-n on the last record, a record is still present, but this record is an Emacs guess. It is also necessary to note that Emacs maintains a number of different histories, such as the path history of our open files, or we invoke the compiler's compilation parameter history, and the Emacs search history is also in the corresponding history list.
The parameters about Minibuffer history are commonly two, history-length the history queue maximum, history-delete-duplicates whether to delete the same history. It is literally not to say it carefully.
If we are now in the main window and can quickly recall the most recently executed commands, use C-x ESC ESC (Repeat-complex-command) to execute the command in the nearest Minibuffer again, Emacs will prompt you whether to execute. We can also use M-p, m-n to choose other history. The command m-x list-command-history can list all recent history.
Finally, minibuffer the essence of history, they are stored in the Lisp variable command-history items, each of which is saved each execution of the command and parameters.
Summary:
This is a lot of things to say.
Keys |
Command |
Role |
(none) |
Set-variable |
Setting variables |
C-m-v |
Scroll-other-window |
Scroll down another window |
M-pagedown |
Ditto |
Ditto |
C-m-s-v |
Scroll-other-window-down |
Scroll up another window |
M-pageup |
Ditto |
Ditto |
TAB |
Minibuffer-complete |
Auto complement Minibuffer |
Spc |
Minibuffer-complete-word |
A word in auto-complement Minibuffer |
Ret |
Minibuffer-complete-and-exit |
Submit Minibuffer |
? |
Minibuffer-completion-help |
List all possible complements |
RET (in candidate list) |
Choose-completion |
Select candidate |
← |
Previous-completion |
Previous candidate |
→ |
Next-completion |
The next candidate |
C-x K |
Kill-buffer |
Close a buffer |
(none) |
Icomplete-mode |
Automatic Update completion mode |
M-p |
Previous-history-element |
Previous history |
M-n |
Next-history-element |
Last history |
M-r (RegExp) |
Previous-matching-history-element |
Previous history, using regular expressions |
M-s (RegExp) |
Next-matching-history-element |
Last history, using regular expressions |
C-x ESC ESC |
Repeat-complex-command |
Repeat the last command |
(none) |
List-command-history |
List all command history |
AutoComplete is case sensitive
Variable |
Role |
insert-default-history |
|
resize-mini-window |
minibuffer size change mode |
Max-mini-window-height |
minibuffer maximum height |
Enable-recursive-minibuffers |
|
|
|
completion-ignored-extensions |
|
read-file-name-completion-ignored-case |
history-length |
|
history-delete-duplicates |
|
PS: The meaning of the highlighted text appears in the text, red is the shortcut key, the first few chapters are so used; Green is the command, that is, the content entered after pressing m-x; the blue is the variable name of Emacs.
Not to be continued ...
Emacs Tutorial (iv)