无法使用自定义初始化文件在“magit状态模式”下运行emacs

无法使用自定义初始化文件在“magit状态模式”下运行emacs,emacs,boot,magit,Emacs,Boot,Magit,我喜欢使用终端工具,其中之一是“magit”——作为Emacs包实现的很棒的Git客户端。我用它来控制Git项目。我有一个脚本,可以在计算机启动时自动启动emacs(这与我的日常工作相同)但我也在寻找一种在magit状态模式下运行emacs的方法(无需每次手动执行m-x magit status…)。Emacs提供了在init配置文件中配置其环境的可能性。为了让emacs在启动时运行magit,我创建了一个特殊的magit.el文件,并从命令行运行emacs $ emacs -q --load

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

$ emacs -q --load ~/.emacs.d/magit.el
不幸的是,我无法在
magic状态模式下切换emacs
——init文件有问题。启动后,Emacs仍处于
lisp交互模式
。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))
试试这个:

(交互调用“magit状态”)
而不是所有这些:

(设置默认主模式“magit状态模式”)
(在init hook#magit-status-mode之后添加hook)
(如果在初始时间之后
(在init hook#“magit-status-mode”之后添加hook)
在init hook之后使用
在init文件中是有意义的,但是使用
-q
时,您显然没有使用init文件(使用
--load
不是一回事),并且在加载自定义
magit.el
文件时,该hook已经运行,因此,在该阶段添加到钩子中的任何内容都不会被处理

请注意,您根本不想调用
magit状态模式
。这并不是一个您希望手动调用的主要模式,因为除了由
magit status
命令创建的缓冲区外,您永远不希望任何缓冲区使用该模式。

尝试以下操作:

(交互调用“magit状态”)
而不是所有这些:

(设置默认主模式“magit状态模式”)
(在init hook#magit-status-mode之后添加hook)
(如果在初始时间之后
(在init hook#“magit-status-mode”之后添加hook)
在init hook
之后使用
在init文件中是有意义的,但是使用
-q
时,您显然没有使用init文件(使用
--load
不是一回事),并且在加载自定义
magit.el
文件时,该hook已经运行,因此,在该阶段添加到钩子中的任何内容都不会被处理


请注意,您根本不想调用
magit状态模式
。这不是一个主要的模式,你永远不会被期望手动调用,因为除了由
magit status
命令创建的缓冲区之外,你永远不会希望任何缓冲区使用该模式。

Awesome!非常感谢。令人惊叹的!非常感谢。