步步为营,零秒精通 Emacs

第二章的拓展topic1:

这么多的键绑定, 从语义化的理解是一方面, 更重要的一方面可能应该去找捷径, 比如调用直觉和由此带来的强烈满足感和成就感.

编辑过程中对blank-lines的处理,

C-x C-o调用(delete-blank-lines)

C-x C-o的绑定键没有逻辑, o是个洞吗? 一个洞代表空行?

Emacs Manual中很多这样的处理细分领域的绑定键, 头悬梁锥刺股的用下来, 对emacs的热情和兴趣早早磨光了.

回到C-x C-o调用(delete-blank-lines)

假设有这样四行

"The quick brown fox jumps over the lazy dog"


"The quick brown fox jumps over the lazy dog"

当前的光标在第一行上的fox,后 发现两行文字中间的空行是多余的, 因此要删掉.

需要动用人肉劳力这样做:

  1. C-n 管标移动到下一行
  2. 连续两次C-k删除空行
  3. 然后凭借超强的记忆力(记住刚才是在fox的位置, 和导弹一般精确的点位控制回到fox后面.

劳神费力.

应用C-x C-o呢? 可以在第一行的任意位置上调用C-x C-o, 下面的空行会自动删除.

怎样从直觉上理解呢?

  1. 光标在第一行的某个点上, 然后调用一个命令, 在光标之外的另外一个地方会立刻发生某件事情, 这就是远程控制呗;
  2. 更直觉一点, 这边是"意念移物"呗,

由此从直觉里生发的成就感和兴趣会驱动我们应用更加复杂的命令和组合.

P.S. 作为对"零秒" 这个标题党的补充.

Appendix B: Git Version Control

|-----------------------+------------------------------+----------------------------------------------|
| Objects               | Features                     | Actions:                                     |
|-----------------------+------------------------------+----------------------------------------------|
| 0.Introduction        |                              |                                              |
|                       | Faster commands              |                                              |
|                       | Stability                    |                                              |
|                       | Isolated Environments        |                                              |
|                       | Efficient Merging            |                                              |
|-----------------------+------------------------------+----------------------------------------------|
| 1.Overview            | Objects:                     | Actions:                                     |
|-----------------------+------------------------------+----------------------------------------------|
|                       | 1.working directory          | configure                                    |
|                       | 2.staging area               | recording                                    |
|                       | 3.Commit history             | undoing                                      |
|                       | 4.developmnent branches      | branch (non-linear)                          |
|                       | 5.remotes                    | remote                                       |
|-----------------------+------------------------------+----------------------------------------------|
| 2.Configuration       | 1) User Info:                |                                              |
|                       |                              | git config --global user.name                |
|                       |                              | git config --global user.email               |
|                       | 2) Editor:                   |                                              |
|                       |                              | git config --global core.editor emacs        |
|                       | 3) Alias:                    |                                              |
|                       |                              | git config --global alias.ci commit          |
|                       | .inspect                     |                                              |
|                       |                              | git config -l                                |
|-----------------------+------------------------------+----------------------------------------------|
|                       | help:                        | git help log                                 |
|                       |                              | man git-log                                  |
|                       |                              | tldr git-log                                 |
|-----------------------+------------------------------+----------------------------------------------|
| 3.Recoding Chaneges   |                              |                                              |
|                       | Staging area:                |                                              |
|                       |                              | git add                                      |
|                       |                              | git rm --cached                              |
|                       | .inspecting:                 |                                              |
|                       |                              | git status                                   |
|                       |                              | git diff (--cached)                          |
|-----------------------+------------------------------+----------------------------------------------|
|                       | Commits                      |                                              |
|                       |                              | git commit                                   |
|                       | .inspecting                  |                                              |
|                       |                              | git log                                      |
|                       |                              | git log --oneline  <file>                    |
|                       |                              | git log <since> ... <until>                  |
|                       | Tagging commit               |                                              |
|                       |                              | git tag -a v1.0  'stable version'            |
|-----------------------+------------------------------+----------------------------------------------|
| 4.Undoing Changes     | 1) Woriking directory        |                                              |
|                       |                              |                                              |
|                       |                              | git reset --hard HEAD                        |
|                       |                              | git clean -f (git rid of unstaged files)     |
|                       | .individual file:            |                                              |
|                       |                              | git checkout HEAD <file> (most frequent)     |
|-----------------------+------------------------------+----------------------------------------------|
|                       | 2) Staging area              |                                              |
|                       |                              | git reset HEAD <file> (extra staged file)    |
|                       |                              | (No --hard here)                             |
|-----------------------+------------------------------+----------------------------------------------|
|                       | 3) Commits                   |                                              |
|                       | .resetting                   |                                              |
|                       |                              | git reset HEAD~1                             |
|                       | .reverting                   |                                              |
|                       |                              | git revert <commit-id> (created new commit ) |
|                       | .ameding                     |                                              |
|                       |                              | git commit --amend                           |
|-----------------------+------------------------------+----------------------------------------------|
| 5.Branches            | 1) Manipulate brnaches       |                                              |
|                       | .listing branches            |                                              |
|                       |                              | git branch                                   |
|                       | .creating branches           |                                              |
|                       |                              | git branch <name>                            |
|                       |                              | git checkout -b <name>                       |
|                       |                              | .git/refs/heads/develop                      |
|                       | .deleting branches           |                                              |
|                       |                              | git branch -d, -D                            |
|                       |                              |                                              |
|                       | Checking out branches        |                                              |
|                       |                              | git checkout  <branch>                       |
|                       | .detached                    |                                              |
|                       |                              | git checkout -b <new-branch-name>            |
|-----------------------+------------------------------+----------------------------------------------|
|                       | 2) Merging branches          |                                              |
|                       | .fast-forward:               |                                              |
|                       |                              | git checkout master                          |
|                       |                              | git merge some-feature                       |
|                       | .3-way merge:                |                                              |
|                       |                              | same as the above                            |
|                       | .merge conflicts             |                                              |
|                       |                              | <<<<<<HEAD                                   |
|                       |                              | ==================                           |
|                       |                              | >>>>> some-feature                           |
|-----------------------+------------------------------+----------------------------------------------|
|                       | 3) Branches workflow         |                                              |
|                       | .types of branches           |                                              |
|                       |                              | permanent or topic                           |
|                       | .permanent_branch            |                                              |
|                       |                              | master(public ), develop,                    |
|                       | .topic_branch                |                                              |
|                       |                              | feature and hotfix                           |
|-----------------------+------------------------------+----------------------------------------------|
|                       | 4) Rebasing:                 |                                              |
|                       |                              | git checkout some-feature                    |
|                       |                              | git rebase master                            |
|-----------------------+------------------------------+----------------------------------------------|
|                       | .interactive_rebasing:       |                                              |
|                       |                              | git rebase -i master                         |
|                       |                              | (Notice for rewriting)                       |
|-----------------------+------------------------------+----------------------------------------------|
| 6.Remote Repositories |                              |                                              |
|                       | 1) Manipulate remotes:       |                                              |
|                       | .listing remotes:            |                                              |
|                       |                              | git remote                                   |
|                       |                              | git remote -v                                |
|                       | .creating_remotes:           |                                              |
|                       |                              | git remote add <name> <path-to-repo.         |
|                       | .deleting_remotes:           |                                              |
|                       |                              | git remote rm <remote-name>                  |
|-----------------------+------------------------------+----------------------------------------------|
|                       | 2) Remote branches:          |                                              |
|                       | .fetching_remote_branches    |                                              |
|                       |                              | git fetch <remote> <branch>                  |
|                       |                              | git branch -r                                |
|                       | .inspecting_remote_branches: |                                              |
|                       |                              | git log origin/master                        |
|                       | .merging/rebsing:            |                                              |
|                       |                              | git checkout some-feature                    |
|                       |                              | git fetch origin                             |
|                       |                              | git merge origin/master                      |
|                       |                              | (littered with meaninglesss merge commits)   |
|                       |                              |                                              |
|                       |                              | git checkout some-feature                    |
|                       |                              | git fetch origin                             |
|                       |                              | git rebase origin/master                     |
|                       | .pulling:                    |                                              |
|                       |                              | git pull origin/master (--rebase )           |
|                       | .pushing:                    |                                              |
|                       |                              | git push <remote> <branch>                   |
|                       |                              |                                              |
|-----------------------+------------------------------+----------------------------------------------|
|                       | 3) Remote workflow:          |                                              |
|                       | .bare_repository:            |                                              |
|                       |                              | git init --bare <path>                       |
|                       | .centralized_workflow:       |                                              |
|                       |                              | git fetch origin master                      |
|                       |                              | git rebase origin/master                     |
|                       |                              | git push                                     |
|                       | .integrator_workflow:        |                                              |
|                       |                              | github的模式                                 |
|-----------------------+------------------------------+----------------------------------------------|
| Conclusion            |                              |                                              |
|                       | 1.working directory          |                                              |
|                       | 2.staging area               |                                              |
|                       | 3.commit history             |                                              |
|                       | 4.branches                   |                                              |
|                       | 5.remotes                    |                                              |
|-----------------------+------------------------------+----------------------------------------------|
1 个赞

