mirror of
https://github.com/masscollaborationlabs/emacs.git
synced 2025-07-08 13:19:36 +00:00
Added :mode and :interpreter keywords
This commit is contained in:
parent
0736be8e67
commit
bdf1505f44
1 changed files with 97 additions and 46 deletions
|
@ -75,8 +75,17 @@
|
||||||
;; on your system. So remember to keep `:init' activities to only those that
|
;; on your system. So remember to keep `:init' activities to only those that
|
||||||
;; would succeed either way.
|
;; would succeed either way.
|
||||||
;;
|
;;
|
||||||
;; If you aren't using `:commands' or `:bind' (which implies `:commands'), you
|
;; Similar to `:bind', you can use `:mode' and `:interpreter' to establish a
|
||||||
;; can still defer loading with the `:defer' keyword:
|
;; deferred binding within `auto-mode-alist' and `auto-interpreter-alist'.
|
||||||
|
;; The specifier to either keyword can be a single cons or a list:
|
||||||
|
;;
|
||||||
|
;; (use-package python-mode
|
||||||
|
;; :mode ("\\.py$" . python-mode)
|
||||||
|
;; :interpreter ("python" . python-mode))
|
||||||
|
;;
|
||||||
|
;; If you aren't using `:commands', `:bind', `:mode', or `:interpreter' (all
|
||||||
|
;; of which imply `:commands'), you can still defer loading with the `:defer'
|
||||||
|
;; keyword:
|
||||||
;;
|
;;
|
||||||
;; (use-package ace-jump-mode
|
;; (use-package ace-jump-mode
|
||||||
;; :defer t
|
;; :defer t
|
||||||
|
@ -243,6 +252,8 @@
|
||||||
;; (cons (plist-get entry :symbol)
|
;; (cons (plist-get entry :symbol)
|
||||||
;; `(status "installed" recipe ,entry)))
|
;; `(status "installed" recipe ,entry)))
|
||||||
;; el-get-sources)))
|
;; el-get-sources)))
|
||||||
|
|
||||||
|
;;; Code:
|
||||||
|
|
||||||
(require 'bind-key)
|
(require 'bind-key)
|
||||||
|
|
||||||
|
@ -250,8 +261,6 @@
|
||||||
"A use-package declaration for simplifying your .emacs"
|
"A use-package declaration for simplifying your .emacs"
|
||||||
:group 'startup)
|
:group 'startup)
|
||||||
|
|
||||||
;;;_ , Create use-package macro, to simplify customizations
|
|
||||||
|
|
||||||
(eval-when-compile
|
(eval-when-compile
|
||||||
(require 'cl))
|
(require 'cl))
|
||||||
|
|
||||||
|
@ -278,13 +287,35 @@
|
||||||
|
|
||||||
(put 'with-elapsed-timer 'lisp-indent-function 1)
|
(put 'with-elapsed-timer 'lisp-indent-function 1)
|
||||||
|
|
||||||
|
(defun use-package-discover-el-get-type (args)
|
||||||
|
(let* ((pkg-name (plist-get args :name))
|
||||||
|
(git-config (expand-file-name
|
||||||
|
(concat pkg-name "/.git/config")
|
||||||
|
user-site-lisp-directory)))
|
||||||
|
|
||||||
|
(catch 'found
|
||||||
|
;; Look for a readable .git/config with at least one defined remote.
|
||||||
|
(if (file-readable-p git-config)
|
||||||
|
(with-temp-buffer
|
||||||
|
(insert-file-contents-literally git-config)
|
||||||
|
(while (re-search-forward "\\[remote" nil t)
|
||||||
|
(if (re-search-forward "url = \\(.+\\)"
|
||||||
|
(save-excursion
|
||||||
|
(re-search-forward "\\[remote" nil t)
|
||||||
|
(point)) t)
|
||||||
|
(nconc args (list :type 'git
|
||||||
|
:url (match-string 1))))))))
|
||||||
|
args))
|
||||||
|
|
||||||
(defmacro use-package (name &rest args)
|
(defmacro use-package (name &rest args)
|
||||||
(let* ((commands (plist-get args :commands))
|
(let* ((commands (plist-get args :commands))
|
||||||
(init-body (plist-get args :init))
|
(init-body (plist-get args :init))
|
||||||
(config-body (plist-get args :config))
|
(config-body (plist-get args :config))
|
||||||
(diminish-var (plist-get args :diminish))
|
(diminish-var (plist-get args :diminish))
|
||||||
(defines (plist-get args :defines))
|
(defines (plist-get args :defines))
|
||||||
(keybindings (plist-get args :bind))
|
(keybindings )
|
||||||
|
(mode-alist )
|
||||||
|
(interpreter-alist )
|
||||||
(predicate (plist-get args :if))
|
(predicate (plist-get args :if))
|
||||||
(pkg-load-path (plist-get args :load-path))
|
(pkg-load-path (plist-get args :load-path))
|
||||||
(defines-eval (if (null defines)
|
(defines-eval (if (null defines)
|
||||||
|
@ -302,32 +333,50 @@
|
||||||
(name-string (if (stringp name) name
|
(name-string (if (stringp name) name
|
||||||
(symbol-name name))))
|
(symbol-name name))))
|
||||||
|
|
||||||
(if diminish-var
|
(unless (plist-get args :disabled)
|
||||||
(setq config-body
|
(if diminish-var
|
||||||
`(progn
|
(setq config-body
|
||||||
,config-body
|
`(progn
|
||||||
(ignore-errors
|
,config-body
|
||||||
,@(if (listp diminish-var)
|
(ignore-errors
|
||||||
(mapcar (lambda (var) `(diminish (quote ,var)))
|
,@(if (listp diminish-var)
|
||||||
diminish-var)
|
(mapcar (lambda (var) `(diminish (quote ,var)))
|
||||||
`((diminish (quote ,diminish-var))))))))
|
diminish-var)
|
||||||
|
`((diminish (quote ,diminish-var))))))))
|
||||||
|
|
||||||
(when keybindings
|
|
||||||
(if (and commands (symbolp commands))
|
(if (and commands (symbolp commands))
|
||||||
(setq commands (list commands)))
|
(setq commands (list commands)))
|
||||||
(setq init-body
|
|
||||||
`(progn
|
|
||||||
,init-body
|
|
||||||
,@(mapcar #'(lambda (binding)
|
|
||||||
(push (cdr binding) commands)
|
|
||||||
`(bind-key ,(car binding)
|
|
||||||
(quote ,(cdr binding))))
|
|
||||||
(if (and (consp keybindings)
|
|
||||||
(stringp (car keybindings)))
|
|
||||||
(list keybindings)
|
|
||||||
keybindings)))))
|
|
||||||
|
|
||||||
(unless (plist-get args :disabled)
|
(flet ((init-for-commands
|
||||||
|
(func sym-or-list)
|
||||||
|
(let ((cons-list (if (and (consp sym-or-list)
|
||||||
|
(stringp (car sym-or-list)))
|
||||||
|
(list sym-or-list)
|
||||||
|
sym-or-list)))
|
||||||
|
(if cons-list
|
||||||
|
(setq init-body
|
||||||
|
`(progn
|
||||||
|
,init-body
|
||||||
|
,@(mapcar #'(lambda (elem)
|
||||||
|
(push (cdr elem) commands)
|
||||||
|
(funcall func elem))
|
||||||
|
cons-list)))))))
|
||||||
|
|
||||||
|
(init-for-commands #'(lambda (binding)
|
||||||
|
`(bind-key ,(car binding)
|
||||||
|
(quote ,(cdr binding))))
|
||||||
|
(plist-get args :bind))
|
||||||
|
|
||||||
|
(init-for-commands #'(lambda (mode)
|
||||||
|
`(add-to-list 'auto-mode-alist
|
||||||
|
(quote ,mode)))
|
||||||
|
(plist-get args :mode))
|
||||||
|
|
||||||
|
(init-for-commands #'(lambda (interpreter)
|
||||||
|
`(add-to-list 'interpreter-mode-alist
|
||||||
|
(quote ,interpreter)))
|
||||||
|
(plist-get args :interpreter)))
|
||||||
|
|
||||||
`(progn
|
`(progn
|
||||||
,@(mapcar
|
,@(mapcar
|
||||||
#'(lambda (path)
|
#'(lambda (path)
|
||||||
|
@ -345,29 +394,31 @@
|
||||||
`(load ,name t)
|
`(load ,name t)
|
||||||
`(require ',name nil t)))
|
`(require ',name nil t)))
|
||||||
|
|
||||||
,(when (and (boundp 'el-get-sources)
|
,(when (boundp 'el-get-sources)
|
||||||
(plist-get args :type))
|
|
||||||
(setq args
|
|
||||||
(mapcar #'(lambda (arg)
|
|
||||||
(cond
|
|
||||||
((eq arg :config)
|
|
||||||
:after)
|
|
||||||
((eq arg :requires)
|
|
||||||
:depends)
|
|
||||||
(t
|
|
||||||
arg)))
|
|
||||||
args))
|
|
||||||
(unless (plist-get args :name)
|
(unless (plist-get args :name)
|
||||||
(nconc args (list :name (if (stringp name)
|
(nconc args (list :name name-string)))
|
||||||
name (symbol-name name)))))
|
|
||||||
(nconc args (list :symbol (if (stringp name)
|
(unless (plist-get args :type)
|
||||||
(intern name) name)))
|
(setq args (use-package-discover-el-get-type args)))
|
||||||
`(push (quote ,args) el-get-sources))
|
|
||||||
|
(when (plist-get args :type)
|
||||||
|
(setq args
|
||||||
|
(mapcar #'(lambda (arg)
|
||||||
|
(cond
|
||||||
|
((eq arg :config)
|
||||||
|
:after)
|
||||||
|
((eq arg :requires)
|
||||||
|
:depends)
|
||||||
|
(t
|
||||||
|
arg)))
|
||||||
|
args))
|
||||||
|
|
||||||
|
(nconc args (list :symbol (intern name-string)))
|
||||||
|
|
||||||
|
`(push (quote ,args) el-get-sources)))
|
||||||
|
|
||||||
,(if (or commands (plist-get args :defer))
|
,(if (or commands (plist-get args :defer))
|
||||||
(let (form)
|
(let (form)
|
||||||
(unless (listp commands)
|
|
||||||
(setq commands (list commands)))
|
|
||||||
(mapc #'(lambda (command)
|
(mapc #'(lambda (command)
|
||||||
(push `(autoload (function ,command)
|
(push `(autoload (function ,command)
|
||||||
,name-string nil t) form))
|
,name-string nil t) form))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue