Skip to content

condy0919/spdx.el

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spdx.el

Latest

spdx.el provides SPDX license header and copyright insertion.

Installation

Please install spdx from melpa.

Put spdx.el in your Emacs system. Add the following to your .emacs:

(require 'spdx)
(define-key prog-mode-map (kbd "C-c i l") #'spdx-insert-spdx)

Or use use-package with straight.el:

(use-package spdx
  :ensure t
  :straight (:host github :repo "condy0919/spdx.el")
  :bind (:map prog-mode-map
         ("C-c i l" . spdx-insert-spdx))
  :custom
  (spdx-copyright-holder 'auto)
  (spdx-project-detection 'auto))

Usage

you can press C-c i l to trigger spdx-insert-spdx

Or manually run M-x spdx-insert-spdx

Then, spdx.el will ask you to select a license. It's done by completing-read.

After that, the license header will be written. An example follows.

;; SPDX-License-Identifier: MIT

If you use tempo, add spdx-tempo-setup to the mode specific hook. Type spdx then M-x tempo-expand-if-complete, you will get the same result as above.

It's recommanded to combine tempo-expand-if-complete with hippie-expand:

(use-package hippie-exp
  :ensure nil
  :bind ([remap dabbrev-expand] . hippie-expand)
  :config
  (defun try-expand-tempo (_old)
    (require 'tempo)
    (tempo-expand-if-complete))
  :custom
  (hippie-expand-try-functions-list '(try-expand-tempo
                                      try-expand-dabbrev
                                      try-expand-dabbrev-all-buffers
                                      try-expand-dabbrev-from-kill
                                      try-complete-file-name-partially
                                      try-complete-file-name
                                      try-expand-all-abbrevs
                                      try-expand-list
                                      try-expand-line
                                      try-complete-lisp-symbol-partially
                                      try-complete-lisp-symbol)))

Let M-/ rule the world.

Available functions

  • spdx-insert-spdx inserts a SPDX license header.
  • spdx-insert-spdx-only inserts a SPDX license header without comments.
  • spdx-insert-spdx-identifier-only inserts a SPDX identifier only.
  • spdx-insert-copyright inserts a copyright header.
  • spdx-insert-spdx-copyrightinserts a SPDX license and copyright header.

Available tempo snippets

The following tempo snippets can be expanded via M-x tempo-expand-if-complete. Make sure spdx-tempo-setup is called to access these tempo snippets.

  • spdx expands to a SPDX license header.
  • spdxo expands to a SPDX license header without comments.
  • spdxi expands to a SPDX identifier only.
  • cpy expands to a copyright header.
  • spdxcpy expands to a SPDX license and copyright header.

Customization

  • spdx-copyright-holder ('auto by default)
  • spdx-copyright-sign ('ascii by default)
  • spdx-project-detection ('auto by default)
  • spdx-ignore-deprecated (nil by default)

Other projects

lice-el

lice-el provides license template management and file header insertion.

The content of license is inserted while spdx.el only inserts two lines.

;; Copyright (C)  spdx.el Authors
;; SPDX-License-Identifier: MIT

If you use lice-el, you may also need to hide the massive headers. Take a look at the builtin elide-head package.

license-snippets

license-snippets is a license snippet collection of yasnippet.

spdx.el uses the builtin completion system tempo without dependencies of third party libraries.

license-template

license-template creates LICENSE file using GitHub API. It's NOT used to insert license header.

copyright

Emacs has a builtin copyright package providing copyright header insertion. However, the copyright elisp-mode has only one leading semicolon.

;Copyright (C) 2020 by Me

;; M-x copyright

spdx.el inserts with ;; with one space following.

;; Copyright (C) 2020  spdx.el Authors

;; M-x spdx-insert-copyright

Contribution

If you found the spdx-spdx-identifiers is out of date, don't hesitate to raise a PR.

FAQ

  1. spdx-insert-spdx-copyright failed to work in text-mode.

    Now, it works. Even though text-mode hasn't defined comment syntax, spdx.el will ask user to define it.