在Emacs中,我们可以进行一次击键来执行不同的命令吗?

时间:2011-02-18 09:41:37

标签: emacs

我想做一次击键,比如说C-F12来做delete-other-windowswinner-undo。我认为如果我已经学习了Emacs Lisp编程并设置了一个布尔标志,这很容易。也就是说,如果先前它运行delete-other-window,现在它将运行winner-undo

你是如何在Emacs Lisp中做到的?

由于

3 个答案:

答案 0 :(得分:3)

尝试这样的事情

(setq c-f12-winner-undo t)

(define-key (current-global-map) [C-f12]
  (lambda() 
    (interactive) 
    (if c-f12-winner-undo 
        (winner-undo)
      (delete-other-windows))
    (setq c-f12-winner-undo (not c-f12-winner-undo))))

答案 1 :(得分:1)

(defun swdev-toggle-sole-window ()
  (interactive)
  (if (cdr (window-list))
      (delete-other-windows)
    (winner-undo)))
(global-set-key (kbd "<C-f12>") 'swdev-toggle-sole-window)
  1. 第一行开始声明一个名为swdev-toggle-sole-window的函数,不带任何参数。
  2. 此函数声明为交互式,即可以使用M-x或通过键绑定进行调用。
  3. 如果窗口列表包含多个元素,即如果有多个窗口,则......
  4. ...然后删除其他窗口......
  5. ... else撤消窗口删除。
  6. 将功能绑定到键C-f12

答案 2 :(得分:1)

这是使用Emacs的recenter-top-bottom功能采用的方法的解决方案:

(defun delete-other-window-or-winner-undo ()
  "call delete-other-window on first invocation and winner-undo on subsequent invocations"
  (interactive)
  (if (eq this-command last-command) 
      (winner-undo)
    (delete-other-windows)))

(global-set-key (kbd "<C-f12>") 'delete-other-window-or-winner-undo)