-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacros.el
29 lines (26 loc) · 1.16 KB
/
macros.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
;;; macros.el --- jds core macros -*- lexical-binding: t -*-
;;https://emacs.stackexchange.com/questions/54500/how-to-add-a-locally-override-the-message-function
;;;###autoload
(defmacro jds~with-temp-advice (fn-orig where fn-advice &rest body)
"Execute BODY with advice temporarily enabled."
`(let ((fn-advice-var ,fn-advice))
(unwind-protect
(progn
(advice-add ,fn-orig ,where fn-advice-var)
,@body)
(advice-remove ,fn-orig fn-advice-var))))
;; https://emacs.stackexchange.com/questions/3323/is-there-any-way-to-run-a-hook-function-only-once
;;;###autoload
(defmacro jds~add-hook-run-once (hook function &optional append local)
"Like add-hook, but remove the hook after it is called"
(let ((sym (make-symbol "#once")))
`(progn
(defun ,sym ()
(remove-hook ,hook ',sym ,local)
(funcall ,function))
(add-hook ,hook ',sym ,append ,local))))
;; https://emacs.stackexchange.com/questions/7653/elisp-code-to-check-for-internet-connection
;;;###autoload
(defun jds~internet-up-p (&optional host)
(= 0 (call-process "ping" nil nil nil "-c" "1" "-W" "1"
(if host host "www.google.com"))))