-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkindex1.el
207 lines (187 loc) · 6.66 KB
/
markindex1.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
; Functions to mark text for an index
; Put this in the .emacs file in the latex-mode-hook
; (load "markindex1")
; (local-set-key "\C-ci" index-key-map)
(defvar markindex-indexfile nil)
; if this variable is nil, don't create a file of index terms
(setq markindex-indexfile "/home/tmoon/junkindex")
; the text that is used in the index command
(defvar index-start-text "\\Index{")
(defvar index-end-text "}")
; the following is used if the word is upper case:
; display in upper case, but insert in index in lower case
; command: \Index2{text Word}{index word}
(defvar index-start-text2 "\\Index2{")
(defvar index-interm-b "}{")
(defvar index-end-text2 "}")
; the register that is used to save the data
(defvar index-register 'k)
(setq index-key-map '(keymap
(119 . index-word1) ; w - index one word
(109 . mmark-word2) ; m - mark a word
(99 . clear-index-mark) ; c - clear the marking
(87 . index-word2) ; W - index several words
))
; pq marks the range of words to index
(setq pq nil)
(defun index-word1()
"Mark a single word and put it into index form"
(interactive "*")
(mmark-word)
(copy-to-register index-register (marker-position (car pq))
(marker-position (car (cdr pq))))
(setq downword (downcase (get-register index-register)))
(if (not (string= downword (get-register index-register)))
; if an upper case word
(if (y-or-n-p (concat "Insert index word ["
(get-register index-register) "] in upper case? "))
; insert in upper case
(progn ; mark the index in the buffer
(goto-char (marker-position (car pq)))
(insert index-start-text) ; \Index{
; (insert-register index-register t) ; word
(goto-char (marker-position (car (cdr pq))))
(insert index-end-text) ; }
(setq saveword (get-register index-register))
)
; else insert in lower case
(progn ; make the index in the buffer
(goto-char (marker-position (car pq)))
(insert index-start-text2) ; \Index2{
; (insert-register index-register t) ; Word
(goto-char (marker-position (car (cdr pq))))
(insert index-interm-b) ; }{
(insert downword) ; word
(insert index-end-text2) ; }
(setq saveword downword)
)
)
; else a lower-case word
(progn
(goto-char (marker-position (car pq)))
(insert index-start-text)
; (insert-register index-register t)
(goto-char (marker-position (car (cdr pq))))
(insert index-end-text)
(setq saveword (get-register index-register))
)
)
; Now check for the buffer with the index list in it
(if (not (eq markindex-indexfile nil))
(progn (princ "using indexfile")
(insert-index-word saveword)
)
)
(setq pq nil) ; clear out for next round of marking
)
(defun insert-index-word (word)
"Put an index word into the index word buffer"
(interactive "*")
(setq markindexb (find-file-noselect markindex-indexfile))
(save-excursion
(set-buffer markindexb)
(goto-char 1) ; go to the top of the file
(setq case-fold-search t)
; look for the word in the other buffer
(if(not(word-search-forward word (point-max) t))
(progn (insert word)
(insert "\n")
; sort the whole thing
(sort-lines nil (point-min) (point-max))
)
)
)
)
(defun mmark-word()
"Marks the word that the point is sitting on or after"
(interactive "*")
(move-to-wordstart)
(setq p (point-marker))
(forward-word 1)
(setq q (point-marker))
(setq pq (list p q))
)
(defun mmark-word2()
"Marks the word that the point is sitting on or after, keeping track of multiple words; moves to next word after marking"
(interactive "*")
(move-to-wordstart)
(if (null pq)
; if no previous mark, simple set up as usual
(progn (setq p (point-marker)) (forward-word 1) (setq q (point-marker)))
; otherwise,
(progn
; if point < previous p, set new p
(if (< (point) (marker-position (car pq)))
(progn (setq p (point-marker)) (setq q (car (cdr pq))))
; else if point > previous q, set new q
(if (> (point) (marker-position (car (cdr pq))))
(progn (setq p (car pq)) (forward-word 1) (setq q (point-marker)))
)
)
)
)
(forward-word 1) (backward-word 1)
(setq pq (list p q))
)
(defun clear-index-mark()
"Clear the marking of a word sequence"
(interactive "*")
(setq pq nil)
)
(defun move-to-wordstart()
"Moves the point to the beginning of a word"
(interactive "*")
(if (not (looking-at "\\w")) (backward-char 1))
(while (looking-at "\\w") (backward-char 1)
)
(forward-char 1)
)
(defun index-word2()
"Place marked words into index"
(interactive "*")
(copy-to-register index-register (marker-position (car pq))
(marker-position (car (cdr pq))))
(setq downword (downcase (get-register index-register)))
(if (not (string= downword (get-register index-register)))
; if an upper case word
(if (y-or-n-p (concat "Insert index word ["
(get-register index-register) "] in upper case? "))
; insert in upper case
(progn ; mark the index in the buffer
(goto-char (marker-position (car pq)))
(insert index-start-text) ; \Index{
; (insert-register index-register t) ; word
(goto-char (marker-position (car (cdr pq))))
(insert index-end-text) ; }
(setq saveword (get-register index-register))
)
; else insert in lower case
(progn ; make the index in the buffer
(goto-char (marker-position (car pq)))
(insert index-start-text2) ; \Index2{
; (insert-register index-register t) ; Word
(goto-char (marker-position (car (cdr pq))))
(insert index-interm-b) ; }{
(insert downword) ; word
(insert index-end-text2) ; }
(setq saveword downword)
)
)
; else a lower-case word
(progn
(goto-char (marker-position (car pq)))
(insert index-start-text)
; (insert-register index-register t)
(goto-char (marker-position (car (cdr pq))))
(insert index-end-text)
(setq saveword (get-register index-register))
)
)
; Now check for the buffer with the index list in it
(if (not (eq markindex-indexfile nil))
(progn (princ "using indexfile")
(insert-index-word saveword)
)
)
(setq pq nil) ; clear out for next round of marking
)