无法在`magit状态,mode`使用自定义的初始化文件

无法在`magit状态,mode`使用自定义的初始化文件

问题描述:

我喜欢用终端工具运行Emacs和他们的一个是“magit” - 真棒Git的客户端作为一个Emacs包中实现。我用它来控制Git项目。我有一个脚本,自动启动,在电脑开机的emacs(这同我的时间与日常工作)。 但我也在寻找一种方法来运行emacsmagit-status模式(无需手动执行M-x magit-status...每次)。 Emacs提供了在init配置文件中配置它的环境的可能性。为了使在启动时运行magit的Emacs我创建特殊magit.el文件并运行emacs的命令行无法在`magit状态,mode`使用自定义的初始化文件

$ emacs -q --load ~/.emacs.d/magit.el 

不幸的是我无法切换的emacs在magic-status-mode - 有毛病init文件。启动后Emacs仍然在lisp-interaction-mode。 init文件的内容如下:

;; disable welcome screen at launch 
(setq inhibit-startup-screen t) 

(setq visible-bell t) 

; Disable tabs indent 
(setq-default c-basic-offset 4 
      tab-width 4 
      indent-tabs-mode nil) 

(global-set-key "\C-h" 'delete-backward-char) 

;; Makes *scratch* empty. 
(setq initial-scratch-message "") 

;; Removes *scratch* from buffer after the mode has been set. 
(defun remove-scratch-buffer() 
    (if (get-buffer "*scratch*") 
     (kill-buffer "*scratch*"))) 
;(add-hook 'after-change-major-mode-hook 'remove-scratch-buffer) 

;; Removes *messages* from the buffer. 
;(setq-default message-log-max nil) 
;(kill-buffer "*Messages*") 

;; Removes *Completions* from buffer after you've opened a file. 
;(add-hook 'minibuffer-exit-hook 
;  '(lambda() 
;   (let ((buffer "*Completions*")) 
;   (and (get-buffer buffer) 
;    (kill-buffer buffer))))) 

;; Don't show *Buffer list* when opening multiple files at the same time. 
(setq inhibit-startup-buffer-menu t) 

;; Show only one active window when opening multiple files at the same time. 
;(add-hook 'window-setup-hook 'delete-other-windows) 

;; Tell emacs where is your personal elisp lib dir (magit) 
(add-to-list 'load-path "~/.emacs.d/lisp/") 
(load "git") ;; best not to include the ending “.el” or “.elc” 
;; activate installed packages 
(package-initialize) 


(setq-default major-mode 'magit-status-mode) 
(add-hook 'after-init-hook #'magit-status-mode) 
(if after-init-time 
    (add-hook 'after-init-hook #'magit-status-mode)) 

试试这个:

(call-interactively 'magit-status) 

而是这一切:

(setq-default major-mode 'magit-status-mode) 
(add-hook 'after-init-hook #'magit-status-mode) 
(if after-init-time 
    (add-hook 'after-init-hook #'magit-status-mode)) 

使用after-init-hook将使意义,在init文件,但-q你明确使用init文件(使用--load是不一样的东西),以及钩早已るN乘您的自定义magit.el文件加载时间,所以什么你在这个阶段加入到钩永远不会被处理。

请注意,您不要根本不想拨打magit-status-mode。这不是你竟会有望手动调用的主要模式,因为你永远不会想要的模式不是由magit-status命令创建的一个以外的任何缓冲。

+0

真棒!谢谢! –