init-neotree.el 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. ;;; init-neotree.el --- .Emacs Configuration -*- lexical-binding: t -*-
  2. ;;; Commentary:
  3. ;;
  4. ;;; Code:
  5. ;;-----------------------------------
  6. ;; Neotree - NerdTree for Vim
  7. ;;-----------------------------------
  8. (use-package shrink-path
  9. :ensure t)
  10. (use-package neotree
  11. :ensure t
  12. :pin "MELPA"
  13. :commands (neotree-show
  14. neotree-hide
  15. neotree-toggle
  16. neotree-dir
  17. neotree-find
  18. neo-global--with-buffer
  19. neo-global--window-exists-p)
  20. :bind (([f8] . neotree-toggle)
  21. (:map neotree-mode-map
  22. ("<C-return>" . neotree-change-root)
  23. ("C" . neotree-change-root)
  24. ("c" . neotree-create-node)
  25. ("+" . neotree-create-node)
  26. ("d" . neotree-delete-node)
  27. ("r" . neotree-rename-node)))
  28. :config
  29. (when (and (require 'neotree nil t)
  30. (fboundp 'off-p))
  31. (setq neo-create-file-auto-open nil
  32. neo-auto-indent-point nil
  33. neo-autorefresh t
  34. neo-smart-open nil
  35. neo-mode-line-type 'none
  36. neo-window-width 25
  37. neo-window-fixed-size nil
  38. neo-show-updir-line nil
  39. neo-theme (if (display-graphic-p) 'icons 'arrow)
  40. neo-banner-message nil
  41. neo-confirm-create-file #'off-p
  42. neo-confirm-create-directory #'off-p
  43. neo-show-hidden-files nil
  44. neo-keymap-style 'concise
  45. neo-hidden-regexp-list
  46. '(;; vcs folders
  47. "^\\.\\(git\\|hg\\|svn\\)$"
  48. ;; compiled files
  49. "\\.\\(pyc\\|o\\|elc\\|lock\\|css.map\\)$"
  50. ;; generated files, caches or local pkgs
  51. "^\\(node_modules\\|.\\(project\\|cask\\|yardoc\\|sass-cache\\)\\)$"
  52. ;; org-mode folders
  53. "^\\.\\(sync\\|export\\|attach\\)$"
  54. "~$"
  55. "^#.*#$")))
  56. (when (bound-and-true-p winner-mode)
  57. (push neo-buffer-name winner-boring-buffers))
  58. (defun shrink-root-entry (node)
  59. "shrink-print pwd in neotree"
  60. (when (and (require 'neotree nil t)
  61. (fboundp 'shrink-path-dirs))
  62. (insert (propertize (concat (shrink-path-dirs node) "\n") 'face `(:inherit (,neo-root-dir-face))))))
  63. (when (and (require 'neotree nil t)
  64. (fboundp 'neo-buffer--insert-root-entry)
  65. (fboundp 'shrink-root-entry))
  66. (advice-add #'neo-buffer--insert-root-entry :override #'shrink-root-entry))
  67. )
  68. (defun neotree-project-dir-toggle ()
  69. "Open NeoTree using the project root, using find-file-in-project or the current buffer directory."
  70. (interactive)
  71. (when (and (require 'neotree nil t)
  72. (fboundp 'projectile-project-root))
  73. (let ((project-dir
  74. (ignore-errors
  75. ;;; Pick one: projectile or find-file-in-project
  76. (projectile-project-root)))
  77. (file-name (buffer-file-name)))
  78. (if (and (fboundp 'neo-global--window-exists-p)
  79. (neo-global--window-exists-p))
  80. (neotree-hide)
  81. (progn
  82. (neotree-show)
  83. (if project-dir
  84. (neotree-dir project-dir))
  85. (if file-name
  86. (neotree-find file-name)))))))
  87. (provide 'init-neotree)
  88. ;; Local Variables:
  89. ;; byte-compile-warnings: (not free-vars)
  90. ;; End:
  91. ;;; init-neotree.el ends here