• This repository has been archived on 04/Feb/2021
  • Stars
    star
    409
  • Rank 105,709 (Top 3 %)
  • Language
    Emacs Lisp
  • License
    GNU General Publi...
  • Created about 8 years ago
  • Updated almost 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Parinfer for Emacs :)

Parinfer Mode

https://melpa.org/packages/parinfer-badge.svg https://stable.melpa.org/packages/parinfer-badge.svg

images/logo.png

Deprecated

This project is no longer maintained.I have no success for a fast enough implementation in Emacs Lisp.

Fortunately, there’s a parinfer-rust-mode!

Demo

images/demo.gif

Table of contents

What Is Parinfer

Parinfer is a proof-of-concept editor mode for Lisp programming languages. It will infer some changes to keep Parens and Indentation inline with one another. Parinfer consists of two modes:

Indent Mode
Indent Mode gives you full control of indentation, while Parinfer corrects parens.
Paren Mode
Paren Mode gives you full control of parens, while Parinfer corrects indentation.

To learn more about Parinfer, please take a look at its home page.

And the parinfer-mode is the implementation on Emacs with parinfer-elisp.

Installation

Parinfer is available on MELPA(and MELPA Stable) now, I recommend to install with use-package.

Add following code to your .emacs or init.el.

(use-package parinfer
  :ensure t
  :bind
  (("C-," . parinfer-toggle-mode))
  :init
  (progn
    (setq parinfer-extensions
          '(defaults       ; should be included.
            pretty-parens  ; different paren styles for different modes.
            evil           ; If you use Evil.
            lispy          ; If you use Lispy. With this extension, you should install Lispy and do not enable lispy-mode directly.
            paredit        ; Introduce some paredit commands.
            smart-tab      ; C-b & C-f jump positions and smart shift with tab & S-tab.
            smart-yank))   ; Yank behavior depend on mode.
    (add-hook 'clojure-mode-hook #'parinfer-mode)
    (add-hook 'emacs-lisp-mode-hook #'parinfer-mode)
    (add-hook 'common-lisp-mode-hook #'parinfer-mode)
    (add-hook 'scheme-mode-hook #'parinfer-mode)
    (add-hook 'lisp-mode-hook #'parinfer-mode)))

Indent And Paren Modes

Toggle Indent Mode and Paren Mode with command parinfer-toggle-mode.

Avoid unexpect buffer changes.

Whenever you switch to Indent Mode, parinfer-mode will correct all parens of current buffer.

After opening a file, the parinfer-mode enable Indent Mode if it won’t make any changes. Otherwise, Paren Mode will be enabled, you can switch to Indent Mode manually later.

Alternatively, you can use parinfer-diff command to see how will Indent Mode modify the buffer with Ediff.

images/diff_demo.gif

And there are some keybindings in Ediff:

KeyDescription
qQuit diff.
bB->A in Ediff, this can apply change to your origin code.
raRestore A in Ediff, this can revert change.
nMove to next difference.
pMove to previous difference.

Also, There’s a command parinfer-auto-fix to fix wrong indentation for whole buffer. (Only works with balanced parens)

Configurations

parinfer-auto-switch-indent-mode

(setq parinfer-auto-switch-indent-mode nil)  ;; default

t for enable, Parinfer will auto switch to Indent Mode whenever parens are balance in Paren Mode.

parinfer-auto-switch-indent-mode-when-closing

(setq parinfer-auto-switch-indent-mode-when-closing nil)  ;; default

t for enable, Parinfer will auto switch to Indent Mode when the inserted close parens (), ], }) balance the parens of current sexp.

parinfer-delay-invoke-threshold

(setq parinfer-delay-invoke-threshold 6000)  ;; default

When the length of text for processing is longer than this, Parinfer will process text after a idle delay instead of process immediately.

parinfer-delay-invoke-idle

(setq parinfer-delay-invoke-idle 0.3)  ;; default

The idle seconds before Parinfer processing text on large sexp.

parinfer-extensions

