我是StackOverflow的新手,我对一个问题提出了一个问题,这个问题在我掌握Emacs的过程中几乎是唯一让我烦恼的问题。
我配置了.emacs
文件,将Emacs的默认帧大小设置为70行和80列,如下所示:
(add-to-list 'default-frame-alist '(left . 0))
(add-to-list 'default-frame-alist '(top . 0))
(add-to-list 'default-frame-alist '(height . 70))
(add-to-list 'default-frame-alist '(width . 80))
这在启动Emacs时工作正常,问题是当我使用new-frame
或emacsclient -c
启动新框架时,这些设置不受尊重。有没有办法强制emacsclient
和new-frame
在执行时读取.emacs
文件中的设置?
修改
这是我的.emacs
文件:
;;This setting is meant to force emacs to read size settings before make-frame.
(add-hook 'before-make-frame-hook
#'(lambda ()
(add-to-list 'default-frame-alist '(left . 0))
(add-to-list 'default-frame-alist '(top . 0))
(add-to-list 'default-frame-alist '(height . 70))
(add-to-list 'default-frame-alist '(width . 80))))
;;disable annoying welcome screen.
(setq inhibit-splash-screen t)
(setq inferior-lisp-program "/usr/bin/abcl")
(add-to-list 'load-path "/usr/share/emacs/site-lisp/slime/")
(require 'slime)
(slime-setup)
(add-to-list 'auto-mode-alist '("\\.lisp$" . lisp-mode))
(add-to-list 'auto-mode-alist '("\\.cl$" . lisp-mode))
(add-to-list 'auto-mode-alist '("\\.asd$" . lisp-mode))
(require 'slime)
(slime-setup)
(eval-after-load "slime"
'(progn
(setq slime-complete-symbol*-fancy t
slime-complete-symbol-function 'slime-fuzzy-complete-symbol
slime-when-complete-filename-expand t
slime-truncate-lines nil
slime-autodoc-use-multiline-p t)
(slime-setup '(slime-fancy slime-asdf))
(define-key slime-repl-mode-map (kbd "C-c ;")
'slime-insert-balanced-comments)
(define-key slime-repl-mode-map (kbd "C-c M-;")
'slime-remove-balanced-comments)
(define-key slime-mode-map (kbd "C-c ;")
'slime-insert-balanced-comments)
(define-key slime-mode-map (kbd "C-c M-;")
'slime-remove-balanced-comments)
(define-key slime-mode-map (kbd "RET") 'newline-and-indent)
(define-key slime-mode-map (kbd "C-j") 'newline)))
(add-to-list 'default-frame-alist '(left . 0))
(add-to-list 'default-frame-alist '(top . 0))
(add-to-list 'default-frame-alist '(height . 70))
(add-to-list 'default-frame-alist '(width . 80))
(normal-erase-is-backspace-mode 0)
(tool-bar-mode -1) ;;method for disabling changed in 24. can not nil, most negative
(scroll-bar-mode -1)
;;for loading cedet.
(load-file "/usr/share/emacs/site-lisp/cedet/common/cedet.el")
答案 0 :(得分:5)
您可以尝试将以下挂钩添加到您的Emacs启动文件(通常为~/.emacs
),即:
(add-hook 'before-make-frame-hook
#'(lambda ()
(add-to-list 'default-frame-alist '(left . 0))
(add-to-list 'default-frame-alist '(top . 0))
(add-to-list 'default-frame-alist '(height . 70))
(add-to-list 'default-frame-alist '(width . 80))))
或者,如果您想重新加载整个.emacs
文件:
(add-hook 'before-make-frame-hook #'(lambda () (load-file "~/.emacs")))
以前的钩子几乎肯定是可取的,因为重新加载整个.emacs
文件可能不仅不必要而且浪费资源,而且还有可能导致错误或奇怪的行为(取决于文件的内容)。
详细说明,钩子是定义在Emacs会话中发生特定事件时执行的命令列表的变量,例如,加载主要编辑模式,或者,如本例所示,创建新帧。有关详细信息,请参阅相关的Emacs manual page on hooks。一般来说,如果您希望每次在Emacs中发生特定事件时执行某些功能,将所述功能添加到正确的预先存在的钩子可能是最好的方法。