spdx.el provides SPDX license header and copyright insertion.
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))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: MITIf 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.
spdx-insert-spdxinserts a SPDX license header.spdx-insert-spdx-onlyinserts a SPDX license header without comments.spdx-insert-spdx-identifier-onlyinserts a SPDX identifier only.spdx-insert-copyrightinserts a copyright header.spdx-insert-spdx-copyrightinserts a SPDX license and copyright header.
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.
spdxexpands to a SPDX license header.spdxoexpands to a SPDX license header without comments.spdxiexpands to a SPDX identifier only.cpyexpands to a copyright header.spdxcpyexpands to a SPDX license and copyright header.
spdx-copyright-holder('autoby default)spdx-copyright-sign('asciiby default)spdx-project-detection('autoby default)spdx-ignore-deprecated(nilby default)
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: MITIf you use lice-el, you may also need to hide the massive headers. Take a look
at the builtin elide-head package.
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 creates LICENSE file using GitHub API. It's NOT used to insert license header.
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 copyrightspdx.el inserts with ;; with one space following.
;; Copyright (C) 2020 spdx.el Authors
;; M-x spdx-insert-copyrightIf you found the spdx-spdx-identifiers is out of date, don't hesitate to raise a PR.
-
spdx-insert-spdx-copyrightfailed to work intext-mode.Now, it works. Even though
text-modehasn't defined comment syntax,spdx.elwill ask user to define it.