(setq parinfer-extensions '(defaults pretty-parens smart-yank))

The extensions that will be enabled. The list could contain followings:

ExtensionFunction
defaultsShould be enabled, basic compatibility
pretty-parensUse dim style for Indent Mode, rainbow delimiters for Paren Mode
smart-yankYank will preserve indentation in Indent Mode, will preserve parens in Paren Mode
smart-tabC-f & C-b on empty line will goto next/previous import indentation.
pareditIntroduce some paredit commands from paredit-mode.
lispyIntegration with Lispy.
evilIntegration with Evil.
oneExperimental on fuzz Indent Mode and Paren Mode. Not recommanded.

parinfer-lighters

(setq parinfer-lighters '(" Parinfer:Indent" . "Parinfer:Paren"))

Troubleshooting

If Parinfer seems to be indenting incorrectly, ensure indent-tabs-mode is set to nil via (setq-default indent-tabs-mode nil). While Parinfer’s theoretical model is able to correctly handle indentation with tabs, parinfer-mode can currently only handle indentation using spaces.

Credits

shaunlebron
Create Parinfer.
oakmac
Bring Parinfer to Emacs with parinfer-elisp.
tumashu
Help me a lot in writing this plugin.
purcell & syohex
Advice and Tips for writing emacs plugin

Contribution

Please open an issue if there’s any bug or suggestion, and PR is welcomed!

License

parinferlib.el from parinfer-elisp, is licensed under the ISC.

Rest part licensed under the GPLv3.

More Repositories

1

emacs-rime

RIME ㄓ in Emacs
Emacs Lisp
400
star
2

holdem

A Lightweight Texas Hold'em Poker Game
Clojure
102
star
3

org-html-themify

Themify org-mode HTML export with installed color theme.
CSS
70
star
4

meomacs

A simple Emacs configuration with modal editing
Emacs Lisp
26
star
5

rainbow-fart.el

Rainbow Fart in Emacs, playing audio when you type keywords.
Emacs Lisp
16
star
6

joker-theme

A minimal theme for emacs.
Emacs Lisp
13
star
7

dotfiles

personal dotfiles
Shell
13
star
8

tunnel

一个纯Clojure的聊天程序
Clojure
11
star
9

zprint.el

zprint in Emacs
Emacs Lisp
10
star
10

mcss

Macro your CSS
Clojure
9
star
11

inf-iex

Interaction with IEx session
Emacs Lisp
9
star
12

casease

ease for cases
Emacs Lisp
8
star
13

printed-theme

A high contrast Emacs theme to against sunlight
Emacs Lisp
7
star
14

storybook-theme

A light emacs theme for daily coding
Emacs Lisp
7
star
15

shadow-cljs-with-react-native-note

[DEPRECATED]A note for how to use shadow-cljs with react-native
6
star
16

carbon-theme

A dark theme for Emacs
Emacs Lisp
6
star
17

py-echarts

Python
4
star
18

awesome

re-natal & react-native-navigation
Clojure
4
star
19

little-demo

Clojure
3
star
20

elemental-theme

A clean and soft dark theme
Emacs Lisp
3
star
21

rime_double_pinyin_dvorak

適用於德沃夏克的佈局的雙拼輸入法
3
star
22

shiftless.el

Insert uppercase without shift.
Emacs Lisp
3
star
23

borsh-clj

A pure Clojure/Script implementation for Borsh
Clojure
2
star
24

xmodmap-dvp

Xmodmap configuration for Dvorak Programmer
2
star
25

HiccupMacroParser

An experimental React wrapper that transform hiccup during macroexpand.
Clojure
2
star
26

tmp

mv file to /tmp/.trash instead of rm :(
Shell
2
star
27

parinfer-mode-demo

minimal setup for emacs parinfer-mode(just for testing)
Emacs Lisp
2
star
28

fullstack-explore

Clojure
1
star
29

paperlike-theme

A theme for E-ink monitor
Emacs Lisp
1
star
30

dogKeys

personal keyboard setup
1
star
31

shadow-cljs-reload-reproduce

HTML
1
star
32

division

Chain-style stylesheet generator for CLJSRN and CSS for Clojure.
Clojure
1
star