Skip to content

BriansEmacs/insert-pair-edit.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MELPA Github Actions Badge

Insert Pair Edit


insert-pair-edit

This project defines a GNU Emacs package, ipe ("i"nsert-"p"air-"e"dit). This package supplies commands that are a more feature rich alternative to the standard M-( Emacs keybinding, (insert-parentheses).


Overview

The ipe package supplies commands to insert (and also, update, edit and delete) "PAIRs" within an Emacs buffer. These PAIRs consist of OPEN and CLOSE strings that delimit text in some fashion. (This could be a simple open and close parentheses, ( and ), or, it could be a more complex pair of strings that are used within a programming language.)

The main entry point to the ipe package is the Emacs interactive command ipe-insert-pair-edit. When executed, this command will prompt the user to enter a MNEMONIC identifying a (customizable) PAIR via the Emacs minibuffer.

ipe-insert-pair-edit command

Selection of a MNEMONIC will cause two overlays to be inserted into the buffer. These overlays represent the OPEN and CLOSE strings of the PAIR to be inserted.

These overlays can then be either: immediately inserted into the buffer, or, more importantly, moved about the buffer to correctly surround the text to be enclosed by the PAIR.


Editing PAIRs

Insert Pair Edit - ipe-edit-mode

After adding the OPEN and CLOSE overlays into the buffer, the ipe-insert-pair-edit command starts the Insert Pair Edit minor mode (ipe-edit-mode)

The Insert Pair Edit (ipe) minor mode supplies commands to move these OPEN and CLOSE overlays about the buffer. When positioned correctly, these OPEN and CLOSE overlays can then either be inserted <RET> (ipe-edit--insert-pair), or discarded <C-g> (ipe-edit--abort).

The Insert Pair Edit (ipe) minor mode also supplies additional commands to:

  • Change the 'lexical units' used by the movement commands. Insert Pair Edit - lexical-units

  • Change the PAIR to be inserted on-the-fly. Insert Pair Edit - change-pair

  • Operate on the CONTENTS of the PAIR (i.e. the text between the OPEN and CLOSE overlays.) Text can be copied, deleted, replaced and case converted. Insert Pair Edit - change-contents

  • Escape characters between the OPEN and CLOSE strings. Insert Pair Edit - escapes

  • Search for (and edit) other PAIRs. Insert Pair Edit - other-pairs

  • Operate on multiple PAIRs at once. Insert Pair Edit - multiple-pairs

Customizations for the mode can be found under the ipe group.

Insert Pair Edit - customize


Mode-Specific

The set of PAIRs available for editing are defined per-major-mode.

Insert Pair Edit - markdown-mode

Example PAIR Definitions are supplied for:

  • Markdown
  • TexInfo
  • HTML

Pairs Menu

Insert Pair Edit - Menu

Most of the functionality of the ipe package can also be accessed via the Emacs menubar. If running Emacs in an environment which supports menus, the ipe package can add an extra Pairs sub-menu to the standard Emacs Edit menu item.

If the Pairs menu is enabled, the set of PAIRs listed under the Pairs -> Insert PAIR / Update PAIR / Delete PAIR sub-menus will change dynamically based upon the current buffer's major-mode.

Insert Pair Edit - Mode Menu

Selecting a menu item under Insert PAIR will insert the selected PAIR into the current buffer around POINT, and enter ipe-edit-mode.

Selecting a menu item under Update PAIR will update the nearest PAIR (of the given type) and enter ipe-edit-mode.

Selecting a menu item under Delete PAIR will delete the nearest PAIR (of the given type) and remain in the current Emacs mode.


Installation

1a. Download the ipe package from MELPA:

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.org/packages/"))
(package-initialize)
(package-install 'ipe)

Or:

1b. Download the insert-pair-edit.el project source:

git clone https://github.com/BriansEmacs/insert-pair-edit.el <path-to-download-dir>/ipe

And add the following to your .emacs file:

(add-to-list 'load-path "<path-to-download-dir>/ipe")
(add-to-list 'load-path "<path-to-download-dir>/ipe/modes")
  1. Add the following to your .emacs file:
(require 'ipe)
(global-set-key (kbd "M-(") 'ipe-insert-pair-edit)
  1. You may also want to enable the ipe "Pairs" menu:
(customize-save-variable 'ipe-menu-support-p t)
  1. You may also want to bind the other ipe commands:
(global-set-key (kbd "A-(") 'ipe-insert-pair-edit-update)
(global-set-key (kbd "H-(") 'ipe-insert-pair-edit-delete)
  1. You may also want to load the "example" modal PAIR mappings:
(require 'ipe-markdown-mode)
(require 'ipe-texinfo-mode)
(require 'ipe-html-mode)

Further Help

After installation:

From the keyboard:

M-x ipe-help
M-x ipe-help-info
M-x ipe-options

(If you have enabled ipe-menu-support-p) From the Emacs Edit menu:

Edit >
  Pairs >
    Options
    Info
    Help

About

GNU Emacs Lisp - insert-pair-edit.el - 'M-(' with interactive editing and modal pairs

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors