Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 60 lines (47 sloc) 2.022 kB
0838bb7 @troydm buffcycle added
authored
1 ;;; buffcycle.el --- Buffer cycling for Emacs
2
3 ;; Copyright (C) 2011 Dmitry Geurkov
4
5 ;; Author: Dmitry Geurkov <dmitry_627@mail.ru>
6
7 ;; This program is free software: you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation, either version 3 of the License, or
10 ;; (at your option) any later version.
11
12 ;; This program is distributed in the hope that it will be useful,
13 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ;; GNU General Public License for more details.
16
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20 ;;; Commentary:
21 ;;; Simple Buffer cycling for Emacs between file buffers only using C-tab
22 ;;; and killing buffer using C-q
23 ;;; To use add
24 ;;; (require 'buffcycle)
25 ;;; to your .emacs
26
27 ;; Buffer Cycling
df0d7c7 @troydm buffcycle added switching to ibuffer on C-Tab
authored
28 (defvar *buffcycle-ibuffer-time* 0.5)
29 (defvar *buffcycle-last-time* (float-time))
30
0838bb7 @troydm buffcycle added
authored
31 (defun next-buffer-cycle()
32 (interactive)
df0d7c7 @troydm buffcycle added switching to ibuffer on C-Tab
authored
33 (let ((cur-buffer (buffer-name))
34 (time-diff 0.0))
35 (progn (setq time-diff (- (float-time) *buffcycle-last-time*))
36 (if (>= *buffcycle-ibuffer-time* time-diff)
37 (progn (setq *buffcycle-last-time* (float-time))
38 (ibuffer)))
39 (next-buffer)
95b801e @troydm buffcycle scratch buffer killing protection added
authored
40 (while (and (booleanp (buffer-file-name)) (not (string= (buffer-name) cur-buffer)))
df0d7c7 @troydm buffcycle added switching to ibuffer on C-Tab
authored
41 (next-buffer))
42 (setq *buffcycle-last-time* (float-time))
43 (if (string= cur-buffer (buffer-name))
44 (ibuffer)))))
95b801e @troydm buffcycle scratch buffer killing protection added
authored
45
46 (defun kill-this-buffer-if-not-scratch()
47 (interactive)
813be3f @troydm dedicated window kill protection added
authored
48 (if (window-dedicated-p (selected-window))
49 (message "this is dedicated window")
95b801e @troydm buffcycle scratch buffer killing protection added
authored
50 (if (not (string= (buffer-name) "*scratch*"))
51 (kill-this-buffer)
813be3f @troydm dedicated window kill protection added
authored
52 (message "this is scratch unkillable"))))
0838bb7 @troydm buffcycle added
authored
53
54 ;; Buffer Cycling keybindings
55 (global-set-key (kbd "<C-tab>") 'next-buffer-cycle)
95b801e @troydm buffcycle scratch buffer killing protection added
authored
56 (global-set-key (kbd "C-q") 'kill-this-buffer-if-not-scratch)
0838bb7 @troydm buffcycle added
authored
57
58 (provide 'buffcycle)
59
Something went wrong with that request. Please try again.