UP | HOME

Defaults Configuration

Table of Contents


The code below collects customizations for Emacs built-in components.

(use-package emacs
  :custom
  (bidi-paragraph-direction 'left-to-right)
  (delete-by-moving-to-trash t)
  (version-control t)
  (delete-old-versions t)
  (vc-make-backup-files t)
  (inhibit-startup-screen t)
  (register-preview-delay 0)
  (ring-bell-function #'ignore)
  (visible-bell t)
  (column-number-mode t)
  :config
  (add-hook 'before-save-hook 'time-stamp)
  (if (version<= "27.1" emacs-version)
      (setq bidi-inhibit-bpa t))
  (setq-default indent-tabs-mode nil)
  (fset 'yes-or-no-p 'y-or-n-p))

Automatic Time Stamps

Emacs supports time stamps in any text buffer where Time-stamp: <> can be found in the first eight lines. The time-stamp command can then be used to automatically update the time. A simpler solution, however, is to have Emacs automatically update the time stamp when the buffer is saved.

(add-hook 'before-save-hook 'time-stamp)

Bidirectional Editing

Emacs supports bidirectional editing. This is rarely used feature for many and can actually result in slower performance. To improve performance if bidirectional editing it not used, the following can be set:

  1. Tell Emacs that text should be read from left to right.

    (bidi-paragraph-direction 'left-to-right)
    
  2. Turn off bidrectional editing mode.

    (if (version<= "27.1" emacs-version)
        (setq bidi-inhibit-bpa t))
    

Display Battery Mode

Display Battery Mode will display the battery charge status in the modeline

(use-package battery
  :straight (:type built-in)
  :defer 3
  :config
  (display-battery-mode t))

Send Deleted Files to System Trash

Emacs does not send files to the trash by default which is counter-intuitive for many beginning users. In order to risk losing files it is a good idea to turn on the option to send all files to the system trash.

(delete-by-moving-to-trash t)

Backup Files with Version Control

Emacs has a built-in version control system in which it will create a series of backup files. This will create a number of backup flies, however, that will need to be cleaned up on a regular basis.

(version-control t)
(delete-old-versions t)
(vc-make-backup-files t)

Indent Using Spaces

Indenting with spaces rather than tabs is genrally recommended when working with code. Especially when writing code in Python.

(setq-default indent-tabs-mode nil)

Inhibit Startup Screen

After seeing the startup screen hundreds of times, there is no longer any need to load it on startup as it no longer contains any new information.

(inhibit-startup-screen t)

Register Delay

(register-preview-delay 0)

Ring Bell Function

(ring-bell-function #'ignore)
(visible-bell t)

Shorten "Yes or No" to "Y or N"

To make work faster, instead of typing "yes" or "no" for each question prompt, use just "y" or "n" .

(fset 'yes-or-no-p 'y-or-n-p)

Show Column Number

Many programming language style guides recommend that each line of code is less than 80 characters long. To determine if code lines are too long, a simple tool is to activate column-number-mode. Once enabled, the current column (i.e. the number of characters on that line) will be displayed.

(column-number-mode t)

A better fix would be to use code formatters to prevent lines from getting too long. For example, Apheleia will run formatters such as Black on Python code to keep code lines from becoming too long.

End

(provide 'freemacs-defaults)

;;; freemacs-defaults.el ends here

Date: Time-stamp: <2022-07-21 Thu 18:25>

Author: Thomas Freeman

Created: 2022-07-21 Thu 18:26

Validate