iis服务器助手广告广告
返回顶部
首页 > 资讯 > 后端开发 > Python >GNU emacs Lisp小结3
  • 452
分享到

GNU emacs Lisp小结3

小结GNUemacs 2023-01-31 01:01:00 452人浏览 独家记忆

Python 官方文档:入门教程 => 点击学习

摘要

chapter4 与缓冲区有关的函数4.1 查找更多的信息C-h f 函数名   ;查询函数C-h v 变量名   ;查询变量find-tags 函数 ;跳到响应函数M-. 函数名     ;同上上面函数需要定义一个标记表(tags tab

chapter4 与缓冲区有关的函数
4.1 查找更多的信息
C-h f 函数名   ;查询函数
C-h v 变量名   ;查询变量
find-tags 函数 ;跳到响应函数
M-. 函数名     ;同上
上面函数需要定义一个标记表(tags table),这是一个名为"TAGS"的文件。
可以使用M-x visit-tages-table来指定
C-h p 命令让你用主题关键字搜索EMacs Lisp标准库。

4.2 简化的beginning-of-buffer函数定义
beginning-of-buffer => M-<
end-of-buffer => M->

(defun simple-beginning-of-buffer ()
"Move point to the beginning of the buffer;
leave mark at previous position."
(interactive)
(push-mark)
(Goto-char (point-min)))
你可以使用C-h f fun来查询具体函数。
C-x C-x可以回到原来位置。
end-of-buffer 只需要把point-min换成point-max.

4.3 mark-whole-buffer函数
快捷键:C-x h

(defun mark-whole-buffer ()
"Put point at beginning and mark at end of buffer."
(interactive)
(push-mark (point))
(push-mark (point-max))
(goto-char (point-min)))

4.4 append-to-buffer函数的定义
(defun append-to-buffer (buffer start end)
"Append to specified buffer the next of the region.
It is insert into that buffer before its point.
When calling from a program, give three arguments:
a buffer or the name of one, and two character numbers
specifying the portion of the current buffer to be copied."
(interactive "BAppend to buffer:\nr")
(let ((oldbuf (current-buffer)))        
(save-excursion
(set-buffer (get-buffer-create buffer))
(insert-buffer-substring oldbuf start end))))

4.5回顾
1.descibe-function, describe-variable
C-h f, C-h v
2.find-tag
M-.
3.save-excursion
保存当前的位点,标记,缓冲区,执行参数,最后返回原状态。
4.push-mark
在指定位置设置一个标记,并在标记环中记录原来标记的值。
5.goto-char
将位点设置为由参量指定的位置。
6.insert-buffer-substring
将一个来自缓冲区的文本域拷贝到当前缓冲区。
7.mark-whole-buffer
C-x h
8.set-buffer
将Emacs的注意力转移到另一个缓冲区,但是不改变显示的窗口。
9.get-buffer-create, get-buffer
寻找一个已指定名字的缓冲区,或当指定名字的缓冲区不存在时就创建它。


chapter5 更复杂的函数
5.1 copy-to-buffer函数的定义
(defun copy-to-buffer (buffer, start, end)
"...."
(interactive "BCopy to buffer:\nr")
(let ((oldbuf (current-buffer)))
 (save-excursion
   (set-buffer (get-buffer-create buffer))
   (erase-buffer)
   (save-excursion
     (insert-buffer-substring oldbuf start end)))))

5.2 insert-buffer函数的定义
(defun insert-buffer (buffer)
"Insert after point the contents of BUFFER.
Puts mark after the inserted text.
BUFFER may be a buffer or a buffer name."
 (interactive "*bInsert buffer:")
 (or (bufferp buffer))
   (setq buffer (get-buffer buffer))
 (let (start end newmark)
   (save-excursion
     (save-excursion
       (set-buffer buffer)
       (setq start (point-min) end (point-max)))
     (insert-buffer-substring buffer start end)
     (setq newmark (point)))
   (push-mark newmark)))

5.2.1 insert-buffer函数中的交互表达式
1.只读缓冲区
“*”用于缓冲区是一个只读缓冲区。
2.交互表达式中的“b”
传送给insert-buffer函数的参量应是一个存在的缓冲区或者这个缓冲区的名字。
大写的“B”可以允许参量传送不存在的缓存区。

5.2.2 insert-buffer 函数体
or表达式的目地是为了确保buffer参量真正与一个缓冲区绑定在一起,而不是绑定缓冲区的名字。

5.2.3 用if表达式(而不是or表达式)编写的insert-buffer函数
(if (not (bufferp buffer))                ;if-part
   (setq buffer (get-buffer buffer)))    ;then-part

5.2.4 函数体中的or表达式
一个or函数可以有很多参量。它逐一对每一个参量并返回第一个其值不是nil的参量的值。
一旦遇到其值不是nil的参量之后,or表达式就不再对后续的参量的求值。

5.2.5 insert-buffer 函数中的let表达式

5.3 biginning-of-buffer函数的完整定义
C-u 7 M-<  将光标移动到从缓冲区开始的这个缓冲区的70%处,如果大于10,则移到末尾。

(defun beginning-of-buffer (&optional arg)
 "Move point to the beginning of the buffer;
 leave mark at previous position.
 With arg N, put point N/10 of the way
 from the true beginning.
 Don't use this in Lisp programs!
 \(goto-char (point-min)) is faster
 and does not set the mark."
 (interactive "P")
 (push-mark)
 (goto-char
   (if arg
     (if  (> (buffer-size) 10000)
        ;;Avoid overflow for large buffer sizes!
        (* (prefix-numeric-value arg) (/ (buffer-size) 10))
        (/ (+ 10 (* (buffer-size) (prefix-numeric-value arg))) 10))
     (point-min)))
 (if arg (forward-line 1)))

5.4 回顾
1.or
逐一对每一个参量求值,直到返回第一个非空值。
2.and
逐一对每一个参量求值,直到有一个参量的值是nil
3.&optional
在函数定义中用于指出一个参量是可选参量。
4.prefix-numeric-value
将一个由(interactive "P")产生的未加工的前缀参量转换成一个数值。
5.forward-line
将光标移到下一行的行首,如果参数大于1,则移动多行。
6.erase-buffer
删除当前缓冲区的全部内容
7.bufferp
如果其参量是一个缓冲区则返回“真”,否则返回“假”。

chapter 6 变窄和曾宽
6.1 save-restriction特殊表
跟踪变窄开启的部分。
(save-restriction
body....)

(save-excursion
(save-restriction
body...))
如果需要同时使用,顺序不能错。

6.2 what-line函数
这个函数告诉你光标所在的行数。
(defun what-line ()
 "Print the current line number (in the buffer) of point."
 (interactive)
 (save-restriction
   (widen)
   (save-recursion
     (beginning-of-line)
     (message "Line %d" (1+(count-lines 1 (point)))))))


增补:
C-x n n
   Narrow down to between point and mark (narrow-to-region).
C-x n w
   Widen to make the entire buffer accessible again (widen).
C-x n p
   Narrow down to the current page (narrow-to-page).
C-x n d
   Narrow down to the current defun (narrow-to-defun).



--结束END--

本文标题: GNU emacs Lisp小结3

本文链接: https://www.lsjlt.com/news/185038.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
  • GNU emacs Lisp小结3
    chapter4 与缓冲区有关的函数4.1 查找更多的信息C-h f 函数名   ;查询函数C-h v 变量名   ;查询变量find-tags 函数 ;跳到响应函数M-. 函数名     ;同上上面函数需要定义一个标记表(tags tab...
    99+
    2023-01-31
    小结 GNU emacs
  • java连接zookeeper的3种方式小结
    目录java连接zookeeper3种方式1、使用zookeeper原始api2、使用ZkClient客户端连接,这种连接比较简单3、使用curator连接Java集成zookeep...
    99+
    2024-04-02
  • Python导入模块的3种方式小结
    目录导入模块方式一:临时添加模块完整路径导入模块方式二:将模块保存到指定位置导入模块方式三:设置环境变量很多初学者经常遇到这样的问题,即自定义 Python 模板后,在其它文件中用 ...
    99+
    2023-03-10
    Python导入模块
  • Mybatis之typeAlias配置的3种方式小结
    目录Mybatis typeAlias配置1.定义别名2.扫描包方式3.注解方式springboot加载mybatis的typeAlias问题为了清晰可见,直接贴代码Mybatis ...
    99+
    2024-04-02
  • vue深拷贝的3种实现方式小结
    目录1、通过递归方式实现深拷贝2、JSON.parse(JSON.stringify(obj))3、jQuery的extend方法实现深拷贝拓展阅读vue深拷贝的其他实现方式总结vu...
    99+
    2023-02-21
    vue深拷贝的三种实现方式 vue实现深拷贝 vue 深拷贝
  • MySQL8.0安装中遇到的3个小错误总结
    前言 过去公司都是用的5.7 系列的MySQL,随着8.0的发版,也想试着升级一下。遇到了两个小错误,记录在此。 在开始之前,如果对MySQL8.0安装步骤不清楚的朋友们可以参考这篇文章:https://w...
    99+
    2024-04-02
  • 【总结】JavaScript可以实现的3个有趣小功能
    JavaScript是一种广泛用于网页前端开发的脚本语言,其在实现小功能方面拥有丰富的资源。本文将介绍几个有趣的小功能实现,帮助读者进一步了解JavaScript的应用。一、鼠标跟随器鼠标跟随器是一种让元素随着鼠标移动而运动的小功能。这个动...
    99+
    2023-05-14
  • Spring中@Autowired和@Qualifier注解的3个知识点小结
    目录@Autowired和@Qualifier注解的3个知识点1.@Autowired自动注入2.如果想直接使用byName的注入方式3.如果没有指定Spring创建的bean的名称...
    99+
    2024-04-02
  • Python让列表逆序排列的3种方式小结
    目录Python列表逆序排列第一种方法 list.reverse()第二种方法 使用切片第三种 使用reversed()方法怎么 选择使用python列表技巧(倒序)Pyt...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作