aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Blandy1991-02-04 22:07:47 +0000
committerJim Blandy1991-02-04 22:07:47 +0000
commit54369c0fba2264459cb128a065ce8ce6a3ccfa5b (patch)
treed1606f774b4e580002f9a430dce3218cc2d5887a
parent5627d72e884c39e033dc402205cf23e213c112fa (diff)
downloademacs-54369c0fba2264459cb128a065ce8ce6a3ccfa5b.tar.gz
emacs-54369c0fba2264459cb128a065ce8ce6a3ccfa5b.zip
Initial revision
-rw-r--r--lisp/term/bg-mouse.el304
-rw-r--r--lisp/textmodes/bib-mode.el233
2 files changed, 537 insertions, 0 deletions
diff --git a/lisp/term/bg-mouse.el b/lisp/term/bg-mouse.el
new file mode 100644
index 00000000000..9b83f5f6c2a
--- /dev/null
+++ b/lisp/term/bg-mouse.el
@@ -0,0 +1,304 @@
1;; GNU Emacs code for BBN Bitgraph mouse.
2;; Copyright (C) Free Software Foundation, Inc. Oct 1985.
3;; Time stamp <89/03/21 14:27:08 gildea>
4
5;; This file is part of GNU Emacs.
6
7;; GNU Emacs is free software; you can redistribute it and/or modify
8;; it under the terms of the GNU General Public License as published by
9;; the Free Software Foundation; either version 1, or (at your option)
10;; any later version.
11
12;; GNU Emacs is distributed in the hope that it will be useful,
13;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15;; GNU General Public License for more details.
16
17;; You should have received a copy of the GNU General Public License
18;; along with GNU Emacs; see the file COPYING. If not, write to
19;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20
21
22;;; Original version by John Robinson (jr@bbn-unix.arpa, bbncca!jr), Oct 1985
23;;; Modularized and enhanced by gildea@bbn.com Nov 1987
24
25(provide 'bg-mouse)
26
27;;; User customization option:
28
29(defvar bg-mouse-fast-select-window nil
30 "*Non-nil for mouse hits to select new window, then execute; else just select.")
31
32;;; These numbers are summed to make the index into the mouse-map.
33;;; The low three bits correspond to what the mouse actually sends.
34(defconst bg-button-r 1)
35(defconst bg-button-m 2)
36(defconst bg-button-c 2)
37(defconst bg-button-l 4)
38(defconst bg-in-modeline 8)
39(defconst bg-in-scrollbar 16)
40(defconst bg-in-minibuf 24)
41
42;;; semicolon screws up indenting, so use this instead
43(defconst semicolon ?\;)
44
45;;; Defuns:
46
47(defun bg-mouse-report (prefix-arg)
48 "Read, parse, and execute a BBN BitGraph mouse click.
49
50L-- move point | These apply for mouse click in a window.
51--R set mark | If bg-mouse-fast-select-window is nil,
52L-R kill region | these commands on a nonselected window
53-C- move point and yank | just select that window.
54LC- yank-pop |
55-CR or LCR undo | \"Scroll bar\" is right-hand window column.
56
57on modeline: on \"scroll bar\": in minibuffer:
58L-- scroll-up line to top execute-extended-command
59--R scroll-down line to bottom eval-expression
60-C- proportional goto-char line to middle suspend-emacs
61
62To reinitialize the mouse if the terminal is reset, type ESC : RET"
63 (interactive "P")
64 (bg-get-tty-num semicolon)
65 (let*
66 ((screen-mouse-x (min (1- (screen-width)) ;don't hit column 86!
67 (/ (bg-get-tty-num semicolon) 9)))
68 (screen-mouse-y (- (1- (screen-height)) ;assume default font size.
69 (/ (bg-get-tty-num semicolon) 16)))
70 (bg-mouse-buttons (% (bg-get-tty-num ?c) 8))
71 (bg-mouse-window (bg-window-from-x-y screen-mouse-x screen-mouse-y))
72 (bg-cursor-window (selected-window))
73 (edges (window-edges bg-mouse-window))
74 (minibuf-p (= screen-mouse-y (1- (screen-height))))
75 (in-modeline-p (and (not minibuf-p)
76 (= screen-mouse-y (1- (nth 3 edges)))))
77 (in-scrollbar-p (and (not minibuf-p) (not in-modeline-p)
78 (>= screen-mouse-x (1- (nth 2 edges)))))
79 (same-window-p (eq bg-mouse-window bg-cursor-window))
80 (in-minibuf-p (and minibuf-p
81 (not bg-mouse-window))) ;minibuf must be inactive
82 (bg-mode-bits (+ (if in-minibuf-p bg-in-minibuf 0)
83 (if in-modeline-p bg-in-modeline 0)
84 (if in-scrollbar-p bg-in-scrollbar 0)))
85 (bg-command
86 (lookup-key mouse-map
87 (char-to-string (+ bg-mode-bits bg-mouse-buttons))))
88 (bg-mouse-x (- screen-mouse-x (nth 0 edges)))
89 (bg-mouse-y (- screen-mouse-y (nth 1 edges))))
90 (cond ((or in-modeline-p in-scrollbar-p)
91 (select-window bg-mouse-window)
92 (bg-command-execute bg-command)
93 (select-window bg-cursor-window))
94 ((or same-window-p in-minibuf-p)
95 (bg-command-execute bg-command))
96 (t ;in another window
97 (select-window bg-mouse-window)
98 (if bg-mouse-fast-select-window
99 (bg-command-execute bg-command)))
100 )))
101
102
103;;; Library of commands:
104
105(defun bg-set-point ()
106 "Move point to location of BitGraph mouse."
107 (interactive)
108 (bg-move-point-to-x-y bg-mouse-x bg-mouse-y)
109 (setq this-command 'next-line) ;make subsequent line moves work
110 (setq temporary-goal-column bg-mouse-x))
111
112(defun bg-set-mark ()
113 "Set mark at location of BitGraph mouse."
114 (interactive)
115 (push-mark)
116 (bg-move-point-to-x-y bg-mouse-x bg-mouse-y)
117 (exchange-point-and-mark))
118
119(defun bg-yank ()
120 "Move point to location of BitGraph mouse and yank."
121 (interactive "*")
122 (bg-move-point-to-x-y bg-mouse-x bg-mouse-y)
123 (setq this-command 'yank)
124 (yank))
125
126(defun yank-pop-1 ()
127 (interactive "*")
128 (yank-pop 1))
129
130(defun bg-yank-or-pop ()
131 "Move point to location of BitGraph mouse and yank. If last command
132was a yank, do a yank-pop."
133 (interactive "*")
134 (if (eql last-command 'yank)
135 (yank-pop 1)
136 (bg-yank)))
137
138;;; In 18.51, Emacs Lisp doesn't provide most-positive-fixnum
139(defconst bg-most-positive-fixnum 8388607)
140
141(defun bg-move-by-percentage ()
142 "Go to location in buffer that is the same percentage of the way
143through the buffer as the BitGraph mouse's X position in the window."
144 (interactive)
145 ;; check carefully for overflow in intermediate calculations
146 (goto-char
147 (cond ((zerop bg-mouse-x)
148 0)
149 ((< (buffer-size) (/ bg-most-positive-fixnum bg-mouse-x))
150 ;; no danger of overflow: compute it exactly
151 (/ (* bg-mouse-x (buffer-size))
152 (1- (window-width))))
153 (t
154 ;; overflow possible: approximate
155 (* (/ (buffer-size) (1- (window-width)))
156 bg-mouse-x))))
157 (beginning-of-line)
158 (what-cursor-position))
159
160(defun bg-mouse-line-to-top ()
161 "Scroll the line pointed to by the BitGraph mouse to the top of the window."
162 (interactive)
163 (scroll-up bg-mouse-y))
164
165(defun bg-mouse-line-to-center ()
166 "Scroll the line pointed to by the BitGraph mouse to the center
167of the window"
168 (interactive)
169 (scroll-up (/ (+ 2 bg-mouse-y bg-mouse-y (- (window-height))) 2)))
170
171(defun bg-mouse-line-to-bottom ()
172 "Scroll the line pointed to by the mouse to the bottom of the window."
173 (interactive)
174 (scroll-up (+ bg-mouse-y (- 2 (window-height)))))
175
176(defun bg-kill-region ()
177 (interactive "*")
178 (kill-region (region-beginning) (region-end)))
179
180(defun bg-insert-moused-sexp ()
181 "Insert a copy of the word (actually sexp) that the mouse is pointing at.
182Sexp is inserted into the buffer at point (where the text cursor is)."
183 (interactive)
184 (let ((moused-text
185 (save-excursion
186 (bg-move-point-to-x-y bg-mouse-x bg-mouse-y)
187 (if (looking-at "\\s)")
188 (forward-char 1)
189 (forward-sexp 1))
190 (buffer-substring (save-excursion (backward-sexp 1) (point))
191 (point)))))
192 (select-window bg-cursor-window)
193 (delete-horizontal-space)
194 (cond
195 ((bolp)
196 (indent-according-to-mode))
197 ;; In Lisp assume double-quote is closing; in Text assume opening.
198 ;; Why? Because it does the right thing most often.
199 ((save-excursion (forward-char -1)
200 (and (not (looking-at "\\s\""))
201 (looking-at "[`'\"\\]\\|\\s(")))
202 nil)
203 (t
204 (insert-string " ")))
205 (insert-string moused-text)
206 (or (eolp)
207 (looking-at "\\s.\\|\\s)")
208 (and (looking-at "'") (looking-at "\\sw")) ;hack for text mode
209 (save-excursion (insert-string " ")))))
210
211;;; Utility functions:
212
213(defun bg-get-tty-num (term-char)
214 "Read from terminal until TERM-CHAR is read, and return intervening number.
215If non-numeric not matching TERM-CHAR, reprogram the mouse and signal an error."
216 (let
217 ((num 0)
218 (char (- (read-char) 48)))
219 (while (and (>= char 0)
220 (<= char 9))
221 (setq num (+ (* num 10) char))
222 (setq char (- (read-char) 48)))
223 (or (eq term-char (+ char 48))
224 (progn
225 (bg-program-mouse)
226 (error
227 "Invalid data format in bg-mouse command: mouse reinitialized.")))
228 num))
229
230;;; Note that this fails in the minibuf because move-to-column doesn't
231;;; allow for the width of the prompt.
232(defun bg-move-point-to-x-y (x y)
233 "Position cursor in window coordinates.
234X and Y are 0-based character positions in the window."
235 (move-to-window-line y)
236 ;; if not on a wrapped line, zero-column will be 0
237 (let ((zero-column (current-column))
238 (scroll-offset (window-hscroll)))
239 ;; scrolling takes up column 0 to display the $
240 (if (> scroll-offset 0)
241 (setq scroll-offset (1- scroll-offset)))
242 (move-to-column (+ zero-column scroll-offset x))
243 ))
244
245;;; Returns the window that screen position (x, y) is in or nil if none,
246;;; meaning we are in the echo area with a non-active minibuffer.
247;;; If coordinates-in-window-p were not in an X-windows-specific file
248;;; we could use that. In Emacs 19 can even use locate-window-from-coordinates
249(defun bg-window-from-x-y (x y)
250 "Find window corresponding to screen coordinates.
251X and Y are 0-based character positions on the screen."
252 (let ((edges (window-edges))
253 (window nil))
254 (while (and (not (eq window (selected-window)))
255 (or (< y (nth 1 edges))
256 (>= y (nth 3 edges))
257 (< x (nth 0 edges))
258 (>= x (nth 2 edges))))
259 (setq window (next-window window))
260 (setq edges (window-edges window)))
261 (cond ((eq window (selected-window))
262 nil) ;we've looped: not found
263 ((not window)
264 (selected-window)) ;just starting: current window
265 (t
266 window))
267 ))
268
269(defun bg-command-execute (bg-command)
270 (if (commandp bg-command)
271 (command-execute bg-command)
272 (ding)))
273
274(defun bg-program-mouse ()
275 (send-string-to-terminal "\e:0;7;;;360;512;9;16;9;16c"))
276
277;;; Note that the doc string for mouse-map (as defined in subr.el)
278;;; says it is for the X-window mouse. This is wrong; that keymap
279;;; should be used for your mouse no matter what terminal you have.
280
281(or (keymapp mouse-map)
282 (setq mouse-map (make-keymap)))
283
284(defun bind-bg-mouse-click (click-code function)
285 "Bind bg-mouse CLICK-CODE to run FUNCTION."
286 (define-key mouse-map (char-to-string click-code) function))
287
288(bind-bg-mouse-click bg-button-l 'bg-set-point)
289(bind-bg-mouse-click bg-button-m 'bg-yank)
290(bind-bg-mouse-click bg-button-r 'bg-set-mark)
291(bind-bg-mouse-click (+ bg-button-l bg-button-m) 'yank-pop-1)
292(bind-bg-mouse-click (+ bg-button-l bg-button-r) 'bg-kill-region)
293(bind-bg-mouse-click (+ bg-button-m bg-button-r) 'undo)
294(bind-bg-mouse-click (+ bg-button-l bg-button-m bg-button-r) 'undo)
295(bind-bg-mouse-click (+ bg-in-modeline bg-button-l) 'scroll-up)
296(bind-bg-mouse-click (+ bg-in-modeline bg-button-m) 'bg-move-by-percentage)
297(bind-bg-mouse-click (+ bg-in-modeline bg-button-r) 'scroll-down)
298(bind-bg-mouse-click (+ bg-in-scrollbar bg-button-l) 'bg-mouse-line-to-top)
299(bind-bg-mouse-click (+ bg-in-scrollbar bg-button-m) 'bg-mouse-line-to-center)
300(bind-bg-mouse-click (+ bg-in-scrollbar bg-button-r) 'bg-mouse-line-to-bottom)
301(bind-bg-mouse-click (+ bg-in-minibuf bg-button-l) 'execute-extended-command)
302(bind-bg-mouse-click (+ bg-in-minibuf bg-button-m) 'suspend-emacs)
303(bind-bg-mouse-click (+ bg-in-minibuf bg-button-r) 'eval-expression)
304
diff --git a/lisp/textmodes/bib-mode.el b/lisp/textmodes/bib-mode.el
new file mode 100644
index 00000000000..af6f2ded3f0
--- /dev/null
+++ b/lisp/textmodes/bib-mode.el
@@ -0,0 +1,233 @@
1;; bib-mode, major mode for editing bib files.
2;; Copyright (C) 1989 Free Software Foundation, Inc.
3
4;; This file is part of GNU Emacs.
5
6;; GNU Emacs is free software; you can redistribute it and/or modify
7;; it under the terms of the GNU General Public License as published by
8;; the Free Software Foundation; either version 1, or (at your option)
9;; any later version.
10
11;; GNU Emacs is distributed in the hope that it will be useful,
12;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;; GNU General Public License for more details.
15
16;; You should have received a copy of the GNU General Public License
17;; along with GNU Emacs; see the file COPYING. If not, write to
18;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
20
21;; Bib-Mode
22;; GNU Emacs code to help maintain databases compatible with (troff)
23;; refer and lookbib. The file bib-file should be set to your
24;; bibliography file. Keys are automagically inserted as you type,
25;; and appropriate keys are presented for various kinds of entries.
26
27(provide 'bib-mode)
28
29(defvar bib-file "~/my-bibliography.bib"
30 "Default name of file used by `addbib'.")
31
32(defvar unread-bib-file "~/to-be-read.bib"
33 "Default name of file used by `unread-bib' in Bib mode.")
34
35(defvar bib-mode-map (copy-keymap text-mode-map))
36(define-key bib-mode-map "\C-M" 'return-key-bib)
37(define-key bib-mode-map "\C-c\C-u" 'unread-bib)
38(define-key bib-mode-map "\C-c\C-@" 'mark-bib)
39(define-key bib-mode-map "\e`" 'abbrev-mode)
40(defvar bib-mode-abbrev-table nil
41 "Abbrev table used in Bib mode")
42
43(defun addbib ()
44 "Set up editor to add to troff bibliography file specified
45by global variable `bib-file'. See description of `bib-mode'."
46 (interactive)
47 (find-file bib-file)
48 (goto-char (point-max))
49 (bib-mode)
50 )
51
52(defun bib-mode ()
53 "Mode for editing `lookbib' style bibliographies.
54Hit RETURN to get next % field key.
55If you want to ignore this field, just hit RETURN again.
56Use `text-mode' to turn this feature off.
57
58 journal papers: A* T D J V N P K W X
59 articles in books & proceedings: A* T D B E* I C P K W X
60 tech reports: A* T D R I C K W X
61 books: A* T D I C K W X
62
63Fields:
64
65A uthor T itle D ate J ournal
66V olume N umber P age K eywords
67B in book or proceedings E ditor C ity & state
68I nstitution, school, or publisher
69R eport number or 'phd thesis' or 'masters thesis' or 'draft' or
70 'unnumbered' or 'unpublished'
71W here can be found locally (login name, or ailib, etc.)
72X comments (not used in indexing)
73
74\\[unread-bib] appends current entry to a different file (for example,
75a file of papers to be read in the future), given by the value of the
76variable `unread-bib-file'.
77\\[mark-bib] marks current or previous entry.
78Abbreviations are saved in `bib-mode-abbrev-table'.
79Hook can be stored in `bib-mode-hook'.
80Field keys given by variable `bib-assoc'.
81
82Commands:
83\\{bib-mode-map}
84"
85 (interactive)
86 (text-mode)
87 (use-local-map bib-mode-map)
88 (setq mode-name "Bib")
89 (setq major-mode 'bib-mode)
90 (define-abbrev-table 'bib-mode-abbrev-table ())
91 (setq local-abbrev-table bib-mode-abbrev-table)
92 (abbrev-mode 1)
93 (run-hooks 'bib-mode-hook)
94 )
95
96(defconst bib-assoc '(
97 (" *$" . "%A ")
98 ("%A ." . "%A ")
99 ("%A $" . "%T ")
100 ("%T " . "%D ")
101 ("%D " . "%J ")
102 ("%J ." . "%V ")
103 ("%V " . "%N ")
104 ("%N " . "%P ")
105 ("%P " . "%K ")
106 ("%K " . "%W ")
107 ("%W " . "%X ")
108 ("%X " . "")
109 ("%J $" . "%B ")
110 ("%B ." . "%E ")
111 ("%E ." . "%E ")
112 ("%E $" . "%I ")
113 ("%I " . "%C ")
114 ("%C " . "%P ")
115 ("%B $" . "%R ")
116 ("%R " . "%I ")
117 )
118
119"Describes bibliographic database format. A line beginning with
120the car of an entry is followed by one beginning with the cdr.
121")
122
123(defun bib-find-key (slots)
124 (cond
125 ((null slots)
126 (if (bobp)
127 ""
128 (progn (previous-line 1) (bib-find-key bib-assoc))))
129 ((looking-at (car (car slots)))
130 (cdr (car slots)))
131 (t (bib-find-key (cdr slots)))
132 ))
133
134
135(defvar bib-auto-capitalize t
136"*True to automatically capitalize appropriate fields in Bib mode.")
137
138(defconst bib-capitalized-fields "%[AETCBIJR]")
139
140(defun return-key-bib ()
141 "Magic when user hits return, used by `bib-mode'."
142 (interactive)
143 (if (eolp)
144 (let (empty new-key beg-current end-current)
145 (beginning-of-line)
146 (setq empty (looking-at "%. $"))
147 (if (not empty)
148 (progn
149 (end-of-line)
150 (newline)
151 (forward-line -1)
152 ))
153 (end-of-line)
154 (setq end-current (point))
155 (beginning-of-line)
156 (setq beg-current (point))
157 (setq new-key (bib-find-key bib-assoc))
158 (if (and (not empty) bib-auto-capitalize
159 (looking-at bib-capitalized-fields))
160 (save-excursion
161 (capitalize-title-region (+ (point) 3) end-current)))
162 (goto-char beg-current)
163 (if empty
164 (kill-line nil)
165 (forward-line 1)
166 )
167 (insert-string new-key))
168 (newline)))
169
170(defun mark-bib ()
171 "Set mark at beginning of current or previous bib entry, point at end."
172 (interactive)
173 (beginning-of-line nil)
174 (if (looking-at "^ *$") (re-search-backward "[^ \n]" nil 2))
175 (re-search-backward "^ *$" nil 2)
176 (re-search-forward "^%")
177 (beginning-of-line nil)
178 (push-mark (point))
179 (re-search-forward "^ *$" nil 2)
180 (next-line 1)
181 (beginning-of-line nil))
182
183(defun unread-bib ()
184 "Append current or previous entry to file of unread papers
185named by variable `unread-bib-file'."
186 (interactive)
187 (mark-bib)
188 (if (get-file-buffer unread-bib-file)
189 (append-to-buffer (get-file-buffer unread-bib-file) (mark) (point))
190 (append-to-file (mark) (point) unread-bib-file)))
191
192
193(defvar capitalize-title-stop-words
194 (concat
195 "the\\|and\\|of\\|is\\|a\\|an\\|of\\|for\\|in\\|to\\|in\\|on\\|at\\|"
196 "by\\|with\\|that\\|its")
197 "Words not to be capitialized in a title (unless they're the first word
198in the title).")
199
200(defvar capitalize-title-stop-regexp
201 (concat "\\(" capitalize-title-stop-words "\\)\\(\\b\\|'\\)"))
202
203(defun capitalize-title-region (begin end)
204 "Like `capitalize-region', but don't capitalize stop words, except the first."
205 (interactive "r")
206 (let ((case-fold-search nil) (orig-syntax-table (syntax-table)))
207 (unwind-protect
208 (save-restriction
209 (set-syntax-table text-mode-syntax-table)
210 (narrow-to-region begin end)
211 (goto-char (point-min))
212 (if (looking-at "[A-Z][a-z]*[A-Z]")
213 (forward-word 1)
214 (capitalize-word 1))
215 (while (re-search-forward "\\<" nil t)
216 (if (looking-at "[A-Z][a-z]*[A-Z]")
217 (forward-word 1)
218 (if (let ((case-fold-search t))
219 (looking-at capitalize-title-stop-regexp))
220 (downcase-word 1)
221 (capitalize-word 1)))
222 ))
223 (set-syntax-table orig-syntax-table))))
224
225
226(defun capitalize-title (s)
227 "Like `capitalize', but don't capitalize stop words, except the first."
228 (save-excursion
229 (set-buffer (get-buffer-create "$$$Scratch$$$"))
230 (erase-buffer)
231 (insert s)
232 (capitalize-title-region (point-min) (point-max))
233 (buffer-string)))