summaryrefslogtreecommitdiff
path: root/biblio/tib/elisp/tib.el
blob: cdbe91eb5bef6ac339449c2a252a23cdb808f00c (plain)
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
;;;; tib.el - Emacs interface to the Tib bibliography system.
;;;; Requires Olin Shiver's comint package.

;; Copyright (C) 1990 by Sebastian Kremer <sk@thp.uni-koeln.de>

;; 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 1, 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, write to the Free Software
;; Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

;; Lispdir entry for the Elisp Archive:
;;    tib|Sebastian Kremer|sk@thp.uni-koeln.de
;;    |Enter and check bibliographic references for Tib.
;;    |$Date: 90/10/30 11:10:29 $|$Revision: 1.2 $|

;; For your .emacs:

;;    (global-set-key "\C-c[" 'tib-insert-ref)
;;    (global-set-key "\C-c." 'tib-check-reference)
;;    (autoload 'tib-insert-ref "tib" "Insert a tib reference." t)
;;    (autoload 'tib-check-reference "tib" "Check a tib reference." t)
;;    (autoload 'tiblook "tib" "Run tiblook in a buffer." t)

;; Instead of global-set-key, you might want to bind it in
;; (la)tex-mode-map only, in your (la)tex-mode-hook.

(defconst tib-version
  "$Id: tib.el,v 1.2 90/10/30 11:10:29 sk Exp $")

(require 'comint)



























;;; Support for editing tex files containing tib references:

(defun tib-insert-ref ()
  "Insert a tib reference \"[..]\" and put cursor into it."
  (interactive)
  (insert "[.")
  (save-excursion (insert ".]")))

(defconst tib-ref-beginning "\\(\\[\\.\\)\\|\\(,[ \t\n]*\\)"
  "Regexp matching the beginning of a Tib reference.")

(defconst tib-ref-end "\\(\\.\\]\\)\\|\\(,[ \t\n]*\\)"
  "Regexp matching the end of a Tib reference.")

(defun tib-reference-at-point ()
  (save-excursion
    (let ((low (save-excursion (forward-line -1)
			       (point)))
	  (high (save-excursion (forward-line 1)
				(end-of-line)
				(point)))
	  start)
      (or (setq start
		(or (if (looking-at "\\[\\.") (match-end 0))
		    (save-excursion
		      (if (re-search-backward tib-ref-beginning low t)
			  (match-end 0)))
		    (save-excursion
		      (if (re-search-forward tib-ref-beginning high t)
			  (match-end 0)))))
	  (error "Could not find beginning of tib reference."))
      (goto-char start)
      (or (re-search-forward tib-ref-end high t)
	  (error "Could not find end of tib reference."))
      (buffer-substring start (match-beginning 0)))))

(defun tib-check-reference (reference)
  "Check the tib reference around point .
If not on \"\[.\", has a preference for looking backwards.
Pops up a *tiblook* buffer and feeds it tib-reference-at-point.
See also variables tib-ref-beginning and tib-ref-end."
  (interactive (list (tib-reference-at-point)))
  (message "Checking '%s'" reference)
  (let ((buf (current-buffer)))
    (tiblook)				; pop to tiblook buffer
    (goto-char (point-max))
    (insert "\t")			; to separate it visually
    (insert reference)			; from manual input
    (comint-send-input)
    ;; wait for output so that point moves and output is visible:
    (sit-for 1)
    (recenter -1)
    ;; go back to editing buffer:
    (pop-to-buffer buf)))






















;;; The tiblook interface is a customized comint mode.

(defvar tiblook-mode-map (copy-keymap comint-mode-map))

(defvar tiblook-mode-hook nil
  "*Hook for customising tiblook mode.")

(defvar tiblook-prompt-pattern "^\*"
  "Regexp matching tiblook's prompt.")

(defun tiblook-mode ()
  "Major mode for interacting with tiblook.
Return after the end of the process' output sends the text from the
    end of process to the end of the current line.
Return before end of process output copies rest of line to end (skipping
    the prompt) and sends it.

If you accidentally suspend your process, use \\[comint-continue-subjob]
to continue it.

\\{tiblook-mode-map}
Customisation: Entry to this mode runs the hooks on comint-mode-hook and
tiblook-mode-hook (in that order).
"
  (interactive)
  (comint-mode)
  (setq comint-prompt-regexp tiblook-prompt-pattern)
  (setq major-mode 'tiblook-mode)
  (setq mode-name "Tiblook")
  (use-local-map tiblook-mode-map)
  (run-hooks 'tiblook-mode-hook))

(defun tiblook ()
  "Run an inferior tiblook, with I/O through buffer *tiblook*.
If buffer exists but tiblook process is not running, make new process.
If buffer exists and tiblook process is running, just switch to *tiblook*.
The buffer is put in tiblook-mode.
See also variable tiblook-prompt-pattern.

\(Type \\[describe-mode] in the tiblook buffer for a list of commands.)"
  (interactive)
  (cond ((not (comint-check-proc "*tiblook*"))
	 (set-buffer (make-comint "tiblook" "tiblook"))
	 (tiblook-mode)))
  (pop-to-buffer "*tiblook*"))

(provide 'tib)