diff options
| author | Nathan Moreau <nathan.moreau@m4x.org> | 2018-10-03 22:29:38 +0200 |
|---|---|---|
| committer | Bozhidar Batsov <bozhidar.batsov@gmail.com> | 2018-10-03 23:29:38 +0300 |
| commit | b94b05b38e1d76f249d1283fc5c3d0880a639cfd (patch) | |
| tree | ddd373892d8aba3473023f727079d1bf7ac8f62a | |
| parent | 702a1e31a4b5459205d946e8efd743fecf4fbf5b (diff) | |
[Fix #896] Add previous/next project buffer commands (#1312)
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | doc/usage.md | 2 | ||||
| -rw-r--r-- | projectile.el | 37 |
3 files changed, 41 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index a7e6d58..25f7cdc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ * Add [crystal](https://crystal-lang.org) project type. * [#850](https://github.com/bbatsov/projectile/issues/850): Make it possible to prompt for a project, when you're not in a project, instead of raising an error. (see `projectile-require-project-root`). * **(Breaking)** [#1147](https://github.com/bbatsov/projectile/issues/1147): Introduce a faster indexing method - `turbo-alien` (it's the default now). +* [#896](https://github.com/bbatsov/projectile/issues/896) Add commands `projectile-previous-project-buffer ` and +`projectile-next-project-buffer ` to switch to other buffer in the project. ### Changes diff --git a/doc/usage.md b/doc/usage.md index 8643a4b..54af789 100644 --- a/doc/usage.md +++ b/doc/usage.md @@ -94,6 +94,8 @@ Keybinding | Description <kbd>s-p 4 D</kbd> | Opens the root of the project in `dired` in another window. <kbd>s-p 5 D</kbd> | Opens the root of the project in `dired` in another frame. <kbd>s-p e</kbd> | Shows a list of recently visited project files. +<kbd>s-p left</kbd> | Switch to the previous project buffer. +<kbd>s-p right</kbd> | Switch to the next project buffer. <kbd>s-p E</kbd> | Opens the root `dir-locals-file` of the project. <kbd>s-p s s</kbd> | Runs `ag` on the project. Requires the presence of `ag.el`. <kbd>s-p !</kbd> | Runs `shell-command` in the root directory of the project. diff --git a/projectile.el b/projectile.el index 046d218..d9d1ba1 100644 --- a/projectile.el +++ b/projectile.el @@ -1361,6 +1361,7 @@ If PROJECT is not specified the command acts on the current project." (with-current-buffer buffer (and (not (string-prefix-p " " (buffer-name buffer))) (not (projectile-ignored-buffer-p buffer)) + default-directory (string-equal (file-remote-p default-directory) (file-remote-p project-root)) (not (string-match-p "^http\\(s\\)?://" default-directory)) @@ -4025,6 +4026,8 @@ thing shown in the mode line otherwise." (define-key map (kbd "x t") #'projectile-run-term) (define-key map (kbd "x s") #'projectile-run-shell) (define-key map (kbd "z") #'projectile-cache-current-file) + (define-key map (kbd "<left>") #'projectile-previous-project-buffer) + (define-key map (kbd "<right>") #'projectile-next-project-buffer) (define-key map (kbd "ESC") #'projectile-project-buffers-other-buffer) map) "Keymap for Projectile commands after `projectile-keymap-prefix'.") @@ -4048,6 +4051,8 @@ thing shown in the mode line otherwise." ["Kill project buffers" projectile-kill-buffers] ["Save project buffers" projectile-save-buffers] ["Recent files" projectile-recentf] + ["Previous buffer" projectile-previous-project-buffer] + ["Next buffer" projectile-next-project-buffer] "--" ["Toggle project wide read-only" projectile-toggle-project-read-only] ["Edit .dir-locals.el" projectile-edit-dir-locals] @@ -4144,6 +4149,38 @@ Otherwise behave as if called interactively. ;;;###autoload (define-obsolete-function-alias 'projectile-global-mode 'projectile-mode "1.0") +(defun projectile--repeat-until-project-buffer (orig-fun &rest args) + "Repeat ORIG-FUN with ARGS until the current buffer is a project buffer." + (if (projectile-project-root) + (let* ((other-project-buffers (make-hash-table :test 'eq)) + (projectile-project-buffers (projectile-project-buffers)) + (max-iterations (length (buffer-list))) + (counter 0)) + (dolist (buffer projectile-project-buffers) + (unless (eq buffer (current-buffer)) + (puthash buffer t other-project-buffers))) + (when (cdr-safe projectile-project-buffers) + (while (and (< counter max-iterations) + (not (gethash (current-buffer) other-project-buffers))) + (apply orig-fun args) + (incf counter)))) + (apply orig-fun args))) + +(defun projectile-next-project-buffer () + "In selected window switch to the next project buffer. + +If the current buffer does not belong to a project, call `next-buffer'." + (interactive) + (projectile--repeat-until-project-buffer #'next-buffer)) + +(defun projectile-previous-project-buffer () + "In selected window switch to the previous project buffer. + +If the current buffer does not belong to a project, call `previous-buffer'." + (interactive) + (projectile--repeat-until-project-buffer #'previous-buffer)) + + (provide 'projectile) ;;; projectile.el ends here |
