├── LICENSE.md ├── .gitignore ├── .projectile ├── README.md └── projectile-speedbar.el /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Temporary files 2 | *~ 3 | *#* 4 | -------------------------------------------------------------------------------- /.projectile: -------------------------------------------------------------------------------- 1 | # SCM 2 | .git/ 3 | 4 | # Temporary files 5 | *~ 6 | *#* 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | projectile + speedbar 2 | ======== 3 | 4 | ## Summary 5 | 6 | This package sits on top of speedbar and projectile and provides an easy 7 | to use and useful integration between the two. 8 | 9 | With this package when you switch between projects that work with 10 | projectile, speedbar will automatically show the directory listing of 11 | that project as well as expand the tree to show the file in the project. 12 | 13 | ## Dependencies 14 | 15 | Features that are required by this library: `speedbar` `sr-speedbar` 16 | `projectile` 17 | 18 | ## Installation 19 | 20 | ### Melpa 21 | 22 | This package is available to install via Melpa. First, make sure the 23 | Melpa package archive is available. 24 | 25 | ``` lisp 26 | (require 'package) 27 | (add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/")) 28 | ``` 29 | 30 | Then, install this package: 31 | 32 | ``` lisp 33 | (package-install 'projectile-speedbar) 34 | ``` 35 | 36 | ### Manual 37 | 38 | Copy speedbar-projectile.el to your load-path and add this to ~/.emacs 39 | 40 | (require 'projectile-speedbar) 41 | 42 | To invoke this function manually: 43 | 44 | `projectile-speedbar-open-current-buffer-in-tree 45 | 46 | ## Customizations 47 | 48 | Sometimes, when I am deep in a project tree, I like to use this shortcut 49 | to see full context: 50 | 51 | (global-set-key (kbd "M-") 'projectile-speedbar-open-current-buffer-in-tree) 52 | 53 | You can also disable the feature completely: 54 | 55 | (setq projectile-speedbar-projectile-speedbar-enable nil) 56 | 57 | -------------------------------------------------------------------------------- /projectile-speedbar.el: -------------------------------------------------------------------------------- 1 | ;;; projectile-speedbar.el --- projectile integration for speedbar 2 | 3 | ;; Copyright (C) 2014 Anshul Verma 4 | 5 | ;; Author: Anshul Verma 6 | ;; URL: https://github.com/anshulverma/projectile-speedbar 7 | ;; Keywords: project, convenience, speedbar, projectile 8 | ;; Version: 0.0.1 9 | ;; Package-Requires: ((projectile "0.11.0") (sr-speedbar "0")) 10 | 11 | ;; This file is NOT part of GNU Emacs. 12 | 13 | ;;; License 14 | ;; 15 | ;; This program is free software; you can redistribute it and/or modify 16 | ;; it under the terms of the GNU General Public License as published by 17 | ;; the Free Software Foundation; either version 3, or (at your option) 18 | ;; any later version. 19 | 20 | ;; This program is distributed in the hope that it will be useful, 21 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 22 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 23 | ;; GNU General Public License for more details. 24 | 25 | ;; You should have received a copy of the GNU General Public License 26 | ;; along with this program; see the file COPYING. If not, write to 27 | ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth 28 | ;; Floor, Boston, MA 02110-1301, USA. 29 | 30 | ;;; Commentary: 31 | ;; 32 | ;; This package sits on top of speedbar and projectile and provides an 33 | ;; easy to use and useful integration between the two. 34 | ;; 35 | ;; With this package when you switch between projects that work with 36 | ;; projectile, speedbar will automatically show the directly listing 37 | ;; of that project as well as expand the tree to show the file in the 38 | ;; project. 39 | ;; 40 | ;; Features that are required by this library: 41 | ;; 42 | ;; `speedbar' `sr-speedbar' `projectile' 43 | ;; 44 | ;; To invoke this function manually: 45 | ;; 46 | ;; `projectile-speedbar-open-current-buffer-in-tree 47 | ;; 48 | 49 | ;;; Installation 50 | ;; 51 | ;; Copy speedbar-projectile.el to your load-path and add this to ~/.emacs 52 | ;; 53 | ;; (require 'projectile-speedbar) 54 | ;; 55 | 56 | ;;; Customize: 57 | ;; 58 | ;; Sometimes, when I am deep in a project tree, I like to use this shortcut 59 | ;; to see full context: 60 | ;; 61 | ;; (global-set-key (kbd "M-") 'projectile-speedbar-open-current-buffer-in-tree) 62 | ;; 63 | ;; You can also disable the feature completely: 64 | ;; 65 | ;; (setq projectile-speedbar-projectile-speedbar-enable nil) 66 | 67 | ;;; Change log: 68 | ;; 69 | ;; * 13 June 2014: 70 | ;; * Anshul Verma 71 | ;; * Initial feature with commentary 72 | ;; 73 | ;; * 13 June 2014 74 | ;; * Anshul Verma 75 | ;; * fix bug "should switch to file buffer after opening a file via projectile-find-file" 76 | ;; 77 | ;; * 27 June 2014 78 | ;; * Anshul Verma 79 | ;; * add ability to turn projectile speedbar off 80 | ;; 81 | ;; * 13 January 2015 82 | ;; * Anshul Verma 83 | ;; * fix headers to comply with standards 84 | 85 | ;;; Acknowledgments 86 | ;; 87 | ;; All emacsers ... :) 88 | ;; 89 | 90 | ;;; Bug 91 | ;; 92 | ;; * Should select the current buffer file in directory listing after project switch 93 | ;; 94 | 95 | ;;; TODO 96 | ;; 97 | ;; * Find a better way to get project root 98 | ;; 99 | 100 | ;;; Code: 101 | 102 | (require 'speedbar) 103 | (require 'sr-speedbar) 104 | (require 'projectile) 105 | 106 | (defgroup projectile-speedbar nil 107 | "Auto refresh speedbar based on projectile." 108 | :group 'speedbar) 109 | 110 | (defcustom projectile-speedbar-enable t 111 | "Do not auto-refresh speedbar using `projectile-speedbar'. 112 | Set to nil to disable projectile speedbar. Default is t." 113 | :type 'boolean 114 | :set (lambda (symbol value) 115 | (set symbol value)) 116 | :group 'projectile-speedbar) 117 | 118 | (defun projectile-speedbar-project-refresh (root-dir) 119 | "Refresh the context of speedbar based on project root" 120 | (when (and (not (equal root-dir sr-speedbar-last-refresh-dictionary)) 121 | (not (sr-speedbar-window-p))) 122 | (setq sr-speedbar-last-refresh-dictionary root-dir)) 123 | (setq default-directory root-dir) 124 | (speedbar-refresh)) 125 | 126 | (defun projectile-speedbar-open-current-project-in-speedbar (root-dir) 127 | "Refresh speedbar to show current project in tree" 128 | (if (not (sr-speedbar-exist-p)) 129 | (sr-speedbar-toggle)) 130 | (projectile-speedbar-project-refresh root-dir)) 131 | 132 | (defun projectile-speedbar-expand-line-list (&optional arg) 133 | (when arg 134 | (re-search-forward (concat " " (car arg) "$")) 135 | (speedbar-expand-line (car arg)) 136 | (speedbar-next 1) 137 | (projectile-speedbar-expand-line-list (cdr arg)))) 138 | 139 | ;;;###autoload 140 | (defun projectile-speedbar-open-current-buffer-in-tree () 141 | (interactive) 142 | (let* ((root-dir (projectile-project-root)) 143 | (original-buffer-file-directory (file-name-directory 144 | (file-truename (buffer-file-name)))) 145 | (relative-buffer-path (car (cdr (split-string original-buffer-file-directory 146 | (regexp-quote root-dir))))) 147 | (parents (butlast (split-string relative-buffer-path "/"))) 148 | (original-window (get-buffer-window))) 149 | (if projectile-speedbar-enable 150 | (save-excursion 151 | (projectile-speedbar-open-current-project-in-speedbar root-dir) 152 | (select-window (get-buffer-window speedbar-buffer)) 153 | (beginning-of-buffer) 154 | (projectile-speedbar-expand-line-list parents) 155 | (if (not (eq original-window (get-buffer-window speedbar-buffer))) 156 | (select-window original-window) 157 | (other-window 1)))))) 158 | 159 | ;;;###autoload 160 | (defun projectile-speedbar-toggle () 161 | (interactive) 162 | (sr-speedbar-toggle) 163 | (if (sr-speedbar-exist-p) 164 | (projectile-speedbar-open-current-buffer-in-tree))) 165 | 166 | (add-hook 'projectile-find-dir-hook 'projectile-speedbar-open-current-buffer-in-tree) 167 | (add-hook 'projectile-find-file-hook 'projectile-speedbar-open-current-buffer-in-tree) 168 | (add-hook 'projectile-cache-projects-find-file-hook 169 | 'projectile-speedbar-open-current-buffer-in-tree) 170 | (add-hook 'projectile-cache-files-find-file-hook 171 | 'projectile-speedbar-open-current-buffer-in-tree) 172 | 173 | (provide 'projectile-speedbar) 174 | 175 | ;;; projectile-speedbar.el ends here 176 | --------------------------------------------------------------------------------