QiangF / insert-pair-edit.el

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Insert Pair Edit


insert-pair-edit

This project defines a GNU Emacs package, insert-pair-edit. This package supplies commands that are a more feature rich alternative to the standard M-( Emacs keybinding, (insert-parentheses).


Overview

The insert-pair-edit 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 insert-pair-edit package is the Emacs interactive command insert-pair-edit. When executed, this command will prompt the user to enter a MNEMONIC identifying a (customizable) PAIR via the Emacs minibuffer.

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

ipe-edit-mode Commands

After adding the OPEN and CLOSE overlays into the buffer, the insert-pair-edit command starts ipe-edit-mode to enter the Insert Pair Edit (ipe) minor 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 PAIR to be inserted on-the-fly.
  • Change the 'lexical units' used by the movement commands.
  • 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.
  • Search for (and edit) other PAIRs.
  • Operate on multiple PAIRs at once.
  • Escape characters between the OPEN and CLOSE strings.

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:

  • TexInfo
  • HTML
  • Markdown

Pairs Menu

Insert Pair Edit Menu

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

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

Download the insert-pair-edit project:

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

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"))
(require 'insert-pair-edit)
(global-set-key (kbd "M-(") 'insert-pair-edit)

Further Help

After installation: from the Emacs Edit menu:

Edit >
  Pairs >
    Info
    Help

From the keyboard:

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

About

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


Languages

Language:Emacs Lisp 99.5%Language:Makefile 0.5%