1 (defun other-window-reverse (arg &optional all-frames
)
3 (other-window (* -
1 arg
) all-frames
))
5 (defun kill-other-buffer-and-window (arg &optional all-frames
)
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."
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"
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
)))
32 (defun create-scratch-buffer nil
33 (set-buffer (get-buffer-create "*scratch*"))
34 (save-window-excursion
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
)
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
)
59 (goto-char (point-max))
62 "++++++++++++++++++\n"
63 "| Random Fortune |\n"
64 "++++++++++++++++++\n\n"
65 (shell-command-to-string
66 (concat "which fortune 2>/dev/null 1>/dev/null "
68 "|| echo You have no fortune!")))
72 (comment-region begin
(point)))
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)
84 (add-hook 'emacs-startup-hook
'create-scratch-buffer
)
86 (def-keys (current-global-map)
88 "C-x p" 'other-window-reverse
;; just like `ojkther-window'
93 "H-f 1" 'delete-other-frames
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
)