Emacs does not show the file’s trailing newline as a visible line, since it is just a `\n` at the end of the last real line. This makes it hard to see if a file ends with a newline. This package provides a clear indicator (⏎) for that otherwise invisible trailing newline. Optionally, it can also display the next line number (e.g., ⏎ 43) when line numbers are active.
- Shows a ⏎ symbol at the end of a file to mark the trailing newline.
- Optionally shows the next line number beside it (requires `display-line-numbers-mode`).
- Works with most buffer operations and updates automatically.
You can install this package using any of the following methods:
This is the recommended method for installing this package.
First, ensure you have the MELPA repository configured in your Emacs. If you haven’t already, add this to your init file:
(require 'package)
(add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t)
(package-initialize)Then install the package:
M-x package-install RET trailing-newline-indicator RETOr if you use `use-package`:
(use-package trailing-newline-indicator
:ensure t
:init
(global-trailing-newline-indicator-mode 1))Emacs 29 and later can install packages directly from Git repositories.
(package-vc-install "https://github.com/saulotoledo/trailing-newline-indicator")
(require 'trailing-newline-indicator)
(global-trailing-newline-indicator-mode 1)You can later update all VC-installed packages with:
(package-vc-update-all)Alternatively, if you use `use-package`:
(use-package trailing-newline-indicator
:ensure nil
:vc (:url "https://github.com/saulotoledo/trailing-newline-indicator")
:init
(global-trailing-newline-indicator-mode 1))For manual installation, clone the repository to a directory in your `load-path`:
git clone https://github.com/saulotoledo/trailing-newline-indicator.git \
~/.emacs.d/lisp/trailing-newline-indicatorThen add the following to your Emacs configuration:
(add-to-list 'load-path "~/.emacs.d/lisp/trailing-newline-indicator")
(require 'trailing-newline-indicator)
(global-trailing-newline-indicator-mode 1)Note: Adjust the path (`~/.emacs.d/lisp/trailing-newline-indicator`) to match your preferred location.
To activate the trailing newline indicator in just the current buffer:
M-x trailing-newline-indicator-modeOr programmatically:
(trailing-newline-indicator-mode 1)To activate the indicator automatically in all file buffers:
M-x global-trailing-newline-indicator-modeOr programmatically:
(global-trailing-newline-indicator-mode 1)The global mode automatically excludes minibuffers, special modes, and buffers without files.
You can customize the indicator and its behavior:
- To show the next line number (e.g., “⏎ 43”) instead of just the ⏎ symbol:
(setq trailing-newline-indicator-show-line-number t)This feature requires `display-line-numbers-mode`. If line numbers are disabled, only the ⏎ symbol is shown.
- To change the indicator icon (default is ⏎), set:
(setq trailing-newline-indicator-newline-symbol "↵")You can use any string or Unicode character you prefer. This is especially useful if your font does not support the default symbol.
