【问题标题】:how to jump to the newly created buffer/window automatically in Emacs如何在 Emacs 中自动跳转到新创建的缓冲区/窗口
【发布时间】:2012-12-03 02:41:25
【问题描述】:

在编译、发生搜索、grep 搜索等时,Emacs 会在一个单独的窗口中创建一个新的缓冲区来显示结果,有没有自动跳转到那个窗口?它很有用,因为这样我就可以使用np 而不是M-g nM-g p 来移动到下一个和上一个项目;另外,可以使用q 快速退出缓冲区。目前,每次运行这些命令时,我都会手动切换到新缓冲区,这很烦人。谢谢。

【问题讨论】:

    标签: emacs


    【解决方案1】:

    您可以使用建议。

    例如,要跳转到 grep 缓冲区,请使用以下建议:

    (defadvice compilation-start (after compilation-start-maximize activate)
      (when (equal mode 'grep-mode)
        (switch-to-buffer "*grep*")
        ;; you may want to maximize the buffer
        (delete-other-windows)))
    

    如果发生,您可以使用以下建议

    (defadvice occur-1 (after occur-maximize activate)
      (other-window 1))
    

    【讨论】:

    • 谢谢。 (equal mode 'grep-mode) 中的 mode 是什么?在我看来,它既不是变量也不是函数——我无法通过C-h 找到它。顺便说一句,如何使它适用于occur
    • mode 是编译启动函数中建议的变量。这些变量在建议中可用。我为发生添加了一条建议。如果有用的话,你可能会考虑接受我的回答。
    【解决方案2】:

    经过一番搜索,我想出了这个解决方案,但没有建议内置函数:

    (add-hook 'occur-hook (lambda () (pop-to-buffer occur-buf)))
    (add-hook 'grep-mode-hook (lambda () (pop-to-buffer (get-buffer "*grep*"))))
    (setq help-window-select t)
    (add-hook 'compilation-mode-hook (lambda () (pop-to-buffer (get-buffer "*compilation*"))))
    

    它适用于*Occur**grep**compilation**Help*

    【讨论】:

    • 未经测试,但您可能希望尝试使用next-error-last-buffer 变量而不是那些字符串文字缓冲区名称。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多