First commit.

This commit is contained in:
2022-01-09 21:19:46 +01:00
commit df36844dcc
107 changed files with 6565 additions and 0 deletions

51
lisp/lib/utils.el Normal file
View File

@@ -0,0 +1,51 @@
;;; utils.el --- miscellaneous support functions -*- lexical-binding: t; -*-
;;; Commentary:
;;; Code:
(defmacro try-eval (fn &optional finally)
"Safely evaluate expression FN and run FINALLY after."
(declare (debug t)
(indent 1))
`(let (retval)
(condition-case-unless-debug ex
(setq retval (progn ,fn))
('error
(setq retval (cons 'exception (list ex)))))
,@finally
retval))
(defun feature-p (feature)
"Check if FEATURE is available."
(or (featurep feature)
(when (functionp 'package-installed-p)
(package-installed-p feature))
(locate-library (symbol-name feature))))
(defun add-command-switch (handler &rest switch-list)
"Add HANDLER for SWITCH-LIST."
(dolist (switch switch-list)
(add-to-list 'command-switch-alist (cons switch handler))))
(defun add-auto-mode (mode &rest patterns)
"Use `MODE' for all given files matching `PATTERNS'."
(dolist (pattern patterns)
(add-to-list 'auto-mode-alist (cons pattern mode))))
(defun add-magic-mode (mode &rest patterns)
"Use `MODE' for all files containing header `PATTERNS'."
(dolist (pattern patterns)
(add-to-list 'magic-mode-alist (cons pattern mode))))
(defun add-interpreter-mode (mode &rest interpreters)
"Use `MODE' for all files with shebang `INTERPRETERS'."
(dolist (interpreter interpreters)
(add-to-list 'interpreter-mode-alist (cons interpreter mode))))
(provide 'lib/utils)
;;; utils.el ends here