Emacs吧(2)_-_Emacs其实就是函数的组合?

摘要: Vim和Sublime Text等编辑器,本质上是一个编辑器。而emacs本质上是一些函数的组合。Emacs本质上是函数的组合从帮助上看emacs有何不同Vim和Sublime Text等编辑器,本质上是一个编辑器。比如我们看看vim的帮助,是这个风格的,比如我要看i命令的帮助: or *i* *insert* **i Insert text before the cursor [count] times. When using CTRL-O in Insert mode |i_CTRL-O| the count is not supported.再看看emacs的帮助,是这样的风格,比如我们看Ctrl-n键的帮助:C-n runs the command next-line (found in global-map), which is an interactivecompiled Lisp function in ‘simple.el’.It is bound to C-n.(next-line &optional ARG TRY-VSCROLL)This function is for interactive use only;in Lisp code use ‘forward-line’ instead.Move cursor vertically down ARG lines.Interactively, vscroll tall lines if ‘auto-window-vscroll’ is enabled.Non-interactively, use TRY-VSCROLL to control whether to vscroll talllines: if either ‘auto-window-vscroll’ or TRY-VSCROLL is nil, thisfunction will not vscroll.ARG defaults to 1.If there is no character in the target line exactly under the current column,the cursor is positioned after the character in that line which spans thiscolumn, or at the end of the line if it is not long enough.If there is no line in the buffer after this one, behavior depends on thevalue of ‘next-line-add-newlines’. If non-nil, it inserts a newline characterto create a line, and moves the cursor to that line. Otherwise it moves thecursor to the end of the buffer.If the variable ‘line-move-visual’ is non-nil, this command movesby display lines. Otherwise, it moves by buffer lines, withouttaking variable-width characters or continued lines into account.See M-x next-logical-line for a command that always moves by buffer lines.The command C-x C-n can be used to createa semipermanent goal column for this command.Then instead of trying to move exactly vertically (or as close as possible),this command moves to the specified goal column (or as close as possible).The goal column is stored in the variable ‘goal-column’, which is nilwhen there is no goal column. Note that setting ‘goal-column’overrides ‘line-move-visual’ and causes this command to move by bufferlines rather than by display lines.更进一步,我们可以点击simple.el进去看看,可以看到它的源码:(defun next-line (&optional arg try-vscroll) "Move cursor vertically down ARG lines....就是上面贴过的帮助,此处略过" (declare (interactive-only forward-line)) (interactive "^p\np") (or arg (setq arg 1)) (if (and next-line-add-newlines (= arg 1)) (if (save-excursion (end-of-line) (eobp)) ;; When adding a newline, don't expand an abbrev. (let ((abbrev-mode nil)) (end-of-line) (insert (if use-hard-newlines hard-newline "\n"))) (line-move arg nil nil try-vscroll)) (if (called-interactively-p 'interactive) (condition-case err (line-move arg nil nil try-vscroll) ((beginning-of-buffer end-of-buffer) (signal (car err) (cdr err)))) (line-move arg nil nil try-vscroll))) nil)从上面可以看到,比起vim是个相对黑盒,需要文档描述的编辑器,emacs是个比较简单直接的家伙。简单到,基本上就是一堆函数的组合而己,我们做编辑时,就是直接调用这些函数。为了方便,我们把这些函数绑定到快捷键上。只要知道要调用哪个函数,不想记任何快捷键的话,只需要记住一个就可以了,就是Alt+X,然后就可以输入要执行的函数名,去执行这个命令。Emacs的功能,都是由lisp或C语言实现的函数来实现的,所有的源码都是开放的,在新的版本中,直接都可以通过帮助功能来查看,非常方便。在emacs里,Alt键的命令也都可以通过先按Esc再按另一个键的方式来实现。从扩展方向上看emacs的不同vim的扩展Emacs是第一个著名的以可扩展能力而闻名的编辑器,同时期的主流编辑器在这方面都要向emacs学习。到了现在,Sublime Text和Vim等编辑器的扩展功能也是非常值得称道而且受欢迎的。但是,不管是Vim还是Sublime Text,甚至更强大一些的Visual Studio Code和Atom,它们的做法都是把扩展的接口开放出来,大家按照开放出来的接口来写扩展。比如我们先看vim,以我在mac OS下的vim 8.0.600为例,它支持下列feature:

原文链接

请先 登录 后评论

0 个回答

没有找到数据。