-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms-barb.el
executable file
·88 lines (66 loc) · 2.75 KB
/
forms-barb.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
;;; forms-barb.el --- More hooks for `forms-mode' -*- lexical-binding: t; -*-
;; Copyright (C) 2016 Aaron Harris
;; Author: Aaron Harris <[email protected]>
;; Keywords: data forms
;; Dependencies: `forms', `validate' (optional)
;; Advised functions from other packages:
;; forms: `forms-jump-record'
;; 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 of the License, 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:
;; This module adds more hooks for use in `forms-mode'. Note that
;; these are injected using advice, contrary to the usual admonition
;; against advising other packages' functions.
;;
;; The hooks added are as follows:
;;
;; `forms-barb-change-record-hook':
;;
;; This hook is run whenever the current record changes.
;;
;; To enable these hooks, just require `forms-barb'.
;;; Code:
(require 'forms)
;;;; Hook Variables
;;;;===============
(defcustom forms-barb-change-record-hook nil
"Hook run after changing records in `forms-mode'."
:group 'forms
:type 'hook)
;;;; Wrapper Macros
;;=================
(defmacro forms-barb-with-single-record-change (&rest body)
"Eval BODY; run `forms-barb-change-record-hook' only once.
Suppress `forms-barb-change-record-hook' within BODY, and run the
hook once after BODY exits. The hook is run even in the event of
an error or nonlocal exit."
`(unwind-protect
(let ((forms-barb-change-record-hook nil))
,@body)
(run-hooks 'forms-barb-change-record-hook)))
;;;; Hook Insertion
;;;;===============
(defun forms-barb--change-record-hook-advice (&rest args)
"Run `forms-barb-change-record-hook'.
The ARGS are ignored. The reason for including them is so that
this function can be used as advice. By default this function is
installed as :after advice on `forms-jump-record'."
(when (require 'validate nil :noerror)
(validate-variable 'forms-barb-change-record-hook))
(run-hooks 'forms-barb-change-record-hook))
(advice-add 'forms-jump-record :after #'forms-barb--change-record-hook-advice)
;;;; Unloading
;;;;==========
(defun forms-barb-unload-function ()
"Remove all hooks added by `forms-barb' module."
(advice-remove 'forms-jump-record #'forms-barb--change-record-hook-advice))
(provide 'forms-barb)
;;; forms-barb.el ends here