无法使用自定义初始化文件在`magit-status-mode`中运行emacs

时间:2017-09-02 07:31:36

标签: emacs boot magit

我喜欢使用终端工具,其中一个是' magit ' - 作为Emacs包实现的令人敬畏的Git客户端。我用它来控制Git项目。我有一个脚本,可以在计算机启动时自动启动emacs(这与我的常规工作时间相同)。 但我也正在寻找一种在 magit-status 模式下运行 emacs 的方法(无需手动执行M-x magit-status...时间)。 Emacs提供了在init配置文件中配置其环境的可能性。为了让emacs在启动时运行magit,我创建了特殊的magit.el文件并从命令行运行emacs

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

不幸的是我无法在magic-status-mode中切换emacs - 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))

1 个答案:

答案 0 :(得分:0)

试试这个:

(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是不一样的),并且挂钩已经在加载自定义magit.el文件时运行,因此您在该阶段添加到钩子的任何内容都不会被处理。

请注意,您根本不想想要致电magit-status-mode。这不是您希望手动调用的主要模式,因为除magit-status命令创建的缓冲区之外的任何缓冲区都不希望使用该模式。