Emacs is the 2D Command-line Interface

In this article, I’d like to argue that Emacs largely follows the Unix philosophy in its problem domain: working with text , and can be seen as a two dimentional version of the command-line interface.

有什么收获分享一下?

初读的时候,个人觉得 2D 这个概念是比较新颖的。

$ echo "hi" | grep "hi"

如果用任何一个编辑工具,都可以写成下面的形式,但得到相同的结果。

echo "hi" > tmp.log
grep "hi" tmp.log

用 Elisp 写成的程序, 比如下面这个 2D 程序:

(defun open-line (n)
  (interactive "*p")
  (let* ((do-fill-prefix (and fill-prefix (bolp)))
	 (do-left-margin (and (bolp) (> (current-left-margin) 0)))
	 (loc (point-marker))
	 (abbrev-mode nil))
    (newline n)
    (goto-char loc)
    (while (> n 0)
      (cond ((bolp)
	     (if do-left-margin (indent-to (current-left-margin)))
	     (if do-fill-prefix (insert-and-inherit fill-prefix))))
      (forward-line 1)
      (setq n (1- n)))
    (goto-char loc)
    (end-of-line)))

执行起来和下面这个 1D 程序,所达到效果和性能完全一致。

(defun open-line (n) (interactive "*p") (let* ((do-fill-prefix (and fill-prefix (bolp))) (do-left-margin (and (bolp) (> (current-left-margin) 0))) (loc (point-marker)) (abbrev-mode nil)) (newline n) (goto-char loc) (while (> n 0) (cond ((bolp) (if do-left-margin (indent-to (current-left-margin))) (if do-fill-prefix (insert-and-inherit fill-prefix)))) (forward-line 1) (setq n (1- n))) (goto-char loc) (end-of-line)))

或者是想表达这样一种效果?

  • Emacs is the 2D Command-line Interface
  • Vim is the 2D Command-line Interface