Created
July 3, 2018 17:59
-
-
Save melioratus/0757c2fec4dde09ba0f8bbc064b914ed to your computer and use it in GitHub Desktop.
Emacs Lisp script skeleton
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
":"; exec emacs --quick --script "$0" -- "$@" # -*- mode: emacs-lisp; lexical-binding: t; -*- | |
(let ((greeting "Hello %s!") | |
options-done | |
names) | |
(pop argv) ; Remove the -- separator | |
(while argv | |
(let ((option (pop argv))) | |
(cond | |
(options-done (push option names)) | |
;; Don't process options after "--" | |
((string= option "--") (setq options-done t)) | |
((string= option "--greeting") | |
(setq greeting (pop argv))) | |
;; --greeting=Foo | |
((string-match "\\`--greeting=\\(\\(?:.\\|\n\\)*\\)\\'" option) | |
(setq greeting (match-string 1 option))) | |
((string-prefix-p "--" option) | |
(message "Unknown option: %s" option) | |
(kill-emacs 1)) | |
(t (push option names))) | |
(unless (> (length greeting) 0) | |
(message "Missing argument for --greeting!") | |
(kill-emacs 1)))) | |
(unless names | |
(message "Missing names!") | |
(kill-emacs 1)) | |
(dolist (name (nreverse names)) | |
(message greeting name)) | |
(kill-emacs 0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment