Created
February 17, 2017 19:59
-
-
Save caiorss/ab7bce6587789abdf86dd6d928e3ee60 to your computer and use it in GitHub Desktop.
Emacs/ Elisp - Switch between buffer types. Example switch between only c++ *.cpp (c++-mode), files, c-mode *.c, c-mode *.h and so on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Question: Is there a package/lisp code that lets me cycle through filetype buffers? | |
;; Reddit tpic: https://www.reddit.com/r/emacs/comments/5tjgsb/is_there_a_packagelisp_code_that_lets_me_cycle/ | |
;; | |
;; | |
(require 'helm) ;; | |
(require 'cl) ;; | |
(defun switch-buffer-type (buffer-major-mode file-extension) | |
(let ((items (mapcar | |
(lambda (buf) (cons (buffer-name buf) buf)) | |
(remove-if-not (lambda (buf) | |
(and ;; if buffer-major-mode is nil - select buffer by file extension | |
(if buffer-major-mode | |
(equal buffer-major-mode (buffer-local-value 'major-mode buf)) | |
t | |
) | |
;; if file-extension is null - select buffer by major-mode | |
(if file-extension | |
(string-suffix-p file-extension (buffer-file-name buf)) | |
t | |
))) | |
(buffer-list))))) | |
(helm | |
:prompt "Buffer switch: " | |
:sources `(( | |
(name . "Dir: ") | |
(candidates . ,items) | |
(action . switch-to-buffer) | |
))))) | |
(defun switch-cpp-files () | |
(interactive) | |
(switch-buffer-type 'c++-mode ".cpp")) | |
(defun switch-h-files () | |
(interactive) | |
(switch-buffer-type 'c-mode ".h")) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment