my first article
words practice
Apple :apple:
Red :red_car:
Flower :white_flower:
House house
follow me
asdf
asadfg
Apple :apple:
Red :red_car:
Flower :white_flower:
House house
asdf
asadfg
Today is really cool, Song Zhang teach me to use magnet to manage windows in mac pro when use the mateview, now i use emacs to write this article and typora to preview at right hand side.
and record what she write, cool, maybe some years later, it will be meaningful.
My daught call me 'minimu', who is a little horse in the 'Princess Sofia' picture. So it's really a very cute name, i use it as the name of the dev toolbox.
We want reach the auto coding state, first we need setup the begin point, it can go to the stable state. So what is the conditions of the begin point:
with the tool, we can learning all knowledge, and develop the automate coding tools, and the tools then can auto coding.
helm is the init
plugin for emacs 1
2M-x package-refresh-contents
M-x package-install-selected-packages
Sort and align are useful when do format.
Sorting in Emacs works a lot like the command line utility sort. All commands sort lines, except the lone paragraph command.
| Command | Description |
|---|---|
| M-x sort-lines | Sorts alphabetically |
| M-x sort-fields | Sorts field(s) Lexicographically |
| M-x sort-numeric-fields | Sorts field(s) numerically |
| M-x sort-columns | Sorts column(s) alphabetically |
| M-x sort-paragraphs | Sorts paragraphs alphabetically |
| M-x sort-regexp-fields | Sorts by regexp-defined fields lexicographically |
M-x sort-lines sorts in ascending order, but if you call it with a universal argument it will reverse the sort order.
Text alignment in Emacs encompasses both justification and columnated text. In fact, the alignment engine in Emacs is so sophisticated that it is able to automatically align and justify code based on regexp patterns.
| Command | Description |
|---|---|
| M-x align | Aligns region based on align rules |
| M-x align-current | Aligns section based on align rules |
| M-x align-regexp | Aligns region based on regexp |
Emacs’s align commands are powerful and useful if you often deal with unformatted text or code. The only downside is that you have to wade through the complex mode to repeat the alignment process more than once on a single line.
Sorting and aligning are alway use regex to match, then use rules to do some modify, it is also the main idea of formatting code.
When new programming languages appear, a major mode for Emacs that does basic syntax highlighting and indenta- tion appears almost immediately. But i think auto format is more important, no matter what indent you write, code always tobe same format, that means you don't need care about indent at all.
TAB: Indenting the Current Line
| Key and Command | Description |
|---|---|
| TAB | Indents line using major mode's indentation command |
| M-i | Inserts spaces or tabs to next tab stop |
| M-x edit-tab-stops | Edits tab stops |
Disabling tab characters
If you dislike the use of tab characters and if you prefer whitespace, customize the variable indent-tabs-mode.
Changing the amount of indentation
The variable tab-width controls how many characters of spacing each tab uses. It also controls the amount of whitespace to use if you disabled indent-tabs-mode.
| Key and Command | Description |
|---|---|
| TAB | Indents a line or region as per the major mode |
| C-M-\ | Indents using major mode’s region indent command |
| C-x TAB | Rigidly indents |
In an ideal world, pressing TAB with an active region is all you need to re-indent it. Unfortunately, Emacs might not support that, or in some programming languages it is not physically possible to determine the correct indentation. Pressing TAB follows most of the same rules as line indentation: Emacs attempts to indent according to the indent-line-function and it falls back on simply inserting TAB characters (or whitespace, if you disabled indent-tabs-mode).
Typing C-M- explicitly indents the region; for some modes it works identically to TAB and in others it doesn’t. If you give the command a numeric argument, it will indent the region to that column (i.e., the number of characters) and Emacs will also use your fill prefix (if you have one) and fill the text accordingly. C-M- is occasionally useful as it respects your fill prefix. However, if you want to indent a fixed number of columns, you should use C-x TAB.
C-x TAB explicitly indents the region a certain number of columns. It
also takes negative and numeric arguments. However, if you don’t pass an
argument, Emacs will en- ter an arrow-key-driven indentation mode that
lets you interactively indent the region with
S-<left> and S-<right>.
There are several built-in tools – and just as many third-party ones – in Emacs that expand text. All of them serve a slightly different purpose, but the goal is to minimize typing and maximize automation.
| Key Binding | Description |
|---|---|
| C-x a l | Adds mode-specific abbrev |
| C-x a g | Adds global abbrev |
| C-x a i g | Adds mode-specific inverse abbrev |
| C-x a i l | Adds global inverse abbrev |
| Key Binding | Description |
|---|---|
| M-/ | Expands word at the point using M-x dabbrev-expand |
| C-M-/ | Expands as much as possible, and shows a list of possible completions |
DAbbrev is not smart. It looks at other words in your buffer and it attempts to complete the word at the point to one of those. That does not make it useless – it is still useful – it’s just that Hippie Expand is so much better.
To use Hippie Expand effectively, you should replace DAb- brev as the two – though it’s possible to use both – really don’t complement one another at all. Add this to your init file to switch to Hippie Expand:
(global-set-key [remap dabbrev-expand] 'hippie-expand)
Hippie Expand expands more than just words. The variable hippie-expand-try-functions-list is an ordered list of expan- sion functions Hippie Expand will call with the text at the point when you call M-/.
What I like most about Hippie Expand is the file name com- pletion. It works exactly like your shell’s TAB-completion: you type M-/ and Hippie Expand will try to complete the filename or directory at the point. If you ever find yourself inserting absolute paths or relative file names in code, config- uration files or documentation — Hippie Expand will make your life much easier.
Another great feature is its ability to complete whole lines. It will fall back to word completion if it runs out of ideas, and if you regularly write elisp, then Hippie Expand will guess if the text at the point is a potential elisp symbol and automatically complete it for you also.
You can record keystrokes and commands in Emacs and save them for later playback as a keyboard macro. A keyboard macro in Emacs is very different from a lisp macro and you should not confuse the two.
| Key Binding | Description |
|---|---|
| F3 | Starts macro recording or inserts counter value |
| F4 | Stop macro recording or play last macro |
| C-x ( and C-x ) | Starts and stop macro recording |
| C-x e | Plays last macro |
You can also pass the universal argument and digit arguments to the macro commands:
| Key Binding | Description |
|---|---|
| C-u F3 | Starts recording but appends to the last macro |
| C-u F4 | Plays the second macro in the ring |
| numeric F3 | Starts recording but sets counter to numeric |
| numeric F4 | Plays last macro numeric times |
Appending to the last macro (C-u F3) is occasionally useful, but passing a numeric argument to F4 is very useful since replaying the macro a set number of times is a frequent thing indeed; so much so that passing digit 0 (C-0 F4 or C-u 0 F4, for instance) will run the macro over and over again until it terminates with an error, such as reaching the end of a buffer or when a command in the macro triggers an error.
There is an entire prefix key group, C-x C-k, dedicated to Emacs’s macro functionality. There are many commands and you are unlikely to ever use most of them.
Let’s start out with the counters. When you start recording, Emacs will automatically initialize an internal counter to zero, and every time you press F3 during the recording, Emacs will insert the counter and then increment the internal counter by 1. There are, of course, many creative uses for the counter: creating numbered lists is the most obvious.
| Key Binding | Description |
|---|---|
| C-x C-k C-a | Adds to counter |
| C-x C-k TAB, F3 | Inserts counter |
| C-x C-k C-c | Sets counter |
| C-x C-k C-f | Sets format counter |
| C-x C-k q | Queries for user input while recording |
The standout command is C-x C-k q. When you call it, Emacs will tag that step in the macro recording and ask the user for advice – in effect stopping the macro temporarily to prompt the user – before continuing.
| Query Key Binding | Description |
|---|---|
| Y | Continues as normal |
| N | Skips the rest of the macro |
| RET | Stops the macro entirely |
| C-1 | Recenters the screen |
| C-r | Enters recursive edit |
| C-M-c | Exits recursive edit |
Macros in Emacs are stored in a macro ring, a concept that you should recognize from other parts of Emacs (like the kill ring and undo ring.) Creating a new macro automatically stores old macros in the macro ring without you having to do anything. The commands below let you save and recall from the macro ring, edit and bind macros to keys, and more.
| Key Binding | Description |
|---|---|
| C-x C-k C-n | Cycles macro ring to next |
| C-x C-k C-p | Cycles macro ring to previous |
| C-x C-k n | Names the last macro |
| C-x C-k b | Binds the last macro to a key |
| C-x C-k e | Edits last macro |
| C-x C-k l | Edits the last 300 keystrokes |
| M-x insert-kbd-macro | Inserts macro as elisp |
Text manialations is one aspect Emacs is especially good at, and it has a variety of tools to help you. Massaging text files for further processing or extracting pertinent information from log files are both common things to do in Emacs.
I introduced M-x occur in Occur(M-s o in helm): Print lines matching an expression as a way of collating all lines that match a certain pattern.
You can typing e begin to edit, and after you finish, C-c C-c to commit the changes to their original lines, it is especially great for keyboard macros and search & replace.
By default, M-x delete-duplicate-lines deletes the first dupli- cate line it encounters, starting from the top. With a single universal argument, it starts from the bottom and therefore deletes the last.
| Univeral Argument | Description |
|---|---|
| Without | Delete first duplicate line |
| C-u | Delete last duplicate line |
| C-u C-u | Delte only adjacent duplicates |
| C-u C-u C-u | Does not delete adjacent blank lines |
Sometimes you want to filter lines in a region by a pattern; whether that is to flush lines that match a pattern, or keep the ones that do.
Both commands act on the active region so it is common – if you want to do this on a whole buffer - to call C-x h to select the entire buffer first.
| Command | Description |
|---|---|
| M-x flush-lines | Flushes (deletes) all lines in a region that match a pattern |
| M-x keep-lines | Keeps all lines in a region that match a pattern and removes all non-matches |
Keeping lines that match a pattern is useful for large log files then you want to.
Unlike the kill commands that act on lines
(C-M-<backspace> and C-k), these commands won’t alter
your kill ring. They are also more specialized, as they insert or remove
lines with- out moving your point.
| Key Binding | Description |
|---|---|
| C-o | Inserts a blank line after point |
| C-x C-o | Deletes all blank lines after point |
| C-M-o | Splits a line after point, keeping the indentation |
| M-ˆ | Joins the line the point is on with the one above |
Managing whitespace is an issue that recurs often when you yank text from elsewhere or if you work with languages where whitespace is significant.
| Command | Description |
|---|---|
| M-SPC | Deletes all but I space or tab to the left and right of the point |
| M-x cycle-spacing | As above but cycles through all but one, all, and undo |
| M-\ | Deletes all spaces and tabs around the point |
M-SPC is useful as it trims all whitespace, to the left or right of the point, to a single whitespace character. ving none. M-x cycle-spacing cycles between leaving one, leaving none, and restoring the original spacing.
Transposing text is the act of swapping two syntactic units of text with one another.
| Key Binding | Purpose |
|---|---|
| C-t | Transpose characters |
| M-t | Transpose words |
| C-M-t | Transpose s-expression |
| C-x C-t | Transpose lines |
| M-x transpose-paragraphs | Transpose paragraphs |
| M-x transpose-sentences | Transpose sentences |
1 | A█BC |
After C-t:
1 | BA█C |
Note that the point moved forward one character so you can repeat calls to C-t to “pull” the character to the right:
1 | BCA█ |
When you are at the end of a line. C-t will swap the two characters to the left of the point:
1 | BCA█ |
After C-t:
1 | BAC█ |
This asymmetry is a surprisingly useful way of fixing typos as they occur. Fixing mistyped characters with C-t is a useful time saver as it saves you the effort of deleting both characters and retyping them.
Transposing two words with M-t works as you would expect when the words are plain text, like this:
1 | Hello █World |
After M-t:
1 | World Hello█ |
Consider this example Python code where we have a dictionary (a key-value hash map):
1 | names = { |
With the point between the key and value, a call to M-t is pure magic:
1 | names = { |
Consider what happens if we mix a balanced expression with a word:
1 | Hello,█ (insert name here)! |
After C-M-t:
1 | (insert name here), Hello█! |
Transposing lines with C-x C-t is useful however. I use it frequently to re-order newline-based lists and it’s also useful for swapping around variable assignments; changing the order functions are called, and so on.
| Key Binding | Purpose |
|---|---|
| C-d | Delete character |
<backspace> |
Delete previous character |
M-d, C-<backspace> |
Kill word |
| C-k | Kill rest of line |
| M-k | Kill sentence |
| C-M-k | Kill s-expression |
C-S-<backspace> |
Kill current line |
Some clipboard-emuivalent commands:
| Key Binding | Kill Ring Purpose | Clipboard |
|---|---|---|
| C-w | Kill active region | cut |
| M-w | Copy to kill ring | copy |
| C-M-w | Append kill | |
| C-y | Yank last kill | paste |
| M-y | Cycle through kill ring, replacing yanked text | - |
Emacs’s kill commands are best summarized with five simple rules:
Consecutive kills append to the kill ring. When you kill some words use M-d, and then move to next line and kill another three words. Your last three words are what you yank from the kill ring, not all six! The movement command broken the cycle.
The kill ring can hold many items and like the undo ring you cannot lose information in the kill ring.
The kill ring is global and between all the buffers in Emacs. You can view the kill ring - by running C-h v kill-ring.
Killing is also deleting when you don't care about the killed text.
Marking is unnecessary for most operations that involve syntactic units. There are two exceptions:
Type C-M-w, If next command is a kill command, it will append to the last element in the kill ring.
You can use the method to collect several comments into one big group.
| Key Binding | Purpose | Clipboard |
|---|---|---|
| C-y | Yank last kill | paste |
| M-y | Cycle through kill ring, replacing yanked text | - |
Cycle through the kill ring is easy: