更具体地说,我想创建一个重复内置命令 10 次的函数:enlarge-window
。
C-h
f enlarge-window
告诉我们该函数采用参数 DELTA,该参数是放大窗口的行数,并且此值在交互式调用时默认为 1 行:
enlarge-window is an interactive compiled Lisp function in ‘window.el’.
It is bound to C-x ^.
(enlarge-window DELTA &optional HORIZONTAL)
Make the selected window DELTA lines taller.
Interactively, if no argument is given, make the selected window
one line taller. If optional argument HORIZONTAL is non-nil,
make selected window wider by DELTA columns. If DELTA is
negative, shrink selected window by -DELTA lines or columns.
因此,虽然您可以编写一个调用(enlarge-window 1)
十次的函数,但您可以更简单地调用一次 DELTA 值为 10。
(defun my-enlarge-window-10 ()
"Make the selected window 10 lines taller."
(interactive)
(enlarge-window 10))
另请注意,您可以交互式地使用前缀参数将 DELTA 值传递给 enlarge-window
,因此您也可以键入以下内容之一以在没有自定义函数的情况下获得相同的结果:
- C-u
10
C-x^ - M-1 M-0C-x^