修改成了M-x find-file, C-x C-f,
这样下文可以自然进入到编辑功能, 先把文件打开, 才好编辑.

对比Search功能的Emacs操作与命令行操作

Emacs的优势是对数据和查询结果的便捷二次处理.

比如想从宏观上了解下Emacs手册中中全部whitespace操作.

可以从Terminal中完成

find . -type f -exec grep --color -inH --null -e  "whitespace" \{\} +

可以看到结果, 但没法做简单的统计.

即使加上nl

 find . -type f -exec grep --color -inH --null -e  "whitespace" \{\} +

也只能大略了解到’whitespace’在整个文档中, 有95句话提到过.

而在Emacs中执行同样的命令:
C-x grep-find;

则瞬间眼明心亮, 有95句话有一个或多个whitespace这个单词, 总计有151个. 而且在 Killing.org 这个文件中有6句话, 在 text.org 中有5句, 在 Display,org 中有17句话, 在 Program.org 中也有17句, 等等,

Emacs中执行命令的突出优势是简单方便的二次处理.

对初学者帮助很大

初学, 有多初?
看看这个帖子,

假如是自己从零DIY, 后面几章真正施展Emacs的强大功能之处,
可能在你的机器上不能复现.

目前的流程图 Meta --> Control —> Cursor —> Edit

