【问题标题】:How to toggle fullscreen with Emacs as default?如何使用 Emacs 默认切换全屏?
【发布时间】:2012-02-12 13:01:56
【问题描述】:

我正在使用http://emacsformacosx.com/的mac emacs,我需要在启动我的emacs时点击最大化的图标。

如何将最大化的 emacs 窗口设置为默认值?

【问题讨论】:

  • 您是否尝试过查看 Emacs Wiki,例如emacswiki.org/emacs/FullScreen#toc18emacswiki.org/emacs/EmacsForMacOS#toc27?它们可能过时也可能不会过时,我没有 Mac,所以无法测试。
  • 我在使用 emacsforosx.com 提供的 Emacs 发行版时遇到了相当大的麻烦;今天我从this version that's been thoroughly patched for OS X 构建了一个新的 Emacs,并且发现了更好的结果,包括正确的 OS X 全屏支持。希望这会有所帮助!
  • @Eric Fail -- 添加 OSX 标签的问题在于,这些人对 Emacs 一无所知,并且倾向于否决并投票关闭,因为他们是错误的目标受众。
  • @lawlist,我不确定我是否完全理解这个问题。你能扩展一下吗?
  • @Eric Fail -- 我刚刚在广泛的主题标签方面遇到了糟糕的经历,论坛参与者很快就投票否决并投票结束。许多人要么订阅感兴趣的特定标签,要么为喜欢的标签添加书签并监控新活动。我个人认为,如果有很多监视 OSX 标签的人可能不太关心如何最大化 Emacs 框架。大多数具有较高声誉的论坛参与者会简单地删除标签而不说任何话,所以如果他们对此有强烈的感觉,我会留给他们。这对我来说没什么大不了的,我只是想让你。

标签: macos emacs


【解决方案1】:

像这样启动emacs

emacs -mm

