Giter Club home page Giter Club logo

elfmt's Introduction

elfmt

This is (yet another) code formatter for Emacs Lisp.

Features

  • Won’t format lines that end in ; nofmt
  • Focuses on the placement of lists and (mostly) ignores atoms
  • Tries to break at fill-column, but lines may exceed this number due to inline comments, long literals, trailing sequences of closed parens, or postprocessing (see elfmt-autojoin-1 for example)
  • Prefers “modern” Elisp (old-style backquotes will cause it to halt)

‘Screenshot’

(defun elfmt--mend-line-p ()
  "Whether to join the current line with the next.
This uses heuristics that disregard the contributions of trailing
comments, closing parentheses, and backslash abbreviations like
\\n, so lines may end up longer than `fill-column'."
  ;; precond: point is on an sexp
  (let ((sexp-str (thing-at-point 'sexp)))
    (and
     sexp-str
     (string-match "\n" sexp-str)  ; sexp crosses to the next line
     (setq sexp-str (format "%S" (car (read-from-string sexp-str))))
     (< (length sexp-str) (- fill-column (current-column))) ; mostly fits
     (< (cl-count ?\( sexp-str) 5) ; visual complexity (i.e. nested parens)
     (save-excursion
       (and
        (not (elfmt--trailing-syntax))     ; not inside a string/comment
        (eq (forward-line 1) 0)            ; and the next line, if any:
        (not (looking-at "[[:space:]]*;")) ; ...is not a comment
        (not (elfmt--nofmt-line-p)))))))

Usage

  • Type M-x elfmt to format the current buffer
  • Type M-x elfmt-sexp to format the current sexp
  • Type M-x elfmt-mode to automatically format the buffer on save
  • Type M-x elfmt-global-mode to enable elfmt-mode everywhere

Alternatives

elfmt's People

Contributors

riscy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

ideasman42

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.