Skip to content

saulotoledo/trailing-newline-indicator

Repository files navigation

https://melpa.org/packages/trailing-newline-indicator-badge.svg

trailing-newline-indicator

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.

./preview.gif

Features

  • 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.

Installation

You can install this package using any of the following methods:

Installing via MELPA

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 RET

Or if you use `use-package`:

(use-package trailing-newline-indicator
  :ensure t
  :init
  (global-trailing-newline-indicator-mode 1))

Using package-vc-install (Emacs 29+)

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))

Manual installation

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-indicator

Then 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.

Usage

Enable locally (current buffer only)

To activate the trailing newline indicator in just the current buffer:

M-x trailing-newline-indicator-mode

Or programmatically:

(trailing-newline-indicator-mode 1)

Enable globally (all file buffers)

To activate the indicator automatically in all file buffers:

M-x global-trailing-newline-indicator-mode

Or programmatically:

(global-trailing-newline-indicator-mode 1)

The global mode automatically excludes minibuffers, special modes, and buffers without files.

Configuration

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.

About

Emacs package for showing an indicator for the trailing newline in the end of the file

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •