open README under git root directory in Emacs
I often need update my README files at the root directory of my project which is always managed by git.
As a lazy guy, I' rather use some hotkey to open that README.
So if you add below elisp code into your ~/ .emacs, you can use hot key C-c C-f
to open the README:
(defun open-readme-in-git-root-directory () (interactive) (let (filename (root-dir (locate-dominating-file (file-name-as-directory (file-name-directory buffer-file-name)) ".git")) ) ;; (message "root-dir=%s" root-dir) (and root-dir (file-name-as-directory root-dir)) (setq filename (concat root-dir "README.org")) (if (not (file-exists-p filename)) (setq filename (concat root-dir "README.md")) ) ;; (message "filename=%s" filename) (if (file-exists-p filename) (switch-to-buffer (find-file-noselect filename nil nil)) (message "NO README.org or README.md found!")) )) (global-set-key (kbd "C-c C-f") 'open-readme-in-git-root-directory)
,,,,