Skip to content

Instantly share code, notes, and snippets.

@aarvid
Created September 6, 2013 15:10
Show Gist options
  • Save aarvid/6465196 to your computer and use it in GitHub Desktop.
Save aarvid/6465196 to your computer and use it in GitHub Desktop.
modification of bcycle. https://github.com/dalkire/bcycle
;;; bcycle.el --- buffer cycling with skip patterns
;; https://github.com/dalkire/bcycle
;; Intro
;; --------------------
;; This file is a simple alternative to next-buffer/previous-buffer.
;; It adds the ability to include patterns to match buffers to skip.
;; Usage
;; --------------------
;; Download this repository into your .emacs.d directory.
;; Include the directory in your load-path.
;; Require the package and configure it to your liking.
;; Example Code in .emacs:
;; (add-to-list 'load-path "~/.emacs.d/bcycle")
;; (require 'bcycle)
;; (setq bcycle-skip-patterns (cons "^my-new-pattern$" bcycle-skip-patterns))
;; (global-set-key (kbd "M-TAB") 'bcycle-next-buffer)
;; (global-set-key (kbd "M-`") 'bcycle-previous-buffer)
;;; Code:
(require 'cl)
(defvar bcycle-skip-patterns '("^\s*\\*" "^\s*%"))
(defvar bcycle-dont-skip '("*slime-repl sbcl*")
"explicit buffers not to skip")
(defun bcycle-matches-regexp (str regexp-list)
"Return non-nil if str matches anything in regexp-list."
(loop for regexp in regexp-list thereis (string-match regexp str)))
(defun bcycle-cycle-buffer (buffer-function)
(let ((orig-bname (buffer-name (current-buffer))))
(funcall buffer-function)
(while (let ((curr-bname (buffer-name (current-buffer))))
(and (bcycle-matches-regexp curr-bname bcycle-skip-patterns)
(not (member curr-bname bcycle-dont-skip))
(not (equal curr-bname orig-bname))))
(funcall buffer-function))))
(defun bcycle-next-buffer ()
"Goes to the next buffer that doesn't match any exclusion patterns."
(interactive)
(bcycle-cycle-buffer 'next-buffer))
(defun bcycle-previous-buffer ()
"Goes to the previous buffer that doesn't match any exclusion patterns."
(interactive)
(bcycle-cycle-buffer 'previous-buffer))
(provide 'bcycle)
;;; bcycle ends here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment