Code Monkey home page Code Monkey logo

el-indent's Introduction

el-indent

An indent-line-function configurator

About

el-indent allows to quckly build an indent-line-function for a major mode. It may be helpful if you'd like to customize the way code is indented in mode you're using or if you're writing support for a new mode.

Installation

Add el-indent.el to you .emacs load-path

Usage

To use with a major-mode add (require 'el-indent)

(NOTE: adding to MELPA soon, so these instructions will change.)

How to use ready configurations ?

Load feature and add hook to your mode, e.g. for lisp-mode:

(require 'el-indent/lisp)
(add-hook 'lisp-mode-hook 'el-indent-set-lisp)

Naming convention for other modes stays the same. For xml-mode will be: el-indent/xml and el-indent-set-xml etc.

How to configure your own indent function ?

To configure indent-line-function you need to provide list of strings that affects indentation.

Example - let's say we deal with mode in which code is nested by parenthesis. So ( nests +1 and ) nests -1, we configure rules this way:

(list
    (list "\(" "\)")
    (list 1    -1)
    (list t    t))

In first list you group strings (in form of regexps) that affect indentation. In second you say which way it affects indentation and in third list you say what rules should be followed after that string in code occured. If it's same rules then you may just put t. otherwise you should put object with differnt rules that would be used afterwards.

Sometimes in first group you'll put string that change the rules of indentation but actually doesn't indent the code. For example beginning of comments might be the case, then just put 0 in second list.

Finally you'll pack rules into functions for direct use:

(setq el-indent-exp-mymode
    (el-indent-build-exps
        (list
            (list "\(" "\)")
            (list 1    -1)
            (list t    t))))

; el-indent-build-exps translates your rules into expressions that are
evaluated when actually indenting.

(defun el-indent-mymode ()
    (el-indent-line (lambda () el-indent-exp-mymode)))

; In place of lambda you may put your custom function that will return different
; expressions according to place in which indent is calculated

(defun el-indent-set-mymode ()
    (setq indent-line-function 'el-indent-mymode))

That's it, configuration may be used as described in How to use ready configurations.

Indent rules are generally more complicated than in this example. You can learn more from configurations that are included with this project.

el-indent's People

Contributors

medikoo avatar jasonm23 avatar

Watchers

 avatar James Cloos avatar  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.