Skip to content

conao3/leaf-convert.el

Repository files navigation

https://raw.githubusercontent.com/conao3/files/master/blob/headers/png/leaf-convert.el.png https://img.shields.io/github/license/conao3/leaf-convert.el.svg?style=flat-square https://img.shields.io/github/tag/conao3/leaf-convert.el.svg?style=flat-square https://github.com/conao3/leaf-convert.el/workflows/Main%20workflow/badge.svg https://img.shields.io/codacy/grade/62a36f4f04524d5e8c758440e8071c45.svg?logo=codacy&style=flat-square https://img.shields.io/badge/twitter-@conao__3-blue.svg?logo=twitter&style=flat-square https://img.shields.io/badge/chat-on_slack-blue.svg?logo=slack&style=flat-square

Table of Contents

Description

Convert from a plain Elisp to an expression using a leaf.

This is accomplished by not just converting use-package’s keywords, but by converting them once they have been expanded to a plain Elisp.

This may result in a simpler leaf expression, but if there is no corresponding keyword, most of it will be converted to a :config section.

Since the source is Elisp, it is possible to convert the leaf to Elisp once and then convert it to leaf again.

This can be used to convert miscellaneous settings in the :config section into leaf expressions with appropriate keywords. It is also possible to optimize settings that are not needed.

Currently, the following leaf keywords are supported for automatic conversion.

(leaf-available-keywords)
;;=> (:disabled
;;    :leaf-protect           ; <leaf system keyword>
;;    :load-path              ; supported!!
;;    :load-path*             ; supported!!
;;    :leaf-autoload          ; <leaf system keyword>
;;    :doc                    ; <leaf doc keyword>
;;    :req                    ; <leaf doc keyword>
;;    :tag                    ; <leaf doc keyword>
;;    :file                   ; <leaf doc keyword>
;;    :url                    ; <leaf doc keyword>
;;    :added                  ; <leaf doc keyword>
;;    :defun                  ; supported!!
;;    :defvar                 ; supported!!
;;    :leaf-defun             ; <leaf system keyword>
;;    :leaf-defvar            ; <leaf system keyword>
;;    :preface                ; supported!!
;;    :when                   ; supported!!
;;    :unless                 ; supported!!
;;    :if                     ; <convert to :when or :unless>
;;    :emacs<
;;    :emacs<=
;;    :emacs=
;;    :emacs>
;;    :emacs>=
;;    :package                ; <converted to :ensure>
;;    :ensure                 ; supported!!
;;    :feather                ; <no corresponding sexp>
;;    :straight
;;    :el-get
;;    :after                  ; supported!!
;;    :commands               ; supported!!
;;    :bind                   ; supported!!
;;    :bind*                  ; supported!!
;;    :mode                   ; supported!!
;;    :interpreter            ; supported!!
;;    :magic                  ; supported!!
;;    :magic-fallback         ; supported!!
;;    :hook                   ; supported!!
;;    :advice
;;    :advice-remove
;;    :init                   ; supported!!
;;    :pre-setq
;;    :pl-pre-setq
;;    :auth-pre-setq
;;    :custom                 ; supported!!
;;    :custom*                ; supported!!
;;    :pl-custom
;;    :auth-custom
;;    :custom-face            ; supported!!
;;    :require                ; supported!!
;;    :hydra
;;    :transient
;;    :combop
;;    :combo*
;;    :smartrep
;;    :smartrep*
;;    :chord                  ; supported!!
;;    :chord*                 ; supported!!
;;    :mode-hook
;;    :leaf-defer
;;    :config                 ; supported!!
;;    :global-minor-mode
;;    :diminish               ; supported!!
;;    :delight                ; supported!!
;;    :setq                   ; supported!!
;;    :setq-default           ; supoorted!!
;;    :pl-setq
;;    :auth-setq
;;    :pl-setq-default
;;    :auth-setq-default)

Install

leaf-convert is available via el-get.

(leaf leaf-convert :ensure t)

Usage

Pass any S-exps to leaf-convert to get a leaf expression.

(leaf-convert
 (defvar leaf-covert-variable)
 (bind-key "C-c x" 'my-ctrl-c-x-command)
 (bind-key "C-c x" 'my-ctrl-c-x-command some-other-mode-map)
 (bind-keys :map dired-mode-map
            ("o" . dired-omit-mode)
            ("a" . some-custom-dired-function)))
;;=> (leaf leaf-convert
;;     :defvar leaf-covert-variable
;;     :bind (("C-c x" . my-ctrl-c-x-command)
;;            (some-other-mode-map
;;             ("C-c x" . my-ctrl-c-x-command))
;;            (dired-mode-map
;;             ("o" . dired-omit-mode)
;;             ("a" . some-custom-dired-function))))

(leaf-convert
 (use-package edit-server
   :if window-system
   :init
   (add-hook 'after-init-hook 'server-start t)
   (add-hook 'after-init-hook 'edit-server-start t)))
;;=> (leaf edit-server
;;     :when window-system
;;     :hook ((after-init-hook . server-start)
;;            (after-init-hook . edit-server-start))
;;     :require t)

(leaf-convert
 (leaf markdown-mode
   ;;:mode ("\\.md\\'" . commonmark-gfm-mode)
   :config
   (with-eval-after-load 'markdown-mode
     (require 'org-table)
     (add-hook 'markdown-mode-hook 'orgtbl-mode)
     (unbind-key "`" gfm-mode-map)
     (visual-line-mode nil))))
;;=> (leaf markdown-mode
;;     :after t
;;     :hook ((markdown-mode-hook . orgtbl-mode))
;;     :require org-table
;;     :config
;;     (unbind-key "`" gfm-mode-map)
;;     (visual-line-mode nil))

Customize

Information

Community

All feedback and suggestions are welcome!

You can use github issues, but you can also use Slack if you want a more casual conversation.

Contribution

We welcome PR!

Require tools for testing

  • cask
    • install via brew
      brew install cask
              
    • manual install
      cd ~/
      hub clone cask/cask
      export PATH="$HOME/.cask/bin:$PATH"
              

Running test

Below operation flow is recommended.

make                              # Install git-hooks in local .git

git branch [feature-branch]       # Create branch named [feature-branch]
git checkout [feature-branch]     # Checkout branch named [feature-branch]

# <edit loop>
emacs leaf-convert.el             # Edit something you want

make test                         # Test leaf-convert via multi version Emacs
git commit -am "brabra"           # Commit (auto-run test before commit)
# </edit loop>

hub fork                          # Create fork at GitHub
git push [user] [feature-branch]  # Push feature-branch to your fork
hub pull-request                  # Create pull-request

Migration

License

General Public License Version 3 (GPLv3)
Copyright (c) Naoya Yamashita - https://conao3.com
https://github.com/conao3/leaf-convert.el/blob/master/LICENSE

Author

Contributors

About

Convert Elisp config sexp to leaf form

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published