Git Product home page Git Product logo

emacs-refactor's Introduction

emacs-refactor

Build Status Coverage Status MELPA MELPA stable

Emacs Refactor (EMR) is a framework for providing language-specific refactoring in Emacs. It includes refactoring commands for a variety of languages, including elisp itself!

Summary

To use EMR when editing, simply move point to an expression and M-x emr-show-refactor-menu.

Example

EMR ships with many refactoring commands, and pull requests for extensions are welcome. See Extension for details on extending EMR to other language modes. It's easy (honest!).

Installation

emr is available on MELPA. This is the easiest way to install.

If you haven't set up MELPA, you'll need to add the following to your init.el

;;; Initialize packages.

(require 'package)
(add-to-list 'package-archives '("melpa" . "http://melpa.milkbox.net/packages/"))
(package-initialize)
(unless package-archive-contents (package-refresh-contents))

Once MELPA is configured:

  1. M-x package-install emr

  2. Configure your init.el:

(define-key prog-mode-map (kbd "M-RET") 'emr-show-refactor-menu)

Language support

Most EMR commands are context-sensitive and are available through the refactor menu. Some actions affect the whole buffer and are available in the menu bar.

General

These commands are available for all programming languages.

The following context-sensitive refactoring commands are available:

  • comment region
  • uncomment region

C

The following context-sensitive refactoring commands are available:

  • tidy includes

The following buffer-wide actions are available:

  • insert include

Refactoring support for C is a work in progress. Contributions are welcome.

Lisps

These commands are available to all Lisp dialects, including Clojure, Elisp and Common Lisp.

The following context-sensitive refactoring commands are available:

  • comment form
  • uncomment block

Elisp

The following context-sensitive refactoring commands are available:

  • delete unused definition
  • delete unused let binding form
  • eval and replace
  • extract autoload
  • extract constant
  • extract function
  • extract to let
  • extract variable
  • implement function
  • inline function
  • inline let variable
  • inline variable
  • insert autoload directive
  • tidy autoloads

The following buffer-wide actions are available:

  • find unused definitions

JavaScript

JavaScript refactoring support requires js2 refactor.

The following refactoring commands are available:

  • extract function
  • extract method
  • extract variable
  • add parameter
  • local variable to instance variable
  • log region

Ruby

Ruby refactoring support requires ruby refactor.

The following refactoring commands are available:

  • extract function
  • extract variable
  • extract constant
  • add parameter
  • extract to let

Scheme

The following refactoring commands are available:

  • extract function
  • extract variable

Extension

Use the emr-declare-command function to declare a refactoring action. The action will automatically become available in the refactoring popup menu.

This function supports predicate expressions, allowing the options displayed to be context-sensitive.

As an example, here is the declaration for a refactoring command that ships with EMR:

(emr-declare-command 'emr-el-extract-constant
  :title "constant"
  :description "defconst"
  :modes 'emacs-lisp-mode
  :predicate (lambda ()
               (not (or (emr-el:looking-at-definition?)
                        (emr-el:looking-at-let-binding-symbol?)))))

This wires the emr-el-extract-constant function to be displayed in emacs-lisp-mode, provided point is not looking at an Elisp definition or let-binding form.

If your favourite language mode already offers refactoring commands, it is simple to wire them up with EMR using this interface.

emacs-refactor's People

Contributors

wilfred avatar yangyingchao avatar adrieankhisbe avatar articuluxe avatar tacticiankerala avatar hparker avatar tarsius avatar

Watchers

James Cloos avatar Eric Crosson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.