由Meta的词源语义出发分析Emacs的快捷键绑定, 引入Ctrl键简化输入过程, 光标的移动作为edit的前置步骤, 以find-grep查询收尾基本的编辑功能.

在切入到God’s Eyes(Dired) and God’s Hands(Booksmarks)之前,
先光速浏览File的基本操作(读取和保存):
C-x C-f (M-x find-file) 找到并打开文件
C-x C-r (r是read-only), 比如浏览自己的配置文件, 要避免无心修改掉东西.
C-x C-s (s,save) 保存单个文件
C-x s 保存全部文件, 保存全部文件功能更常用, 因此组合键也少.
最后在个人配置上添加两行, 设置自动保存文件.

(setq auto-save-visited-mode t)   
(auto-save-visited-mode +1)

以上完结, 马上进入精彩的部分.

Dired初窥

在EmacsManual目录下调出Dird后,
快速略扫各个文件的主要内容.

在目录上C-n和C-p上下移动光标.

dired%E5%88%9D%E7%AA%A5

** Dired操作:

1. Entering Dired: C-x d
2. Navigation: C-n C-p
3. Delete files: d, x, D
4. Flagging many files at once:
1) # (file start with #)
2) ~ (flag all backup files whose name end with ~)
3) % d regexp (delete all match regex)

5. Visiting Files
- f or e (visit current file)
- o (another window to display and switch fucus)
- C-o (visit but not switch focus)
- v (view-mode)
- ^ (dired-up)

6. Dired Marks vs. Flags
- * * excutable files
- * m mark
- * @ symbolic link
- * / directory
- * u remove the current
- U remove all
- % m regex
7. Operatons on files
- C copy
- D delete
- R rename
- H hardlink
- S symblic link
- Z, c
8. Shell Commands in Dired
- 这次阅读最大的收获, 可以直接 & 和 X
9. Transform files names
- % u Uppper-case
- % l lowercase
10. File comparision
- dired-diff
11. Subdirectory in Dired
- i
12. Subdirectories switch in Dired
-
13. Moving Over Subdirectories
 -