【讨论】:

    【解决方案2】:

    Ryan McGeary 的 maxframe.el 在 Aquamacs 和 Emacs.app 上都非常适合我。我是通过 EmacsWiki 找到的:http://www.emacswiki.org/emacs/FullScreen。该页面讨论了一个补丁版本,现在是一个 404 页面,但 https://github.com/rmm5t/maxframe.el 的原始版本似乎工作正常。

    【讨论】:

    • 您是否真的像非 emacs 窗口一样获得了完整最大化的覆盖范围。我只能让窗口扩大到默认单空格字体的全字符宽度和高度的倍数。在我的(Ubuntu/GNU Emacs 23.1.1)系统上,这会在 RHS 和底部留下大约半个字符宽的边框。我可以完全展开窗口的唯一方法是通过窗口管理器的系统菜单的最大化选项(在左上角)
    • PS:我找到了另一个 SO 答案,它有一种适用于我的 Linux X-Windows 系统的方法:maximize emacs on start up?(not the fullscreen) .... 取消!!,它没有'不工作..它最大化垂直太多...... 但是,这两种方法一起确实工作(奇怪......也许有一天我会弄清楚为什么?....但它现在可以工作了(经过几个月的困扰我!...感谢 Jon O 的 maxframe 建议。
    • 您也可以通过 emacs 包管理器和 Melpa 获取 maxframe。
    • @Arkell 抱歉,但您不能在 emacs 24 (emacsformacos) 上执行此操作...maxframe 或 Melpa(无论是什么)都不会出现在 emacs 包管理器中
    • @Peter.O 你好,我也有类似的问题:superuser.com/questions/584755/…你能在那里分享你的工作代码吗?
    【解决方案3】:

    这是我编写和使用的一个函数。当你连续按 F11 时,emacs 会切换 4 种模式:

    (defun switch-fullscreen nil
      (interactive)
      (let* ((modes '(nil fullboth fullwidth fullheight))
             (cm (cdr (assoc 'fullscreen (frame-parameters) ) ) )
             (next (cadr (member cm modes) ) ) )
        (modify-frame-parameters
         (selected-frame)
         (list (cons 'fullscreen next)))))
    
    (define-key global-map [f11] 'switch-fullscreen)
    

    【讨论】:

    • 这对我来说很好,除了一个烦恼。当我到达fullboth 模式时,框架会超过屏幕上的所有内容;也就是WM窗口标题栏消失了,我的XFCE面板也消失在了窗口后面(我用的是Xubuntu)。 fullheight 模式正常工作:框架仅使用 XFCE 面板为其留出的垂直空间。我希望fullboth 模式能够像我通过按标题栏中的+ 按钮来最大化WM 窗口一样工作。知道如何实现吗?
    • 这是 gtk 中的错误,而不是 emacs 中的错误。请向 gtk 开发人员报告。
    • fullboth 用词不当。它使 Emacs 以普通的 Mac 术语全屏显示。 maximized 两全其美!
    • 当我在 2006 年或 2007 年编写代码时,它是 fullboth:阅读此处emacswiki.org/emacs/FullScreen#toc16
    • 其实我只在X server上测试过。
    【解决方案4】:

    简短的回答是将以下内容添加到您的custom-set-variables:-

    (custom-set-variables
     ;; custom-set-variables was added by Custom.
     ;; If you edit it by hand, you could mess it up, so be careful.
     ;; Your init file should contain only one such instance.
     ;; If there is more than one, they won't work right.
     ...
     '(initial-frame-alist (quote ((fullscreen . maximized))))
     ...
     )
    

    下面给出的是 我想要的作为解决同一问题的方法。 TL;博士。

    我在所有应用程序中都面临同样的问题,而不仅仅是在 Emacs 中。为此,我已将 Mac 上的快捷键 cmd-m 全局绑定到缩放菜单选项,该选项通常是绿色最大化按钮的菜单选项。然而,Emacs 不提供通常在 Window 菜单项下的 Zoom 菜单选项。所以我最终得到了以下结果。

    我昨晚刚刚编写了以下代码。

    ;; This defines cmd-m to do the same as clicking the green titlebar button
    ;; usually meant for the "Window -> Zoom" menu option in Mac apps
    (defun zoom () "zoom, same as clicking the green titlebar button in Mac app windows"
      (interactive)
      (set-frame-parameter
       nil 'fullscreen
       (pcase (frame-parameter nil 'fullscreen)
         (`nil 'fullheight)
         (`fullheight 'maximized)
         (`fullboth (ding) 'fullboth)
         (`fullscreen (ding) 'fullscreen)
         (_ nil))))
    (global-set-key (kbd "s-m") 'zoom)
    

    代码最后一行中的这个键盘快捷键与我最初描述的全局到 Mac cmd+m 键绑定很相配。您可以将其自定义为适合您的任何内容。我习惯于在启动大多数应用程序时按 cmd-m 直到它适合屏幕,而 Emacs 对我来说就是其中之一。所以我不打扰initial-frame-alist 设置。

    我今晚继续通过添加以下代码来完成我想要的功能集。

    ;; This defines ctrl-cmd-f to do the same as clicking the toggle-fullscreen titlebar
    ;; icon usually meant for the "View -> Enter/Exit Full Screen" menu option in
    ;; Mac apps
    (defun toggle-fullscreen() "toggle-fullscreen, same as clicking the
     corresponding titlebar icon in the right hand corner of Mac app windows"
      (interactive)
      (set-frame-parameter
       nil 'fullscreen
       (pcase (frame-parameter nil 'fullscreen)
         (`fullboth nil)
         (`fullscreen nil)
         (_ 'fullscreen))))
    (global-set-key (kbd "C-s-f") 'toggle-fullscreen)
    ; For some weird reason C-s-f only means right cmd key!
    (global-set-key (kbd "<C-s-268632070>") 'toggle-fullscreen)
    

    几个注意事项:-

    1. 如果您只是在此代码中学习使用 pcase,请注意不要犯与我一样的错误,将反引号误读为文档中的引号。
    2. fullscreenfullboth 的别名,并不是像后者那样用词不当,因此我不仅将这种情况作为(frame-parameter nil 'fullscreen) 的值处理,而且在我想@时使用它987654330@ 至 fullboth

    HTH

    【讨论】:

      【解决方案5】:

      https://stackoverflow.com/a/1029065/351716 给出的答案对我有用(使用 GNU Emacs v24.2.1)。要重复,请在 .emacs 文件中定义以下函数:

      (defun x11-maximize-frame ()
        "Maximize the current frame (to full screen)"
        (interactive)
        (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_MAXIMIZED_HORZ" 0))
        (x-send-client-message nil 0 nil "_NET_WM_STATE" 32 '(2 "_NET_WM_STATE_MAXIMIZED_VERT" 0)))
      

      为方便起见,您可以将命令绑定到一个键。我使用C-z 键,否则会最小化我不需要的框架,但是当我不小心撞到它时总是觉得烦人:

      (global-set-key (kbd "C-z") 'x11-maximize-frame)
      

      正如我在评论中指出的那样,我添加到该答案中,使用此命令在正常帧状态和最大化状态之间反复循环,但有一点烦恼:在这两者之间,有一个奇怪的状态,帧几乎但是没有完全垂直最大化。但这是一个小问题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-12-17
        • 1970-01-01
        • 1970-01-01
        • 2016-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多