[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 202/287: Allow hooks in themes; save settings on exit (Issue #234
From: |
Matthew Fidler |
Subject: |
[elpa] 202/287: Allow hooks in themes; save settings on exit (Issue #234) |
Date: |
Wed, 02 Jul 2014 14:45:59 +0000 |
mlf176f2 pushed a commit to branch externals/ergoemacs-mode
in repository elpa.
commit 61b2cd88b15e26efe1a1f63a15a07fed3f0c0cfd
Author: Matthew L. Fidler <address@hidden>
Date: Mon Jun 23 14:56:24 2014 -0500
Allow hooks in themes; save settings on exit (Issue #234)
---
ergoemacs-functions.el | 14 ++++++++++++++
ergoemacs-macros.el | 7 +++++++
ergoemacs-theme-engine.el | 25 ++++++++++++++++++++++---
ergoemacs-themes.el | 10 ++++++++--
4 files changed, 51 insertions(+), 5 deletions(-)
diff --git a/ergoemacs-functions.el b/ergoemacs-functions.el
index a4fd3fa..4b3278b 100644
--- a/ergoemacs-functions.el
+++ b/ergoemacs-functions.el
@@ -105,6 +105,20 @@
nil)))
t)))
+(defun ergoemacs-exit-customize-save-customized ()
+ "Call `customize-save-customized' on exit emacs.
+
+If an error occurs, display the error, and sit for 2 seconds before exiting"
+ (cond
+ ((not (or custom-file user-init-file))
+ (message "Not saving; \"emacs -q\" would overwrite customizations")
+ (sit-for 1))
+ ((and (null custom-file) init-file-had-error)
+ (message "Cannot save customizations; init file was not fully loaded")
+ (sit-for 1))
+ (t
+ (customize-save-customized))))
+
(defun ergoemacs-ctl-c (&optional arg)
"Ergoemacs C-c key."
(interactive "P")
diff --git a/ergoemacs-macros.el b/ergoemacs-macros.el
index 03ef001..c1d8d06 100644
--- a/ergoemacs-macros.el
+++ b/ergoemacs-macros.el
@@ -141,6 +141,7 @@ Uses `ergoemacs-theme-component--parse-keys-and-body' and
- `global-unset-key' is converted to `ergoemacs-define-key' with keymap equal
to `global-map' and function definition is `nil'
- `global-reset-key' is converted `ergoemacs-define-key'
- `setq' and `set' is converted to `ergoemacs-set'
+- `add-hook' and `remove-hook' is converted to `ergoemacs-set'
- Mode initialization like (delete-selection-mode 1)
or (delete-selection) is converted to
`ergoemacs-set'
@@ -167,6 +168,12 @@ Uses `ergoemacs-theme-component--parse-keys-and-body' and
((ignore-errors (eq (nth 0 elt) 'set))
;; Currently doesn't support (setq a b c d ), but it should.
`(ergoemacs-set ,(nth 1 elt) '(lambda() ,(nth 2 elt))))
+ ((ignore-errors (eq (nth 0 elt) 'add-hook))
+ `(ergoemacs-set ,(nth 1 elt) ,(nth 2 elt)
+ (list t ,(nth 3 elt) ,(nth 4 elt))))
+ ((ignore-errors (eq (nth 0 elt) 'remove-hook))
+ `(ergoemacs-set ,(nth 1 elt) ,(nth 2 elt)
+ (list nil nil ,(nth 3 elt))))
((ignore-errors (eq (nth 0 elt) 'setq))
(let ((tmp-elt elt)
(ret '()))
diff --git a/ergoemacs-theme-engine.el b/ergoemacs-theme-engine.el
index cba8d7e..94b743b 100644
--- a/ergoemacs-theme-engine.el
+++ b/ergoemacs-theme-engine.el
@@ -1099,6 +1099,17 @@ ergoemacs-get-keymaps-for-hook OBJ HOOK")
((assq (nth 0 init) ergoemacs-applied-inits)
;; Already applied, Do nothing for now.
)
+ ((nth 2 init)
+ ;; Hook
+ (let ((add-hook-p (nth 0 (nth 2 init)))
+ (append-p (nth 1 (nth 2 init)))
+ (local-p (nth 2 (nth 2 init))))
+ (if add-hook-p
+ (funcall 'add-hook (nth 0 init) (nth 1 init) append-p local-p)
+ (funcall 'remove-hook (nth 0 init) (nth 1 init) local-p))
+ (push (list (nth 0 init) (nth 1 init)
+ (list (not add-hook-p) append-p local-p))
+ ergoemacs-applied-inits)))
((and (string-match-p "-mode$" (symbol-name (nth 0 init)))
(ignore-errors (commandp (nth 0 init) t)))
(push (list (nth 0 init) (if (symbol-value (nth 0 init)) 1 -1))
@@ -1116,8 +1127,16 @@ ergoemacs-get-keymaps-for-hook OBJ HOOK")
This assumes the variables are stored in `ergoemacs-applied-inits'"
(dolist (init ergoemacs-applied-inits)
(let ((var (nth 0 init))
- (val (nth 1 init)))
+ (val (nth 1 init))
+ (hook (nth 2 init)))
(cond
+ (hook
+ (let ((add-hook-p (nth 0 hook))
+ (append-p (nth 1 hook))
+ (local-p (nth 2 hook)))
+ (if add-hook-p
+ (funcall 'add-hook (nth 0 init) (nth 1 init) append-p local-p)
+ (funcall 'remove-hook (nth 0 init) (nth 1 init) local-p))))
((and (string-match-p "-mode$" (symbol-name var))
(ignore-errors (commandp var t)))
(funcall var val))
@@ -1565,12 +1584,12 @@ The actual keymap changes are included in
`ergoemacs-emulation-mode-map-alist'."
ergoemacs-theme-component-maps--curr-component
map key def))))
-(defun ergoemacs-set (symbol newval)
+(defun ergoemacs-set (symbol newval &optional hook)
(if (not (ergoemacs-theme-component-maps-p
ergoemacs-theme-component-maps--curr-component))
(warn "`ergoemacs-set' is meant to be called in a theme definition.")
;; ergoemacs-set definition.
(with-slots (init) ergoemacs-theme-component-maps--curr-component
- (push (list symbol newval) init)
+ (push (list symbol newval hook) init)
(oset ergoemacs-theme-component-maps--curr-component
init init))))
diff --git a/ergoemacs-themes.el b/ergoemacs-themes.el
index 6ddd5b8..c1782c2 100644
--- a/ergoemacs-themes.el
+++ b/ergoemacs-themes.el
@@ -72,6 +72,10 @@
;; (cua-mode . ,cua-global-keymap))))
)
+(ergoemacs-theme-component save-options-on-exit ()
+ "Save emacs options on exit"
+ (add-hook 'kill-emacs-hook 'ergoemacs-exit-customize-save-customized))
+
;;; Fixed components
(ergoemacs-theme-component standard-fixed ()
"Standard Fixed Shortcuts"
@@ -984,7 +988,8 @@
helm-remaps
multiple-cursors-remaps
quit
- apps-swap)
+ apps-swap
+ save-options-on-exit)
:optional-off '(guru no-backspace search-reg
ergoemacs-banish-shift)
:options-menu '(("Menu/Apps Key" (apps apps-apps apps-punctuation))
@@ -1029,7 +1034,8 @@
helm-remaps
multiple-cursors-remaps
quit
- apps-swap)
+ apps-swap
+ save-options-on-exit)
:optional-off '(guru no-backspace search-reg
ergoemacs-banish-shift)
:options-menu '(("Menu/Apps Key" (apps apps-apps apps-punctuation))
- [elpa] 132/287: Be more careful when redefining maps., (continued)
- [elpa] 132/287: Be more careful when redefining maps., Matthew Fidler, 2014/07/02
- [elpa] 129/287: Fix compiler warnings for ergoemacs-unbind.el, Matthew Fidler, 2014/07/02
- [elpa] 140/287: Fix Byte Compile Warnings, Matthew Fidler, 2014/07/02
- [elpa] 117/287: Take out compiler errors from ergoemacs-test, Matthew Fidler, 2014/07/02
- [elpa] 93/287: Add ergoemacs-shortcut-emulation-mode-map-alist, Matthew Fidler, 2014/07/02
- [elpa] 119/287: Fix byte-compile warnings for ergoemacs-macros.el, Matthew Fidler, 2014/07/02
- [elpa] 67/287: Completely use the object, Matthew Fidler, 2014/07/02
- [elpa] 134/287: Finalize tests; Passes on windows, Matthew Fidler, 2014/07/02
- [elpa] 101/287: Fix Cask setup?, Matthew Fidler, 2014/07/02
- [elpa] 133/287: Remove byte compiled load warning, Matthew Fidler, 2014/07/02
- [elpa] 202/287: Allow hooks in themes; save settings on exit (Issue #234),
Matthew Fidler <=