14. Hiding Subdirectories
 -
15. Updating the Dired Buffer
 g
16. Dired and find
find-name-dired
17. Editing the dired Buffer
 wdired
18. View Images thumbnails
 image-dired-display-thumb
1 个赞

顶, 坚持写完。

1 个赞
** Register操作归纳

M-x view-register r
# 以下所有的命令最后一个letter, 可以自定义为a-z等任何字母.
1. Saving Positions in Registers
   C-x r r (register r)
   # 可以自定义为 C-x r a (能记住便好)
   C-x r j r (register jump to r)
2. Saving Text in Registers
   C-x r s t (register save to r) "text"
   # 修改为C-x r s t (t for text)
   C-x r i t (regiester insert to r) "text"
   M-x append-to-register t
   M-x prepend-to-register t
3. Saving Rectangles in Registers
   C-x r r e (rectangle region to e);
   # 此处省略一个r, 完整语义(C-x r r r e)
   # r been taken so use e for rectangle
   register rectangle region to e
   C-x r i e(rectangle insert to e )
4. Saving Window Configurations in Registers
   C-x r w w (register window to w)
   # 很好用的命令, 可以早上8点保存一个布局,晚上再看看, 临时记住的布局用winner-mode
   C-x r f f (register frameset to f)
   C-x r j f (jump)
5. Keeping Numbers in Registers
   No practical value.
6. Keeping File Names in Registers
   (set-register r '(file . name))
   (set-register ?z '(file . "/gd/gnu/emacs/19.0/src/ChangeLog")
   # prelude for bookmarks
7. Keyboard Macro Registers
   --
8. Bookmarks
   C-x r m (register bookmark for the current file)
   C-x r m  a-name
   C-x r M (not overwrite)
   C-x r b bookmark (jump or write)
   C-x r l (list all bookmarks)
   M-x bookmark-save
   M-x bookmark-load filename
   M-x bookmark-write filename
   M-x bookmark-delete bookmark
   M-x bookmark-insert-location bookmark

Additional

建议不要从零开始折腾Emacs,.
两步安装doom-emacs, 可以实现此项目内的所有操作.

Org Notebook的三个部分梳理:

  1. Documents Structure
  2. Table
  3. Hyper links

假期结束,今天恢复更新。

2 个赞

4. Emacs as a Notebook by Org

Appendix D: Email Management

Org-manual前四章(Notebook功能)总结:

  1. introduction 2) Documents 3)Table 4)Hyperlinks
- **Documents Structure**
 - Visibility Cycling
   + C-u C-u TAB :: Switch back to the startup visibility of the buffer
   + C-u C-u TAB :: org-set-startup-visibility
   + C-c C-k :: outline-show-branche
   + C-c C-x b :: org-tree-to-indirect-buffer
   + C-c C-j  org-goto :: Jump to a different place without changing the current outline visibility.
 - Structure Editing
   * C-RET :: org-insert-heading-respect-content
   * M-S-RET :: org-insert-todo-headin
   * C-S-RET :: org-insert-todo-heading-respect-content
   * TAB :: org-cycle
   * M-LEFT :: org-do-promote
   * M-RIGHT ::  org-do-demote
   * M-S-LEFT :: org-promote-subtree
   * M-S-RIGHT :: org-demote-subtree
   * M-UP :: org-move-subtree-up
   * M-DOWN :: org-move-subtree-down
   * C-c @ :: org-mark-subtree
   * C-c C-x C-w :: org-cut-subtree
   * C-c C-x M-w :: org-copy-subtree
   * C-c C-w :: org-refile
   * C-c ^  :: org-sort
   * C-x n s  :: org-narrow-to-subtree
   * C-x n b  :: org-narrow-to-block
   * C-x n w  :: widen
   * C-c * :: org-toggle-heading
 - Motion
   略
 - Sparse Tree
   + C-c / :: org-sparse-tree
     然后调用swiper
 - Plain Lists
   * TAB :: org-cycle
   * M-RET :: org-insert-heading
   * M-S-RET :: insert a new item with a checkbox
   * M-UP and M-DOWN :: move the items up and down
   * M-LEFT and M-RIGHT :: Decreae/increase the indentation
   * M-S-LEFT and M-S-RIGHT :: Decrease/increase indentations
   * C-c C-c :: toggle checkbox
   * C-c -  :: Cycle different bullets
   * S-LEFT and S-RIGHT :: cycles bullet styles
   * C-c *  :: Turn a plain list item into a headline
   * C-c C-* :: Turn the whole plain list into a subtree of the current heading. ()
   * C-c ^ :: Sort the plain list.
 - Drawer
   + C-c C-x d :: org-insert-drawer
   + C-c C-z  ::  Add a time-stamped note
 - Blocks
   略
