summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2021-01-02 22:49:54 -0600
committerCase Duckworth2021-01-02 22:49:54 -0600
commit3a5d43de30e6f6f94a774d4d69657ca2ccb2a850 (patch)
treef8e004cafe9b8b19a09191b1f27902647176fafb
parentChange ring-bell-function (diff)
downloademacs-3a5d43de30e6f6f94a774d4d69657ca2ccb2a850.tar.gz
emacs-3a5d43de30e6f6f94a774d4d69657ca2ccb2a850.zip
Kill current buffer
-rw-r--r--config.org45
1 files changed, 45 insertions, 0 deletions
diff --git a/config.org b/config.org index ec81761..0fa3911 100644 --- a/config.org +++ b/config.org
@@ -313,6 +313,51 @@ Commented for now because I really need to figure out the keybindings I want to
313 (global-set-key (kbd "<C-S-right>") 'buf-move-right) 313 (global-set-key (kbd "<C-S-right>") 'buf-move-right)
314#+end_src 314#+end_src
315 315
316**** Kill the current buffer
317
318 #+begin_src emacs-lisp
319 (defun acdw/kill-a-buffer (&optional prefix)
320 "Kill a buffer based on the following rules:
321
322 C-x k ⇒ Kill current buffer & window
323 C-u C-x k ⇒ Kill OTHER window and its buffer
324 C-u C-u C-x C-k ⇒ Kill all other buffers and windows
325
326 Prompt only if there are unsaved changes."
327 (interactive "P")
328 (pcase (or (car prefix) 0)
329 ;; C-x k ⇒ Kill current buffer & window
330 (0 (kill-current-buffer)
331 (unless (one-window-p) (delete-window)))
332 ;; C-u C-x k ⇒ Kill OTHER window and its buffer
333 (4 (other-window 1)
334 (kill-current-buffer)
335 (unless (one-window-p) (delete-window)))
336 ;; C-u C-u C-x C-k ⇒ Kill all other buffers and windows
337 (16 (mapc 'kill-buffer (delq (current-buffer) (buffer-list)))
338 (delete-other-windows))))
339
340 (define-key ctl-x-map "k" #'acdw/kill-a-buffer)
341 #+end_src
342
343***** Remap =C-x M-k= to bring up the buffer-killing menu
344
345 #+begin_src emacs-lisp
346 (define-key ctl-x-map (kbd "M-k") #'kill-buffer)
347 #+end_src
348
349**** Immortal =*scratch*= buffer
350
351 #+begin_src emacs-lisp
352 (defun immortal-scratch ()
353 (if (eq (current-buffer) (get-buffer "*scratch*"))
354 (progn (bury-buffer)
355 nil)
356 t))
357
358 (add-hook 'kill-buffer-query-functions 'immortal-scratch)
359 #+end_src
360
316*** Modeline 361*** Modeline
317 362
318**** Smart mode line 363**** Smart mode line