Imported sources
[vee.git] / buffers.el
blob3b70ff54cf0cc5cf8b9b49ef5331e2ab2b8fb80a
1 (defun other-window-reverse (arg &optional all-frames)
2 (interactive "p")
3 (other-window (* -1 arg) all-frames))
5 (defun kill-other-buffer-and-window (arg &optional all-frames)
6 (interactive "p\nP")
7 (save-excursion
8 (other-window arg all-frames)
9 (kill-buffer-and-window-noprompt)))
11 (defun kill-buffer-and-window-noprompt ()
12 "Kill the current buffer and delete the selected window."
13 (interactive)
14 (kill-this-buffer)
15 (delete-window (selected-window)))
17 (defun find-file-and-kill-current-buffer ()
18 "Find file and kill the current buffer in the same window"
19 (interactive)
20 (let ((buffer (current-buffer)))
21 (call-interactively (or (command-remapping 'find-file) 'find-file))
22 (kill-buffer buffer)))
24 (defun kill-buffers-matching (regexp)
25 "Kill all the buffers matching regexp"
26 (interactive "BKill buffers matching: ")
27 (mapc '(lambda (buffer)
28 (and (string-match regexp (buffer-name buffer))
29 (kill-buffer buffer)))
30 (buffer-list)))
32 (defun create-scratch-buffer nil
33 (set-buffer (get-buffer-create "*scratch*"))
34 (save-window-excursion
35 (require 'help-fns)
36 (random t)
37 (let* ((commands (loop for s being the symbols
38 when (commandp s) collect s))
39 (command (nth (random (length commands)) commands))
40 (help-xref-following t)
41 (begin nil)
42 (title (format "| Emacs random command: `%s' |" command)))
45 (describe-function command)
47 (lisp-interaction-mode)
49 (goto-char (point-min))
50 (insert initial-scratch-message)
51 (setq begin (point-marker))
53 (insert-char ?+ (string-width title))
54 (insert "\n" title "\n")
55 (insert-char ?+ (string-width title))
56 (insert "\nInvoke using: " (with-temp-buffer (where-is command t)
57 (buffer-string))
58 "\n\n")
59 (goto-char (point-max))
61 (insert "\n\n"
62 "++++++++++++++++++\n"
63 "| Random Fortune |\n"
64 "++++++++++++++++++\n\n"
65 (shell-command-to-string
66 (concat "which fortune 2>/dev/null 1>/dev/null "
67 "&& fortune futurama"
68 "|| echo You have no fortune!")))
70 (insert "\n")
72 (comment-region begin (point)))
73 (buffer-enable-undo)
74 (make-local-variable 'kill-buffer-query-functions)
75 (add-hook 'kill-buffer-query-functions 'kill-scratch-buffer)))
77 (defun kill-scratch-buffer nil
78 (set-buffer (get-buffer "*scratch*"))
79 (remove-hook 'kill-buffer-query-functions 'kill-scratch-buffer)
80 (kill-buffer (current-buffer))
81 (create-scratch-buffer)
82 nil)
84 (add-hook 'emacs-startup-hook 'create-scratch-buffer)
86 (def-keys (current-global-map)
87 ;; windows
88 "C-x p" 'other-window-reverse ;; just like `ojkther-window'
90 ;; frames
91 "H-f 0" 'delete-frame
92 "H-f 2" 'new-frame
93 "H-f 1" 'delete-other-frames
94 "H-f o" 'other-frame
96 ;; killing buffers
97 "C-x 9 f" 'find-file-and-kill-current-buffer
98 "C-x 9 0" 'kill-buffer-and-window-noprompt
99 "C-x 9 1" 'kill-other-buffer-and-window
100 "C-x 9 k" 'kill-buffers-matching)
102 (when (require? 'wn-mode) (enable-mode wn))
104 (provide 'vee/buffers)