-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgridlock-fix.el
162 lines (137 loc) · 5.6 KB
/
gridlock-fix.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
;;; gridlock-fix.el --- Gridlock for fix
;; Copyright (C) 2018-2019 Dan Harms (dharms)
;; Author: Dan Harms <enniomore@icloud.com>
;; Created: Thursday, March 22, 2018
;; Version: 1.0
;; Modified Time-stamp: <2019-07-26 15:59:47 dan.harms>
;; Modified by: Dan Harms
;; Keywords: tools
;; URL: https://github.com/articuluxe/gridlock.git
;; Package-Requires: ((emacs "24.4"))
;; 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:
;; Defines a minor mode for gridlock with fix messages.
;;
;;; Code:
(require 'gridlock)
(defvar gridlock-fix-init-hook '()
"Hooks run after setting up `gridlock-fix-mode' but before inspecting buffer.")
(defvar gridlock-fix-metadata nil
"The metadata for this fix buffer.")
(defcustom gridlock-fix-preferred-display-schemes
'("popup" "pos-tip" "quick-peek" "echo")
"Preferred display schemes for `gridlock-fix-mode'.
Display schemes will be loaded in this order."
:group 'gridlock-group)
(defvar gridlock-fix-metadata-file "fix4.2.hash"
"Data file to persist tag metadata.")
(defun gridlock-fix--reset-metadata ()
"Reset the metadata associated with the current buffer in `gridlock-fix-mode'."
;(clrhash gridlock-fix-metadata)
)
(defun gridlock-fix--get-buffer-metadata ()
"Initialize the buffer's metadata for `gridlock-fix-mode'."
(if (featurep 'hashtable-print-readable)
(let ((file (locate-file gridlock-fix-metadata-file load-path)))
(if (and file (file-exists-p file))
(gridlock-fix-metadata-read-file file)
(error "No metadata! (%s does not exist)"
(or file gridlock-fix-metadata-file))))
(error
"Gridlock Fix Metadata cannot be read in (hash tables are not serializable in this version of Emacs)")))
(defun gridlock-fix-metadata-read-file (file)
"Read the value of `gridlock-fix-metadata' from FILE."
(with-temp-buffer
(insert-file-contents file)
(setq gridlock-fix-metadata (read (current-buffer)))))
;; field class override for fix
(defclass gridlock-fix-field (gridlock-field)
((tag :initarg :tag
:initform 0
:type (integer 0 *)
:documentation "The fix tag's numeric value."))
"A fix field of interest.")
;; silence compiler warning
(eval-when-compile (defvar gridlock-fix-field))
(gridlock--defmethod-macro gridlock-fix-get-tag ((field gridlock-fix-field))
"Get the fix tag number associated with FIELD."
(oref field tag))
(defmacro gridlock-fix-create-field-macro (&rest args)
"Create a `gridlock-fix-field' with ARGS, parameterized on Emacs version.
This is necessary as constructor arguments changed in Emacs 25."
(if (version< emacs-version "25")
`(apply gridlock-fix-field "gridlock-fix" ,@args)
`(apply gridlock-fix-field ,@args)))
(defun gridlock-fix-create-field-compat (args)
"Create a `gridlock-fix-field' according to ARGS."
(gridlock-fix-create-field-macro args))
(defun gridlock-fix-create-field (&rest args)
"Create a gridlock-fix-field instance with associated values ARGS."
(let* ((field (gridlock-fix-create-field-compat args))
(str (gridlock-get-str field))
(values (split-string str "="))
tag value)
(setq tag (string-to-number (car values)))
(when (> tag 0)
(oset field tag tag))
(setq value (cadr values))
(when value
(oset field string value))
field))
(defun gridlock-fix-get-title (field)
"Return the title associated with FIELD."
(let* ((tag (gridlock-fix-get-tag field))
(str (gethash tag gridlock-fix-metadata)))
(if (and str (not (string-empty-p str)))
str
"")))
(defun gridlock-fix-gather-titles (fields)
"Return a list of all field headings in field list FIELDS."
(mapcar (lambda (field)
(gridlock-fix-get-title field)) fields))
(defvar gridlock-fix-mode-map
(let ((map gridlock-mode-map))
(define-key map [t] 'gridlock-fix-turn-off)
map)
"Keymap for `gridlock-fix-mode'.")
(defun gridlock-fix-reset()
"Reset `gridlock-fix' state."
(gridlock-reset)
(gridlock-fix--reset-metadata)
)
(defun gridlock-fix-turn-off ()
"Turn off `gridlock-fix-mode'."
(interactive)
(gridlock-fix-mode -1))
(define-minor-mode gridlock-fix-mode
"Navigate between and explicate FIX fields."
:init-value nil
:lighter " GRID"
:keymap gridlock-fix-mode-map
(if gridlock-fix-mode
(progn
(setq gridlock-anchor-regex "FIX\\.[45]\\.")
(setq gridlock-field-delimiter "\x01\\||")
(setq gridlock-field-regex-begin "\\(8=\\)")
(setq gridlock-field-regex-end "\\(10=[:digit:]\\{3\\}\\)")
(setq gridlock-metadata-get-title-func #'gridlock-fix-get-title)
(setq gridlock-metadata-gather-titles-func #'gridlock-fix-gather-titles)
(setq gridlock-create-field-func #'gridlock-fix-create-field)
(run-hooks 'gridlock-fix-init-hook)
(gridlock-fix-reset)
(gridlock-fix--get-buffer-metadata)
(gridlock-activate-one-of-display-schemes
gridlock-fix-preferred-display-schemes)
(gridlock-show-title))
(gridlock-fix-reset)))
(provide 'gridlock-fix)
;;; gridlock-fix.el ends here