-
Elisp: Get Buffer String
在前面章节已经进行了学习。略。
-
Elips: Functions on Line elisp 下关于 Line 的操作
-
Get Position of Beginning/End of Line 获取 Line 开头/末尾的位置
测试: minibuffer 里返回了一个位置数值
(line-beginning-position) ;; (line-end-position)
-
Move Cursor to Beginning/End of Line 将光标移动到 Line 的开头/末尾的位置
测试: 光标移动到了行首
(beginning-of-line) ;李杀说该命令优于 (goto-char (line-beginning-position))
测试: 返回 nil,因为光标当时处于行末,光标没有发生移动
(end-of-line) ;;李杀说该命令优于 (goto-char (line-end-position))
李杀提到,这两个命令是基于 C 来写的,所以运行效率比其它基于 elisp 来写的要快。
They work by ewline char. That is, not soft-wrapped line. 这句话还需要理解,因为我不太知道什么叫 newline char
-
Move Cursor to Previous/Next Line 将光标移动到上一行/下一行
(forward-line -1) ;光标移动到上一行,光标出现在行首 (forward-line 1) ;光标移动到下一行,光标出现在行首
-
Get Current Line as String 提出当前行的所有内容到 String
测试: 李杀直接编写了一个名为 myLine 的命令
(setq myLine (buffer-substring-no-properties (line-beginning-position) (line-end-position) ))
-
Get All Lines in a Flie into a List
李杀提供了 2 个命令模板
(defun get-string-from-file (filePath) "Return file content as string" (with-temp-buffer (insert-file-contents filePath) (buffer-string))) (defun read-lines (filePath) "Return a list of lines of a file at filePath" (with-temp-buffer (instert-file-contents filePath) (split-string (buffer-string) "\n" t)))
-
1 个赞