- **Tables**
 - Built-in Table Editor
   + C-c | :: org-table-create-or-convert-from-region
 - Column Width and Alignment
   + C-c C-c :: org-table-align
   + M-LEFT and M-RIGHT :: org-table-move-column-right
   + M-S-LEFT and M-S-RIGHT :: org-table-delete-column and org-table-insert-column
   + M-UP and M-DOWN :: org-table-move-row-up and org-table-move-row-down
   + S-UP and S-DOWN :: org-table-move-cell-up and org-table-move-cell-down
   + M-S-UP :: org-table-kill-row
   + M-S-DOWN :: org-table-insert-row
   + C-c - :: org-table-insert-hline
   + C-c RET :: org-table-hline-and-move
   + C-c ^ :: org-table-sort-lines
   + C-c +  :: org-table-sum
   + S-RET :: org-table-copy-down √
   + C-c TAB :: org-table-toggle-column-widt
   + C-u C-c TAB :: org-table-shrink
   + C-u C-u C-c TAB :: org-table-expand
 - Column Groups
   + <>  :: Column Groups
 - The Orgtbl Minor Mode
   + M-x orgtbl-mode ::
 - The Spreadsheet
   略
 - Org Plot
   略
- **Hyperlinks**
 + internal link :: =[[internal-link]]=
 + file:projects.org::regex
 + gnus:group
 + shell:ls
 + elisp:(find_file "elisp.org")
 + elisp:org-agenda

在竞聘管理员, 差了20多票, 抽空给个支持.

此处提到两处弥足珍贵的键位绑定竟然空了出来, 没有被emacs作为绑定键使用。因而有机会将其自定义为”向上半屏翻页“和“向下半屏翻页”。

meta-n 调用 scroll-half-page-down, meta-p调用scroll-half-page-up。

然而,这个方法并不好用,尤其是快速浏览org笔记的时候,会被晃得晕头转向,还不如繁琐的M-r C-l C-l好用,因为焦点一直会停在中间。

而因为M-r C-l C-l 过于繁琐,出于本能,需要快速浏览的时候,就会只是快速的按键 C-n 不断地下一行。

作为解决方案,将

(scroll-up (/ (window-body-height) 2)))

修改为

(scroll-up (/ (window-body-height) 3)))

用了一段时间,尝试了不同的数值,三分很好用也符合直觉。速览的时候,M-n 然后 C-n再精确定位。

将函数名重新定义为 previous-multilines 与单行的previous-line保持一致。

(defun previous-multilines ()
  "scroll down half the page"
  (interactive)
  (scroll-down (/ (window-body-height) 3)))


(defun next-multilines ()
  "scroll up half the page"
  (interactive)
  (scroll-up (/ (window-body-height) 3)))

(global-set-key "\M-n" 'next-multilines) ;;custom
(global-set-key "\M-p" 'previous-multilines) ;;custom

关于进格删除(forward)与退格删除(backward)的语义化绑定。

退格删除则按键 backspace(Macbook上没有backspace键,可以将delete擦掉,改成backspace),backspace语义化对应backwords。

C-backspace 退格删除一个字符
M-backspace 退格删除一个word

进格删除的forward绑定到了字符 d(d for delete) 键上,

C-d 进格删除一个字符
M-d 进格删除一个word

C-k 进格删除到行尾
M-k 进格删除到句尾

C-x Backsapce 退格删除到行首

只有Backspace键是语义化的backword,其余都是forward。

最后,忘掉delete键,d 就是语义化的 delete。多余的delete键会引发逻辑上混乱。

1 个赞

这个编号有工具自动编号吗?还是自己手动编号的