annotate lisp/dabbrev.el @ 1323:25b5b55a3916

* process.c (wait_reading_process_input): If the select returns ENOMEM, treat that like EINTR under Ultrix.
author Jim Blandy <jimb@redhat.com>
date Sat, 03 Oct 1992 03:30:53 +0000
parents 9fe14b2cc5b9
children 2c7997f249eb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
1 ;;; dabbrev.el --- dynamic abbreviation package for GNU Emacs.
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
2
846
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
3 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
4
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
5 ;; Last-Modified: 16 Mar 1992
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
6 ;; Copyright (C) 1985, 1986 Free Software Foundation, Inc.
20674ae6bf52 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 807
diff changeset
7
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 793
diff changeset
8 ;; Maintainer: FSF
267
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
9
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
10 ;; This file is part of GNU Emacs.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
11
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
13 ;; it under the terms of the GNU General Public License as published by
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 793
diff changeset
14 ;; the Free Software Foundation; either version 2, or (at your option)
267
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
15 ;; any later version.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
16
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
17 ;; GNU Emacs is distributed in the hope that it will be useful,
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
20 ;; GNU General Public License for more details.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
21
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
22 ;; You should have received a copy of the GNU General Public License
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
23 ;; along with GNU Emacs; see the file COPYING. If not, write to
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
24 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
25
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 793
diff changeset
26 ;;; Commentary:
267
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
27
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
28 ; DABBREVS - "Dynamic abbreviations" hack, originally written by Don Morrison
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
29 ; for Twenex Emacs. Converted to mlisp by Russ Fish. Supports the table
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
30 ; feature to avoid hitting the same expansion on re-expand, and the search
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
31 ; size limit variable. Bugs fixed from the Twenex version are flagged by
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
32 ; comments starting with ;;; .
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
33 ;
793
6fb68a1460a6 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 662
diff changeset
34 ; converted to Emacs Lisp by Spencer Thomas.
267
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
35 ; Thoroughly cleaned up by Richard Stallman.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
36 ;
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
37 ; If anyone feels like hacking at it, Bob Keller (Keller@Utah-20) first
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
38 ; suggested the beast, and has some good ideas for its improvement, but
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 793
diff changeset
39 ; doesn't know TECO (the lucky devil...). One thing that should definitely
267
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
40 ; be done is adding the ability to search some other buffer(s) if you can?t
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
41 ; find the expansion you want in the current one.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
42
807
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 793
diff changeset
43 ;;; Code:
4f28bd14272c *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 793
diff changeset
44
267
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
45 ;; (defun dabbrevs-help ()
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
46 ;; "Give help about dabbrevs."
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
47 ;; (interactive)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
48 ;; (&info "emacs" "dabbrevs") ; Select the specific info node.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
49 ;; )
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
50 (defvar dabbrevs-limit nil
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
51 "*Limits region searched by `dabbrevs-expand' to this many chars away.")
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
52 (make-variable-buffer-local 'dabbrevs-limit)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
53
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
54 (defvar dabbrevs-backward-only nil
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
55 "*If non-NIL, `dabbrevs-expand' only looks backwards.")
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
56
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
57 ; State vars for dabbrevs-re-expand.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
58 (defvar last-dabbrevs-table nil
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
59 "Table of expansions seen so far (local)")
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
60 (make-variable-buffer-local 'last-dabbrevs-table)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
61
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
62 (defvar last-dabbrevs-abbreviation ""
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
63 "Last string we tried to expand (local).")
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
64 (make-variable-buffer-local 'last-dabbrevs-abbreviation)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
65
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
66 (defvar last-dabbrevs-direction 0
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
67 "Direction of last dabbrevs search (local)")
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
68 (make-variable-buffer-local 'last-dabbrevs-direction)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
69
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
70 (defvar last-dabbrevs-abbrev-location nil
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
71 "Location last abbreviation began (local).")
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
72 (make-variable-buffer-local 'last-dabbrevs-abbrev-location)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
73
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
74 (defvar last-dabbrevs-expansion nil
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
75 "Last expansion of an abbreviation. (local)")
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
76 (make-variable-buffer-local 'last-dabbrevs-expansion)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
77
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
78 (defvar last-dabbrevs-expansion-location nil
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
79 "Location the last expansion was found. (local)")
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
80 (make-variable-buffer-local 'last-dabbrevs-expansion-location)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
81
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
82 ;;;###autoload
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
83 (defun dabbrev-expand (arg)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
84 "Expand previous word \"dynamically\".
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
85 Expands to the most recent, preceding word for which this is a prefix.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
86 If no suitable preceding word is found, words following point are considered.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
87
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
88 If `case-fold-search' and `case-replace' are non-nil (usually true)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
89 then the substituted word may be case-adjusted to match the abbreviation
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
90 that you had typed. This takes place if the substituted word, as found,
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
91 is all lower case, or if it is at the beginning of a sentence and only
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
92 its first letter was upper case.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
93
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
94 A positive prefix arg N says to take the Nth backward DISTINCT
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
95 possibility. A negative argument says search forward. The variable
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
96 `dabbrev-backward-only' may be used to limit the direction of search to
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
97 backward if set non-nil.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
98
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
99 If the cursor has not moved from the end of the previous expansion and
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
100 no argument is given, replace the previously-made expansion
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
101 with the next possible expansion not yet tried."
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
102 (interactive "*P")
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
103 (let (abbrev expansion old which loc n pattern
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
104 (do-case (and case-fold-search case-replace)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
105 ;; abbrev -- the abbrev to expand
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
106 ;; expansion -- the expansion found (eventually) or nil until then
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
107 ;; old -- the text currently in the buffer
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
108 ;; (the abbrev, or the previously-made expansion)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
109 ;; loc -- place where expansion is found
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
110 ;; (to start search there for next expansion if requested later)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
111 ;; do-case -- non-nil if should transform case when substituting.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
112 (save-excursion
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
113 (if (and (null arg)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
114 (eq last-command this-command)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
115 last-dabbrevs-abbrev-location)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
116 (progn
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
117 (setq abbrev last-dabbrevs-abbreviation)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
118 (setq old last-dabbrevs-expansion)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
119 (setq which last-dabbrevs-direction))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
120 (setq which (if (null arg)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
121 (if dabbrevs-backward-only 1 0)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
122 (prefix-numeric-value arg)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
123 (setq loc (point))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
124 (forward-word -1)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
125 (setq last-dabbrevs-abbrev-location (point)) ; Original location.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
126 (setq abbrev (buffer-substring (point) loc))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
127 (setq old abbrev)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
128 (setq last-dabbrevs-expansion-location nil)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
129 (setq last-dabbrev-table nil)) ; Clear table of things seen.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
130
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
131 (setq pattern (concat "\\b" (regexp-quote abbrev) "\\(\\sw\\|\\s_\\)+"))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
132 ;; Try looking backward unless inhibited.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
133 (if (>= which 0)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
134 (progn
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
135 (setq n (max 1 which))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
136 (if last-dabbrevs-expansion-location
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
137 (goto-char last-dabbrevs-expansion-location))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
138 (while (and (> n 0)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
139 (setq expansion (dabbrevs-search pattern t do-case)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
140 (setq loc (point-marker))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
141 (setq last-dabbrev-table (cons expansion last-dabbrev-table))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
142 (setq n (1- n)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
143 (or expansion
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
144 (setq last-dabbrevs-expansion-location nil))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
145 (setq last-dabbrevs-direction (min 1 which))))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
146
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
147 (if (and (<= which 0) (not expansion)) ; Then look forward.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
148 (progn
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
149 (setq n (max 1 (- which)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
150 (if last-dabbrevs-expansion-location
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
151 (goto-char last-dabbrevs-expansion-location))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
152 (while (and (> n 0)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
153 (setq expansion (dabbrevs-search pattern nil do-case)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
154 (setq loc (point-marker))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
155 (setq last-dabbrev-table (cons expansion last-dabbrev-table))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
156 (setq n (1- n)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
157 (setq last-dabbrevs-direction -1))))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
158
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
159 (if (not expansion)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
160 (let ((first (string= abbrev old)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
161 (setq last-dabbrevs-abbrev-location nil)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
162 (if (not first)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
163 (progn (undo-boundary)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
164 (delete-backward-char (length old))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
165 (insert abbrev)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
166 (error (if first
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
167 "No dynamic expansion for \"%s\" found."
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
168 "No further dynamic expansions for \"%s\" found.")
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
169 abbrev))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
170 ;; Success: stick it in and return.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
171 (undo-boundary)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
172 (search-backward old)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
173 ;; Make case of replacement conform to case of abbreviation
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
174 ;; provided (1) that kind of thing is enabled in this buffer
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
175 ;; and (2) the replacement itself is all lower case.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
176 ;; First put back the original abbreviation with its original
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
177 ;; case pattern.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
178 (save-excursion
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
179 (replace-match abbrev t 'literal))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
180 (search-forward abbrev)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
181 (let ((do-case (and do-case
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
182 (string= (substring expansion 1)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
183 (downcase (substring expansion 1))))))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
184 ;; First put back the original abbreviation with its original
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
185 ;; case pattern.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
186 (save-excursion
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
187 (replace-match abbrev t 'literal))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
188 (search-forward abbrev)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
189 (replace-match (if do-case (downcase expansion) expansion)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
190 (not do-case)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
191 'literal))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
192 ;; Save state for re-expand.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
193 (setq last-dabbrevs-abbreviation abbrev)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
194 (setq last-dabbrevs-expansion expansion)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
195 (setq last-dabbrevs-expansion-location loc))))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
196
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
197 ;;;###autoload
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
198 (define-key esc-map "/" 'dabbrev-expand)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
199
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
200
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
201 ;; Search function used by dabbrevs library.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
202 ;; First arg is string to find as prefix of word. Second arg is
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
203 ;; t for reverse search, nil for forward. Variable dabbrevs-limit
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
204 ;; controls the maximum search region size.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
205
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
206 ;; Table of expansions already seen is examined in buffer last-dabbrev-table,
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
207 ;; so that only distinct possibilities are found by dabbrevs-re-expand.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
208 ;; Note that to prevent finding the abbrev itself it must have been
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
209 ;; entered in the table.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
210
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
211 ;; IGNORE-CASE non-nil means treat case as insignificant while
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
212 ;; looking for a match and when comparing with previous matches.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
213 ;; Also if that's non-nil and the match is found at the beginning of a sentence
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
214 ;; and is in lower case except for the initial
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
215 ;; then it is converted to all lower case for return.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
216
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
217 ;; Value is the expansion, or nil if not found. After a successful
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
218 ;; search, point is left right after the expansion found.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
219
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
220 (defun dabbrevs-search (pattern reverse ignore-case)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
221 (let (missing result (case-fold-search ignore-case))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
222 (save-restriction ; Uses restriction for limited searches.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
223 (if dabbrevs-limit
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
224 (narrow-to-region last-dabbrevs-abbrev-location
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
225 (+ (point)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
226 (* dabbrevs-limit (if reverse -1 1)))))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
227 ;; Keep looking for a distinct expansion.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
228 (setq result nil)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
229 (setq missing nil)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
230 (while (and (not result) (not missing))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
231 ; Look for it, leave loop if search fails.
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
232 (setq missing
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
233 (not (if reverse
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
234 (re-search-backward pattern nil t)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
235 (re-search-forward pattern nil t))))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
236
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
237 (if (not missing)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
238 (progn
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
239 (setq result (buffer-substring (match-beginning 0)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
240 (match-end 0)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
241 (let* ((test last-dabbrev-table))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
242 (while (and test
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
243 (not
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
244 (if ignore-case
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
245 (string= (downcase (car test))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
246 (downcase result))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
247 (string= (car test) result))))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
248 (setq test (cdr test)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
249 (if test (setq result nil)))))) ; if already in table, ignore
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
250 (if result
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
251 (save-excursion
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
252 (let ((beg (match-beginning 0)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
253 (goto-char beg)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
254 (and ignore-case
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
255 (string= (substring result 1)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
256 (downcase (substring result 1)))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
257 (if (string= paragraph-start
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
258 (concat "^$\\|" page-delimiter))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
259 (and (re-search-backward sentence-end nil t)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
260 (= (match-end 0) beg))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
261 (forward-char 1)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
262 (backward-sentence)
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
263 (= (point) beg))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
264 (setq result (downcase result))))))
d83efd759350 Initial revision
Jim Blandy <jimb@redhat.com>
parents:
diff changeset
265 result)))
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 267
diff changeset
266
1144
9fe14b2cc5b9 entered into RCS
Roland McGrath <roland@gnu.org>
parents: 846
diff changeset
267 (provide 'dabbrev)
584
4cd7543be581 *** empty log message ***
Jim Blandy <jimb@redhat.com>
parents: 267
diff changeset
268
662
8a533acedb77 *** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents: 584
diff changeset
269 ;;; dabbrev.el ends here