From 2596a70582725d8c0063559840637d17f51b7a46 Mon Sep 17 00:00:00 2001 From: 10sr <8.slashes@gmail.com> Date: Mon, 15 Oct 2018 14:23:48 +0900 Subject: [PATCH] Add try-cd --- emacs.el | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/emacs.el b/emacs.el index 5d539d4..30c9838 100644 --- a/emacs.el +++ b/emacs.el @@ -1,6 +1,6 @@ ;;; emacs.el --- 10sr emacs initialization -;; Time-stamp: <2018-10-15 13:51:53 JST 10sr> +;; Time-stamp: <2018-10-15 14:22:50 JST 10sr> ;;; Code: @@ -2347,6 +2347,10 @@ use for the buffer. It defaults to \"*recetf-show*\"." (setq git-walktree-current-commitish commitish) (setq git-walktree-current-path path) (setq git-walktree-object-id treeish) + (let ((dir (expand-file-name path git-walktree-repository-root))) + (when (and git-walktree-try-cd + (file-directory-p dir)) + (cd dir))) ;; FIXME: Somehow point go back to point-min when reopen the buffer (if (eq point (point-min)) (goto-char point-tree-start) @@ -2404,6 +2408,12 @@ Result will be inserted into current buffer." (setq git-walktree-current-commitish commitish) (setq git-walktree-current-path path) (setq git-walktree-object-id blob) + (let ((dir (expand-file-name (file-name-directory path) + git-walktree-repository-root))) + (when (and git-walktree-try-cd + (file-directory-p dir)) + (cd dir))) + (setq buffer-read-only t) (goto-char point) ) @@ -2476,7 +2486,9 @@ checking it." :group 'git-walktree) (defcustom git-walktree-try-cd t "Try to cd if directory exists in current working directory if non-nil. -Otherwise buffer's `default-directory' is always repository root.") +Otherwise buffer's `default-directory' is always repository root." + :type 'boolean + :group 'git-walktree) (defun git-walktree--git-plumbing (&rest args) "Run git plubming command with ARGS.