;;; buffers.el --- Default settings for buffers. -*- lexical-binding: t; -*- ;; Time-stamp: <2020-01-24T23:25:31+0100> ;;; Commentary: ;; * Setup scratch buffer. ;; * Set fill-column. ;; * Define which buffers should be ignored. ;; * Enable auto-fill-mode. ;;; Code: (use-package emacs :ensure nil :custom (initial-scratch-message nil) ; Make scratch buffer empty, (initial-major-mode 'markdown-mode) ; and select mode. :config (defvar my/skippable-buffers '("^\\*" "^magit[:-]") "Buffer names ignored by `next-buffer' and `previous-buffer'.") (defvar my/never-skippable-buffers '("^\\*scratch\\*$" "^\\*Easy-hugo\\*$") "Buffer names never ignored by `next-buffer' and `previous-buffer'.") (defun my/buffer-predicate (buffer) "Returns nil if buffer-name matches expression in `my/skippable-buffers'." (catch 'return ;; Return t if buffer-name is on never-skippable list. (dolist (expression my/never-skippable-buffers) (if (string-match expression (buffer-name buffer)) (throw 'return t) )) ;; Return nil if buffer-name is on skippable list. (dolist (expression my/skippable-buffers) (if (string-match expression (buffer-name buffer)) (throw 'return nil) )) t)) (set-frame-parameter nil 'buffer-predicate 'my/buffer-predicate) ) ;; Show and select buffers. (use-package bs :bind ("C-x C-b" . bs-show) ) ;; Delete old buffers. ;; https://www.emacswiki.org/emacs/CleanBufferList (use-package midnight :ensure nil ; Builtin. :defer 10 :init (setq midnight-delay 30 ; 30 seconds after “midnight”. midnight-period (* 2 60 60)) ; Clean every 2 hours. :custom (clean-buffer-list-delay-general 1) ; Clean normal bufs after 1d. (clean-buffer-list-delay-special (* 30 60)) ; Clean special bufs after 30m. :config (setq clean-buffer-list-kill-regexps ; Add these to special buffers. (nconc clean-buffer-list-kill-regexps '("^magit-?.*:" "\\.log$" "^\\*rdm\\*$" "^\\*Backtrace\\*$" "^Pfuture-Callback" ))) (midnight-mode t) ) (use-package window-purpose :pin melpa ; We need > 1.7 :defer nil :config (purpose-mode) (add-to-list 'purpose-user-mode-purposes '(c++-mode . cpp)) (add-to-list 'purpose-user-mode-purposes '(emacs-lisp-mode . elisp)) (add-to-list 'purpose-user-mode-purposes '(Man-mode . help-buffers)) (purpose-compile-user-configuration) (add-to-list 'purpose-special-action-sequences '(help-buffers purpose-display-reuse-window-buffer)) ;; All Magit buffers have the same purpose. (require 'window-purpose-x) (purpose-x-magit-single-on) :bind ("" . purpose-toggle-window-purpose-dedicated) ("C-" . purpose-toggle-window-buffer-dedicated) ) (provide 'basics/buffers) ;;; buffers.el ends here