First commit.
This commit is contained in:
17
lisp/lib/apps.el
Normal file
17
lisp/lib/apps.el
Normal file
@@ -0,0 +1,17 @@
|
||||
;;; apps.el --- Support functions for applications -*- lexical-binding: t; -*-
|
||||
;;; Commentary:
|
||||
;;; Code:
|
||||
|
||||
|
||||
(defun osx-app-installed-p (app)
|
||||
"Return t if APP is installed."
|
||||
(when (eq system-type 'darwin)
|
||||
(let ((lsregister
|
||||
"/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister"))
|
||||
(and (file-executable-p lsregister)
|
||||
(not (string-equal "" (shell-command-to-string
|
||||
(concat lsregister " -dump|grep " app))))))))
|
||||
|
||||
|
||||
(provide 'lib/apps)
|
||||
;;; apps.el ends here
|
28
lisp/lib/bootstrap.el
Normal file
28
lisp/lib/bootstrap.el
Normal file
@@ -0,0 +1,28 @@
|
||||
;;; bootstrap.el --- Helpers for bootstrapping Emacs. -*- lexical-binding: t; -*-
|
||||
;;; Commentary:
|
||||
|
||||
;; Stolen from Alexx Ott, https://github.com/alexott/dotemacs
|
||||
|
||||
;;; Code:
|
||||
|
||||
(declare-function 'path-join "path")
|
||||
|
||||
|
||||
(defun load-all-files-from-dir (dir)
|
||||
"Load all Emacs Lisp files in DIR."
|
||||
(dolist (f (directory-files dir))
|
||||
(when (and
|
||||
(file-directory-p (path-join dir f))
|
||||
(not (string= "." f))
|
||||
(not (string= ".." f)))
|
||||
(load-all-files-from-dir (path-join dir f)))
|
||||
(when (and
|
||||
(not (file-directory-p (path-join dir f)))
|
||||
(not (string= "bootstrapper.el" f))
|
||||
(not (string= ".#" (substring f 0 2)))
|
||||
(string= ".el" (substring f (- (length f) 3))))
|
||||
(load-file (path-join dir f)))))
|
||||
|
||||
|
||||
(provide 'lib/bootstrap)
|
||||
;;; bootstrap.el ends here
|
13
lisp/lib/env.el
Normal file
13
lisp/lib/env.el
Normal file
@@ -0,0 +1,13 @@
|
||||
;;; env.el --- support functions for working with environment variables -*- lexical-binding: t; -*-
|
||||
;;; Commentary:
|
||||
;;; Code:
|
||||
|
||||
(defun getenv-or (env value)
|
||||
"Fetch the value of ENV or, if it is not set, return VALUE."
|
||||
(if (getenv env)
|
||||
(getenv env)
|
||||
value))
|
||||
|
||||
|
||||
(provide 'lib/env)
|
||||
;;; env.el ends here
|
46
lisp/lib/list.el
Normal file
46
lisp/lib/list.el
Normal file
@@ -0,0 +1,46 @@
|
||||
;;; list.el --- Emacs list utilities -*- lexical-binding: t; -*-
|
||||
;;; Commentary:
|
||||
;;; Code:
|
||||
|
||||
(defun add-many-to-list (the-list &rest entries)
|
||||
"Add to THE-LIST any specified ENTRIES."
|
||||
(dolist (entry entries)
|
||||
(add-to-list the-list entry))
|
||||
(eval the-list))
|
||||
|
||||
|
||||
(defmacro user/filter-form (form list)
|
||||
"Return list with elements for which FORM are non-nil in LIST."
|
||||
(declare (debug (form form)))
|
||||
(let ((r (make-symbol "result")))
|
||||
`(let (,r)
|
||||
(--each ,list (when ,form (!cons it ,r)))
|
||||
(nreverse ,r))))
|
||||
|
||||
|
||||
(defun user/filter-list (condp list)
|
||||
"Return list with elements for which CONDP are non-nil in LIST."
|
||||
(delq nil
|
||||
(mapcar (lambda (x) (and (funcall condp x) x)) list)))
|
||||
|
||||
|
||||
(defun user/toggle-element (list element)
|
||||
"Return LIST with ELEMENT removed if present or added if not present."
|
||||
(if (member element list)
|
||||
(user/filter-form (not (eq element it)) list)
|
||||
(cons element list)))
|
||||
|
||||
|
||||
(defun user/all-asscs (asslist query)
|
||||
"A list of all values in ASSLIST corresponding to QUERY (like rassoc)."
|
||||
(cond
|
||||
((null asslist) nil)
|
||||
(t
|
||||
(if (equal (cdr (car asslist)) query)
|
||||
(cons (car (car asslist))
|
||||
(user/all-asscs (cdr asslist) query))
|
||||
(user/all-asscs (cdr asslist) query)))))
|
||||
|
||||
|
||||
(provide 'lib/list)
|
||||
;;; list.el ends here
|
35
lisp/lib/net.el
Normal file
35
lisp/lib/net.el
Normal file
@@ -0,0 +1,35 @@
|
||||
;;; net.el --- Initialize Emacs networking -*- lexical-binding: t; -*-
|
||||
;;; Commentary:
|
||||
;;; Code:
|
||||
|
||||
(require 'lib/path)
|
||||
(require 'lib/utils)
|
||||
|
||||
|
||||
(defconst *user-url-cache-directory*
|
||||
(path-join *user-cache-directory* "url")
|
||||
"Path to user's url data store.")
|
||||
(defconst *user-nsm-data-directory*
|
||||
(path-join *user-data-directory* "nsm")
|
||||
"Path to user's Wanderlust data store.")
|
||||
|
||||
|
||||
(with-eval-after-load 'url
|
||||
(setq
|
||||
;; Set up cache directory.
|
||||
url-configuration-directory *user-url-cache-directory*
|
||||
url-cookie-file (path-join *user-url-cache-directory* "cookies")
|
||||
url-history-file (path-join *user-url-cache-directory* "history")
|
||||
;; Automatically cache all documents.
|
||||
url-automatic-caching t))
|
||||
|
||||
(make-directory *user-nsm-data-directory* t)
|
||||
(with-eval-after-load 'nsm
|
||||
(setq
|
||||
;; Location of security manager settings.
|
||||
nsm-settings-file
|
||||
(path-join *user-nsm-data-directory* "network-security.data")))
|
||||
|
||||
|
||||
(provide 'lib/net)
|
||||
;;; net.el ends here
|
97
lisp/lib/packaging.el
Normal file
97
lisp/lib/packaging.el
Normal file
@@ -0,0 +1,97 @@
|
||||
;;; packaging.el --- initialize package management -*- lexical-binding: t; -*-
|
||||
;;; Commentary:
|
||||
;;; Code:
|
||||
|
||||
(require 'lib/net)
|
||||
|
||||
|
||||
(with-feature 'package
|
||||
(setq
|
||||
;; Configure GNU/Emacs package repositories.
|
||||
package-archives
|
||||
'(("GNU ELPA" . "https://elpa.gnu.org/packages/")
|
||||
("MELPA Stable" . "http://stable.melpa.org/packages/")
|
||||
("MELPA" . "http://melpa.org/packages/")
|
||||
("org" . "http://orgmode.org/elpa/"))
|
||||
;; ("marmalade" . "http://marmalade-repo.org/packages/"))
|
||||
;; Prefer MELPA Stable over GNU over MELPA.
|
||||
package-archive-priorities
|
||||
'(("MELPA Stable" . 20)
|
||||
("GNU ELPA" . 15)
|
||||
("MELPA" . 10)
|
||||
("org" . 5))))
|
||||
;; ("marmalade" . 0))))
|
||||
|
||||
|
||||
;; Bootstrap `use-package'.
|
||||
(package-initialize)
|
||||
(unless (and (package-installed-p 'quelpa-use-package) (package-installed-p 'validate))
|
||||
(package-refresh-contents)
|
||||
(package-install 'quelpa-use-package)
|
||||
(package-install 'validate))
|
||||
|
||||
(eval-when-compile
|
||||
;; Load use-package.
|
||||
(require 'quelpa-use-package)
|
||||
(require 'validate))
|
||||
|
||||
(use-package use-package
|
||||
:config
|
||||
(validate-setq
|
||||
;; Hooks are verbatim.
|
||||
use-package-hook-name-suffix nil)
|
||||
|
||||
(use-package quelpa-use-package
|
||||
:config
|
||||
(validate-setq
|
||||
;; Only use quelpa for custom packages.
|
||||
quelpa-checkout-melpa-p nil
|
||||
;; Only load quelpa on demand.
|
||||
quelpa-use-package-inhibit-loading-quelpa t)
|
||||
|
||||
;; Protect quelpa recipes when forcing ensure.
|
||||
(quelpa-use-package-activate-advice))
|
||||
|
||||
;; Support using keys from init-bindings by using (:key <group> <function>).
|
||||
(push :bind-wrap (cdr (member :bind use-package-keywords)))
|
||||
(push :bind*-wrap (cdr (member :bind* use-package-keywords)))
|
||||
(defun use-package-normalize-bind-wrap (name keyword args)
|
||||
(let ((arg args)
|
||||
args*)
|
||||
(while arg
|
||||
(let ((x (car arg)))
|
||||
(cond
|
||||
;; ((:key :category :function) . COMMAND)
|
||||
((and (consp x)
|
||||
(consp (car x))
|
||||
(equal (caar x) :key))
|
||||
(setq args* (nconc args*
|
||||
(list (cons (apply 'user/get-key (cdar x))
|
||||
(cdar arg)))))
|
||||
(setq arg (cdr arg)))
|
||||
;; (KEY . COMMAND)
|
||||
((and (consp x)
|
||||
(or (stringp (car x))
|
||||
(vectorp (car x)))
|
||||
(or (use-package-recognize-function (cdr x) t #'stringp)))
|
||||
(setq args* (nconc args* (list x)))
|
||||
(setq arg (cdr arg)))
|
||||
;; Nested list.
|
||||
((listp x)
|
||||
(setq args*
|
||||
(nconc args* (use-package-normalize/:bind-wrap name keyword x)))
|
||||
(setq arg (cdr arg)))
|
||||
(t
|
||||
(setq args* (nconc args* (list x)))
|
||||
(setq arg (cdr arg))))))
|
||||
(use-package-normalize/:bind name keyword args*)))
|
||||
(defalias 'use-package-normalize/:bind-wrap 'use-package-normalize-bind-wrap)
|
||||
(defalias 'use-package-normalize/:bind*-wrap 'use-package-normalize-bind-wrap)
|
||||
(defun use-package-handler/:bind-wrap (name keyword arg rest state)
|
||||
(use-package-handler/:bind name keyword arg rest state))
|
||||
(defun use-package-handler/:bind*-wrap (name keyword arg rest state)
|
||||
(use-package-handler/:bind name keyword arg rest state 'bind-keys*)))
|
||||
|
||||
|
||||
(provide 'lib/packaging)
|
||||
;;; packaging.el ends here
|
26
lisp/lib/path.el
Normal file
26
lisp/lib/path.el
Normal file
@@ -0,0 +1,26 @@
|
||||
;;; path.el --- support functions for working with paths -*- lexical-binding: t; -*-
|
||||
;;; Commentary:
|
||||
;;; Code:
|
||||
|
||||
(defun path-abs-buffer ()
|
||||
"Get the current buffer absolute path."
|
||||
(file-truename (or (buffer-file-name) default-directory)))
|
||||
|
||||
|
||||
(defun path-dirname (path)
|
||||
"Get the parent directory of PATH."
|
||||
(file-name-directory (directory-file-name path)))
|
||||
|
||||
|
||||
(defun path-join (root &rest dirs)
|
||||
"Join paths together starting at ROOT and proceeding with DIRS.
|
||||
Ex: (path-join \"/tmp\" \"a\" \"b\" \"c\") => /tmp/a/b/c"
|
||||
(if (not dirs)
|
||||
root
|
||||
(apply 'path-join
|
||||
(expand-file-name (car dirs) root)
|
||||
(cdr dirs))))
|
||||
|
||||
|
||||
(provide 'lib/path)
|
||||
;;; path.el ends here
|
11
lisp/lib/pkg-config.el
Normal file
11
lisp/lib/pkg-config.el
Normal file
@@ -0,0 +1,11 @@
|
||||
;;; pkg-config.el --- pkg-config support -*- lexical-binding: t; -*-
|
||||
;;; Commentary:
|
||||
;;; Code:
|
||||
|
||||
(defun pkg-config-has-p (package)
|
||||
"Check if PACKAGE is available."
|
||||
(eq (call-process-shell-command "pkg-config" nil nil nil "--exists" package) 0))
|
||||
|
||||
|
||||
(provide 'lib/pkg-config)
|
||||
;;; pkg-config.el ends here
|
11
lisp/lib/string.el
Normal file
11
lisp/lib/string.el
Normal file
@@ -0,0 +1,11 @@
|
||||
;;; string.el --- Emacs string functions. -*- lexical-binding: t; -*-
|
||||
;;; Commentary:
|
||||
;;; Code:
|
||||
|
||||
(defmacro with-face (str &rest properties)
|
||||
"Print STR using PROPERTIES."
|
||||
`(propertize ,str 'face (list ,@properties)))
|
||||
|
||||
|
||||
(provide 'lib/string)
|
||||
;;; string.el ends here
|
51
lisp/lib/utils.el
Normal file
51
lisp/lib/utils.el
Normal 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
|
34
lisp/lib/with.el
Normal file
34
lisp/lib/with.el
Normal file
@@ -0,0 +1,34 @@
|
||||
;;; with.el --- conditional eval wrappers -*- lexical-binding: t; -*-
|
||||
;;; Commentary:
|
||||
;;; Code:
|
||||
|
||||
(defmacro with-feature (feature &rest body)
|
||||
"If FEATURE is available, load it and evaluate BODY."
|
||||
(declare (indent defun))
|
||||
`(when (require ,feature nil :noerror)
|
||||
,@body))
|
||||
|
||||
|
||||
(defmacro with-function (function &rest body)
|
||||
"If FUNCTION is available, evaluate BODY."
|
||||
(declare (indent defun))
|
||||
`(when (functionp ,function)
|
||||
,@body))
|
||||
|
||||
|
||||
(defmacro with-executable (executable &rest body)
|
||||
"If EXECUTABLE is available in path, evaluate BODY."
|
||||
(declare (indent defun))
|
||||
`(when (executable-find (symbol-name ,executable))
|
||||
,@body))
|
||||
|
||||
|
||||
(defmacro with-any-executable (executables &rest body)
|
||||
"If any of EXECUTABLES are available in the path, evaluate BODY."
|
||||
(declare (indent defun))
|
||||
`(when (some (lambda (x) (executable-find (symbol-name x))) ,executables)
|
||||
,@body))
|
||||
|
||||
|
||||
(provide 'lib/with)
|
||||
;;; with.el ends here
|
Reference in New Issue
Block a user