如何使用Emacs作为默认切换全屏?

why*_*why 12 macos emacs

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

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

yPh*_*hil 9

像这样启动emacs

emacs -mm
Run Code Online (Sandbox Code Playgroud)


Jon*_* O. 8

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


ali*_*oar 7

这是我编写和使用的函数.当您成功按下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)
Run Code Online (Sandbox Code Playgroud)


trs*_*rss 5

简短的回答是将以下内容添加到您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))))
 ...
 )
Run Code Online (Sandbox Code Playgroud)

以下是我想要解决同一问题的方法.TL; DR.

我面临同样的问题,但在所有应用程序中,而不仅仅是在Emacs中.为此,我将Mac上的快捷键cmd-m全局绑定到"缩放"菜单选项,该选项通常是绿色最大化按钮的菜单选项.但是,Emacs不提供"缩放"菜单选项,该选项通常位于"窗口"菜单项下.所以我最终得到了以下内容.

我昨晚编了以下内容.

;; 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)
Run Code Online (Sandbox Code Playgroud)

代码最后一行中的这个键盘快捷键适用于我最初描述的全局到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)
Run Code Online (Sandbox Code Playgroud)

几个笔记: -

  1. 如果您只是学习使用pcase此代码,请注意不要像在文档中误读反引号那样犯同样的错误.
  2. fullscreen是它的别名fullboth,是不是名不副实像后者是作为一个术语,这意味着什么,因此我不仅处理这种情况下,作为一个值(frame-parameter nil 'fullscreen),但使用的是每当我要set-frame-parameterfullboth

HTH