[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] master 65fc2fe 02/10: Added keyword for use-package
From: |
Ian Dunn |
Subject: |
[elpa] master 65fc2fe 02/10: Added keyword for use-package |
Date: |
Sun, 11 Feb 2018 21:15:40 -0500 (EST) |
branch: master
commit 65fc2fe634e767ed84601a8e10f005e2c834b847
Author: Ian Dunn <address@hidden>
Commit: Ian Dunn <address@hidden>
Added keyword for use-package
* hook-helpers-use-package.el: Adds support for hkhlp keyword in use-package
---
hook-helpers-use-package.el | 121 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 121 insertions(+)
diff --git a/hook-helpers-use-package.el b/hook-helpers-use-package.el
new file mode 100644
index 0000000..2cd7f3f
--- /dev/null
+++ b/hook-helpers-use-package.el
@@ -0,0 +1,121 @@
+;;; hook-helpers-use-package.el --- Support for use-package -*-
lexical-binding: t; -*-
+
+;; Copyright (c) 2017 Ian Dunn
+
+;; Author: Ian Dunn <address@hidden>
+;; Version: 1.0
+
+;; This file is NOT part of GNU Emacs.
+
+;; This program is free software; you can redistribute it and/or modify it
under
+;; the terms of the GNU General Public License as published by the Free
Software
+;; Foundation; either version 3, or (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful, but WITHOUT
+;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS
+;; FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+;; details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+;;; Commentary:
+
+;; Adds support for use-package using the :hkhlp keyword.
+
+;; Sets the current package's mode as a hook run by other hooks.
+
+;; Examples:
+
+;; (use-package outline
+;; :hkhlp
+;; (:cmd outline-minor-mode
+;; prog-mode
+;; text-mode))
+
+;; Adds a hook helper that runs outline-minor-mode, and adds it to
+;; prog-mode-hook and text-mode-hook.
+
+;; (use-package flyspell
+;; :hkhlp
+;; (text-mode-hook
+;; erc-mode-hook
+;; lui-mode-hook
+;; jabber-chat-mode-hook
+;; :cmd flyspell-prog-mode
+;; prog-mode))
+
+;; Creates two hook helpers: The first attaches flyspell-mode to
text-mode-hook,
+;; erc-mode-hook, lui-mode-hook, and jabber-chat-mode-hook. The second
attaches
+;; flyspell-prog-mode to prog-mode-hook.
+
+;;; Code:
+
+(require 'map)
+(require 'use-package nil t)
+
+(defun hkhlp-as-string (string-or-symbol)
+ "If STRING-OR-SYMBOL is already a string, return it. Otherwise
+convert it to a string and return that."
+ (if (stringp string-or-symbol) string-or-symbol
+ (symbol-name string-or-symbol)))
+
+(defun hkhlp-as-hook (string-or-symbol)
+ "If STRING-OR-SYMBOL ends in `-hook' (or its name does), return
+it as a symbol. Otherwise, return it as a symbol with `-hook'
+appended."
+ (let ((string (hkhlp-as-string string-or-symbol)))
+ (intern (if (string-match-p "-hook\\'" string) string
+ (concat string "-hook")))))
+
+(defun hkhlp-normalize-form (args)
+ (let (form
+ current-command
+ found-command)
+ (dolist (arg args form)
+ (pcase arg
+ (':cmd
+ (setq found-command t))
+ (_
+ (if found-command
+ (setq found-command nil
+ current-command arg)
+ (push (hkhlp-as-hook arg)
+ (alist-get current-command form))))))))
+
+(defun hkhlp-init-form (args)
+ (map-apply
+ (lambda (func hooks)
+ `(create-hook-helper ,func ()
+ :hooks (,@hooks)
+ (,func)))
+ (hkhlp-normalize-form args)))
+
+(cl-pushnew :hkhlp use-package-keywords)
+
+(defun use-package-normalize/:hkhlp (name _keyword args)
+ (cond
+ ((symbolp args) (list :cmd (use-package-as-mode name) args))
+ ((listp args)
+ (if (eq (car args) :cmd)
+ args
+ (apply
+ 'append
+ (list :cmd (use-package-as-mode name))
+ args)))))
+
+(defun use-package-handler/:hkhlp (name _keyword arg rest state)
+ (let ((forms (hkhlp-init-form arg))
+ (cmds (mapcar #'car (hkhlp-normalize-form arg))))
+ ;; Defer loading of this package until activated by the other hooks
+ (setq rest (use-package-plist-maybe-put rest :defer t))
+ ;; Add forms to :init
+ (setq rest (use-package-plist-append rest :init forms))
+ (use-package-process-keywords name
+ (use-package-sort-keywords rest)
+ ;; Add the commands to state for autoloading
+ (use-package-plist-append state :commands cmds))))
+
+(provide 'hook-helpers-use-package)
+
+;;; hook-helpers-use-package.el ends here
- [elpa] master updated (4c51a46 -> f058606), Ian Dunn, 2018/02/11
- [elpa] master f213b14 01/10: Backported copyright fix from ELPA, Ian Dunn, 2018/02/11
- [elpa] master 34dbcad 04/10: Updated use of when-let, Ian Dunn, 2018/02/11
- [elpa] master 65fc2fe 02/10: Added keyword for use-package,
Ian Dunn <=
- [elpa] master 58a5cfa 03/10: Created branch for ELPA releases., Ian Dunn, 2018/02/11
- [elpa] master c65004f 05/10: Updated copyright headers, Ian Dunn, 2018/02/11
- [elpa] master 28863f3 07/10: Merge commit '58a5cfa6d2884ac921153a285170b2c1ebec2a51', Ian Dunn, 2018/02/11
- [elpa] master 56e2ea3 08/10: Small mod to documentation, Ian Dunn, 2018/02/11
- [elpa] master d923d2e 06/10: Various updates to documentation, Ian Dunn, 2018/02/11
- [elpa] master f058606 10/10: Merge commit '7c6c2bf1b6eab973e61ff3cacfac47183279a898', Ian Dunn, 2018/02/11
- [elpa] master 7c6c2bf 09/10: Merge remote-tracking branch 'remotes/origin/master' into elpa, Ian Dunn, 2018/02/11