Skip to content

KarimAziev/autofix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

About

Automatically fix common code style issues in Elisp.

Table of Contents

Requirements

NameVersion
Emacs27.1
package-lint0.17

Installation

With use-package and straight.el

(use-package autofix
  :straight (autofix
             :repo "KarimAziev/autofix"
             :type git
             :host github)
  :bind ((:map autofix-multi-completion-map
               ("C-<return>" . autofix-throw-done)
               ("C-M-j" . autofix-throw-done)))
  :commands (autofix
             autofix-footer
             autofix-remove-unused-declarations
             autofix-header
             autofix-autoloads
             autofix-commentary
             autofix-code-comment
             autofix-header-first-line
             autofix-sharpquotes
             autofix-scan-extract-all-docs
             autofix-annotate-buffer
             autofix-url
             autofix-copyright
             autofix-license
             autofix-add-fbound
             autofix-keywords
             autofix-header-body-comment
             autofix-package-requires
             autofix-version
             autofix-update-version
             autofix-author))

Manual installation

Download the source code and put it wherever you like, e.g. into ~/.emacs.d/autofix/

git clone https://github.com/KarimAziev/autofix.git ~/.emacs.d/autofix/

Add the downloaded directory to the load path:

(add-to-list 'load-path "~/.emacs.d/autofix/")
(require 'autofix)

Usage

Minor mode

autofix-mode

Runs autofix on file save when this mode is turned on.

Commands

autofix

Apply all functions from autofix-functions. Default code fixes includes auto adding auto load comments before all interactive commands and removing unused (declare-function …) forms. Default comments fixes includes fixes for file headers, package headers, footer etc. File headers fixes can be customized via autofix-header-functions.

autofix-footer

Add of fix file footer e.g. in the file myfile.el it will add or replace:

(provide 'myfile)
;;; myfile.el ends here

autofix-remove-unused-declarations

Check usage and remove unused declarations:

(declare-function unused-function)

autofix-header

Apply fixes for header comments.

You can add or remove commands by customizing the variable autofix-header-functions.

CommandDescription
autofix-header-first-lineFix or create the first comment line in the header
autofix-copyrightPrompt and fix or make new copyright
autofix-authorAdd or fix author
autofix-urlAdd of fix URL
autofix-versionAdd or fix package version
autofix-keywordsAdd or fix package keywords
autofix-package-requiresAdd or fix package requires section
autofix-header-body-commentAdd comment body (M-x autofix-comment-section-body)
autofix-commentaryAdd Commentary section in current buffer if none
autofix-code-commentAdd Code comment to the end of header block
autofix-licenseAdd SPDX short-form identifier (M-x customize-variable autofix-spdx-license)

autofix-autoloads

Add autoload comments before commands in buffer, that doesn’t look like private.

autofix-sharpquotes

Add a sharpquote (=#’=) when quoting function names. For example, such code:

(mapcar 'car '(a b c d))

Transforms to:

(mapcar #'car '(a b c d))

You can customize rules by customing a variable autofix-sharpquote-symbols-spec.

autofix-scan-extract-all-docs

Return string with all docs in all buffer. If called interactively also copies it.

autofix-annotate-buffer

Add annotations in header comment section, e.g.:

;;; Commands

;; M-x `autofix'
;;      Apply all functions from `autofix-functions'.
;;      Default code fixes includes auto adding auto load comments before all
;;      interactive commands and removing unused (declare-function ...) forms.
;;      Default comments fixes includes fixes for file headers,
;;      package headers, footer etc.
;;      File headers fixes can be customized via `autofix-header-functions'.

;; M-x `autofix-footer'
;;      Add of fix file footer (provide ='filename) with comment ends here.

autofix-add-fbound

Wrap undefined function call in fbound.

Customization

autofix-ignored-file-patterns

List of file name bases to ignore.

autofix-user-fullname

User email to add in header section.

autofix-user-email

User email to add in header section. Can be string, variable or function. Function will be called without args and should return string.

autofix-functions

List of functions to apply with command autofix.

autofix-spdx-license

Default spdx short-form identifier.

autofix-sharpquote-symbols-spec

Alist of symbols and required sharpquote positions. Each element is a cons which car is either symbol or list of symbols, which cdr is a position of children element, that should be sharquoted.

autofix-comment-section-body

Static text for adding in header comment section. It doesn’t includes dynamic variables such author, year etc.