我开了golden ratio(SPC t g)后再开ranger(SPC a r),各个栏的比例就很奇怪了(os x 上直接报错),如何才能让ranger打开时关闭golden ratio, 在ranger关闭时打开golden ratio
我刚刚写了一些 elisp,亲测有效:
(defun my-ranger ()
(interactive)
(if golden-ratio-mode
(progn
(golden-ratio-mode -1)
(ranger)
(setq golden-ration-previous-enable t))
(progn
(ranger)
(setq golden-ration-previous-enable nil))))
(defun my-quit-ranger ()
(interactive)
(if golden-ration-previous-enable
(progn
(ranger-close)
(golden-ratio-mode 1))
(ranger-close)))
(with-eval-after-load 'ranger
(progn
(define-key ranger-normal-mode-map (kbd "q") 'my-quit-ranger)
))
(spacemacs/set-leader-keys "ar" 'my-ranger)
Thanks, 其实ranger遇到会修改buffer或window的mode都会出问题,比如mmm mode, 不知是否有根治的方法?难道只能去体issue?
完美解决估计还是去提 issue,不过估计 ranger 的设计就没有考虑这些。
我在 ranger 下面用 SPC b b
打开 *Message*
buffer 都会报错。
这个的最终方案其实不够优雅:
只有当我们需要在窗口间移动或分割窗口的时候才需要golden ratio的运行(Lazy execution)
(setq golden-ratio-previous-enable nil)
(defun open_golden_ratio_first ()
"open golden-ratio before calling other"
(when (and golden-ratio-previous-enable (not golden-ratio-mode))
(golden-ratio-mode 1)))
(defun mp-ui/ranger ()
(interactive)
(if golden-ratio-mode
(progn
(golden-ratio-mode -1)
(ranger)
(setq golden-ratio-previous-enable t))
(progn
(ranger)
(setq golden-ratio-previous-enable nil))))
(defun mp-ui/quit-ranger ()
(interactive)
(if golden-ratio-previous-enable
(progn
(ranger-close)
(golden-ratio-mode 1))
(ranger-close)))
(defun mp-ui/evil-window-right (count)
:repeat nil
(interactive "p")
(open_golden_ratio_first)
(dotimes (i (or count 1))
(windmove-right))
(run-at-time 0.1 nil (lambda () (golden-ratio))))
(defun mp-ui/evil-window-left (count)
:repeat nil
(interactive "p")
(open_golden_ratio_first)
(dotimes (i (or count 1))
(windmove-left))
(run-at-time 0.1 nil (lambda () (golden-ratio))))
(defun mp-ui/evil-window-down (count)
:repeat nil
(interactive "p")
(open_golden_ratio_first)
(dotimes (i (or count 1))
(windmove-down))
(run-at-time 0.1 nil (lambda () (golden-ratio))))
(defun mp-ui/evil-window-up (count)
:repeat nil
(interactive "p")
(open_golden_ratio_first)
(dotimes (i (or count 1))
(windmove-up))
(run-at-time 0.1 nil (lambda () (golden-ratio))))
(defun mp-ui/split-window-below ()
(interactive)
(open_golden_ratio_first)
(split-window-below))
(defun mp-ui/split-window-right ()
(interactive)
(open_golden_ratio_first)
(split-window-right))
;; TODO: it should change golden-ratio-previous-enable to nil while toggle the golden-ratio
(defun mp-ui/post-init-ranger ()
"Configuations for ranger!"
(with-eval-after-load 'ranger
(progn
(define-key evil-normal-state-map (kbd "C-w j") 'mp-ui/evil-window-down)
(define-key evil-normal-state-map (kbd "C-w h") 'mp-ui/evil-window-left)
(define-key evil-normal-state-map (kbd "C-w k") 'mp-ui/evil-window-up)
(define-key evil-normal-state-map (kbd "C-w l") 'mp-ui/evil-window-right)
(spacemacs/set-leader-keys "ws" 'mp-ui/split-window-below)
(spacemacs/set-leader-keys "wv" 'mp-ui/split-window-right)
;; (define-key ranger-normal-mode-map (kbd "q") 'mp-ui/quit-ranger)
))
(spacemacs/set-leader-keys "ar" 'mp-ui/ranger)
;; Ranger
(setq ranger-ignored-extensions '("mkv" "iso" "mp4"))
(setq ranger-max-preview-size 2)
)
看到 golden-ratio-exclude-modes,想通过这个解决,不过写成这样当时不行。
(with-eval-after-load 'golden-ratio
(add-to-list 'golden-ratio-exclude-modes '("ranger-mode")))
没有查出原因,看来还只能用你的方法了。
(with-eval-after-load 'golden-ratio
(add-to-list 'golden-ratio-exclude-modes "ranger-mode"))
这样可以,但是 ranger 目录层级切换时还是不好用。
(add-hook 'magit-mode-hook 'spacemacs/toggle-golden-ratio-off)
(advice-add 'magit-mode-bury-buffer :after 'spacemacs/toggle-golden-ratio-on)
这样也可以。
奇怪的是直接(golden-ratio-mode 1)
会导致没有自动resize windows,用spacemacs的就好了,但是spacemacs的函数明明是用宏批量生成的,肯定没有做什么额外的和golden-radio相关的处理啊。