Skip to content

In Emacs, operate on current line if no region is active

Notifications You must be signed in to change notification settings

m2ym/whole-line-or-region

This branch is 7 commits behind purcell/whole-line-or-region:refs/heads/master.

Repository files navigation

Melpa Status Melpa Stable Status Build Status Support me

In Emacs, operate on the current line if no region is active

This minor mode allows functions to operate on the current line if they would normally operate on a region and region is currently undefined.

The primary use for this is to kill (cut) the current line if no region is defined, and kill-region is invoked. It basically saves you the effort of going to the begining of the line, selecting the text up to the end of the line, and killing. Similarly, when yanking, it's smart enough to know that the string to be yanked was killed as a whole line, and it should be yanked as one, too. So you don't need to position yourself at the start of the line before yanking. If region is defined, though, all functions act as normal.

This minor mode was originally written by Joe Casadonte in 2001, and was maintained for recent Emacsen by Steve Purcell for several years. In 2020 the internals were rewritten to use modern Emacs features such as filter-buffer-substring-function and yank-handler, and thereby behave more consistently.

Usage

Enabling whole-line-or-region-global-mode causes the common kill/copy commands to be remapped. When no region is active, if you type C-w then the current line will be killed. When yanked using C-y, it will be yanked before the current line. If a region is active, e.g. if you have selected a word, the commands will behave as usual.

Other commands are similarly overridden, e.g. comment-dwim: see whole-line-or-region-local-mode-map for more details.

Using positive numeric prefix arguments, you can operate on multiple lines at once, e.g. C-3 C-w will kill 3 whole lines, beginning with the current line. Cycling yanks with yank-pop (M-y) should also work correctly.

Functions are provided which allow you to easily wrap other commands so that they will also operate on the current line by default. The wrapped commands can then similarly be remapped in whole-line-or-region-local-mode-map.

Installation

Manual

Ensure whole-line-or-region.el is in a directory on your load-path, and add the following to your ~/.emacs or ~/.emacs.d/init.el:

(require 'whole-line-or-region)

MELPA

If you're an Emacs 24 user or you have a recent version of package.el you can install whole-line-or-region from the MELPA repository. The version of whole-line-or-region there will always be up-to-date.

About

Author: Steve Purcell

Homepage: https://github.com/purcell/whole-line-or-region


💝 Support this project and my other Open Source work

💼 LinkedIn profile

✍ sanityinc.com

🐦 @sanityinc

About

In Emacs, operate on current line if no region is active

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Emacs Lisp 96.7%
  • Makefile 3.3%