diff options
Diffstat (limited to 'lisp/acdw.el')
-rw-r--r-- | lisp/acdw.el | 48 |
1 files changed, 31 insertions, 17 deletions
diff --git a/lisp/acdw.el b/lisp/acdw.el index f972d08..444f249 100644 --- a/lisp/acdw.el +++ b/lisp/acdw.el | |||
@@ -45,23 +45,6 @@ Convenience wrapper around `define-key'." | |||
45 | map) | 45 | map) |
46 | key def))))) | 46 | key def))))) |
47 | 47 | ||
48 | (defmacro setq-local-hook (hook &rest args) | ||
49 | "Run `setq-local' on ARGS when running HOOK." | ||
50 | (declare (indent 1)) | ||
51 | (let ((fn (intern (format "%s-setq-local" hook)))) | ||
52 | (when (and (fboundp fn) | ||
53 | (functionp fn)) | ||
54 | (setq args (append (function-get fn 'setq-local-hook-settings) args))) | ||
55 | (unless (and (< 0 (length args)) | ||
56 | (zerop (mod (length args) 2))) | ||
57 | (user-error "Wrong number of arguments: %S" (length args))) | ||
58 | `(progn | ||
59 | (defun ,fn () | ||
60 | ,(format "Set local variables after `%s'." hook) | ||
61 | (setq-local ,@args)) | ||
62 | (function-put ',fn 'setq-local-hook-settings ',args) | ||
63 | (add-hook ',hook #',fn)))) | ||
64 | |||
65 | (unless (fboundp 'ensure-list) | 48 | (unless (fboundp 'ensure-list) |
66 | ;; Just in case we're using an old version of Emacs. | 49 | ;; Just in case we're using an old version of Emacs. |
67 | (defun ensure-list (object) | 50 | (defun ensure-list (object) |
@@ -89,3 +72,34 @@ form (FUNCTION &optional DEPTH LOCAL)." | |||
89 | (dolist (hook (ensure-list hooks)) | 72 | (dolist (hook (ensure-list hooks)) |
90 | (dolist (fn functions) | 73 | (dolist (fn functions) |
91 | (apply #'add-hook hook (ensure-list fn))))) | 74 | (apply #'add-hook hook (ensure-list fn))))) |
75 | |||
76 | ;;; Convenience macros | ||
77 | |||
78 | (defmacro setq-local-hook (hook &rest args) | ||
79 | "Run `setq-local' on ARGS when running HOOK." | ||
80 | (declare (indent 1)) | ||
81 | (let ((fn (intern (format "%s-setq-local" hook)))) | ||
82 | (when (and (fboundp fn) | ||
83 | (functionp fn)) | ||
84 | (setq args (append (function-get fn 'setq-local-hook-settings) args))) | ||
85 | (unless (and (< 0 (length args)) | ||
86 | (zerop (mod (length args) 2))) | ||
87 | (user-error "Wrong number of arguments: %S" (length args))) | ||
88 | `(progn | ||
89 | (defun ,fn () | ||
90 | ,(format "Set local variables after `%s'." hook) | ||
91 | (setq-local ,@args)) | ||
92 | (function-put ',fn 'setq-local-hook-settings ',args) | ||
93 | (add-hook ',hook #',fn)))) | ||
94 | |||
95 | (defmacro with-message (message &rest body) | ||
96 | "Execute BODY, with MESSAGE. | ||
97 | If body executes without errors, MESSAGE...Done will be displayed." | ||
98 | (declare (indent 1)) | ||
99 | (let ((msg (gensym))) | ||
100 | `(let ((,msg ,message)) | ||
101 | (condition-case e | ||
102 | (progn (message "%s..." ,msg) | ||
103 | ,@body) | ||
104 | (:success (message "%s...done" ,msg)) | ||
105 | (t (signal (car e) (cdr e))))))) | ||