-
Notifications
You must be signed in to change notification settings - Fork 8
/
buffer-setting.el
71 lines (67 loc) · 2.45 KB
/
buffer-setting.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
;; -*- coding: utf-8 -*-
;; File: buffer-setting.el
;;
;; Author: Denny Zhang(https://www.dennyzhang.com/contact)
;; Copyright 2020, https://DennyZhang.com
;; Created:2008-10-01
;; Updated: Time-stamp: <2020-02-03 15:37:48>
;;
;; --8<-------------------------- separator ------------------------>8--
(defun next-user-buffer ()
"Switch to the next user buffer.
User buffers are those whose name does not start with *."
(interactive)
(next-buffer)
(let ((i 0))
(while (and (string-match "^*" (buffer-name)) (< i 50))
(setq i (1+ i)) (next-buffer) )))
(defun previous-user-buffer ()
"Switch to the previous user buffer.
User buffers are those whose name does not start with *."
(interactive)
(previous-buffer)
(let ((i 0))
(while (and (string-match "^*" (buffer-name)) (< i 50))
(setq i (1+ i)) (previous-buffer) )))
(defun next-emacs-buffer ()
"Switch to the next emacs buffer.
Emacs buffers are those whose name starts with *."
(interactive)
(next-buffer)
(let ((i 0))
(while (and (not (string-match "^*" (buffer-name))) (< i 50))
(setq i (1+ i)) (next-buffer) )))
(defun previous-emacs-buffer ()
"Switch to the previous emacs buffer.
Emacs buffers are those whose name starts with *."
(interactive)
(previous-buffer)
(let ((i 0))
(while (and (not (string-match "^*" (buffer-name))) (< i 50))
(setq i (1+ i)) (previous-buffer) )))
(global-set-key (kbd "<C-tab>") 'previous-user-buffer) ; Ctrl+Tab
(global-set-key (kbd "<C-S-iso-lefttab>") 'next-user-buffer) ; Ctrl+Shift+Tab
(global-set-key (kbd "<C-S-prior>") 'previous-emacs-buffer) ; Ctrl+Shift+PageUp
(global-set-key (kbd "<C-S-next>") 'next-emacs-buffer) ; Ctrl+Shift+PageDown
;; --8<-------------------------- separator ------------------------>8--
;;alt+p k: kill all other buffers except current buffer
(global-set-key [(meta p)(k)] 'kill-other-buffers)
(defun kill-other-buffers (&optional arg)
(interactive "P")
(let ((curbuf (buffer-name))
(buflist (mapcar (function buffer-name) (buffer-list))))
(dolist (buf buflist)
(unless (string= curbuf buf) (kill-buffer buf))
))
)
;; --8<-------------------------- separator ------------------------>8--
;; TODO enhance this
(defun widen-all-buffers ()
"If some buffer are in narrow status, emacs may fail to exit
Thus widen each buffer, before emacs exit"
(interactive)
(dolist (buffer (buffer-list))
(switch-to-buffer buffer)
(widen)
))
(add-hook 'kill-emacs-hook 'widen-all-buffers)