/[emacs]/emacs/lisp/completion.el
ViewVC logotype

Diff of /emacs/lisp/completion.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.45 by monnier, Thu Aug 15 00:37:57 2002 UTC revision 1.46 by lektu, Tue Feb 4 11:05:54 2003 UTC
# Line 37  Line 37 
37  ;;  ;;
38  ;; Introduction  ;; Introduction
39  ;;---------------  ;;---------------
40  ;;    ;;
41  ;;     After you type a few characters, pressing the "complete" key inserts  ;;     After you type a few characters, pressing the "complete" key inserts
42  ;; the rest of the word you are likely to type.    ;; the rest of the word you are likely to type.
43  ;;  ;;
44  ;; This watches all the words that you type and remembers them.  When  ;; This watches all the words that you type and remembers them.  When
45  ;; typing a new word, pressing "complete" (meta-return) "completes" the  ;; typing a new word, pressing "complete" (meta-return) "completes" the
46  ;; word by inserting the most recently used word that begins with the  ;; word by inserting the most recently used word that begins with the
47  ;; same characters.  If you press meta-return repeatedly, it cycles  ;; same characters.  If you press meta-return repeatedly, it cycles
48  ;; through all the words it knows about.  ;; through all the words it knows about.
49  ;;  ;;
50  ;;  If you like the completion then just continue typing, it is as if you  ;;  If you like the completion then just continue typing, it is as if you
51  ;; entered the text by hand.  If you want the inserted extra characters  ;; entered the text by hand.  If you want the inserted extra characters
52  ;; to go away, type control-w or delete.  More options are described below.  ;; to go away, type control-w or delete.  More options are described below.
53  ;;  ;;
54  ;;  The guesses are made in the order of the most recently "used".  Typing  ;;  The guesses are made in the order of the most recently "used".  Typing
55  ;; in a word and then typing a separator character (such as a space) "uses"  ;; in a word and then typing a separator character (such as a space) "uses"
56  ;; the word.  So does moving a cursor over the word.  If no words are found,  ;; the word.  So does moving a cursor over the word.  If no words are found,
57  ;; it uses an extended version of the dabbrev style completion.  ;; it uses an extended version of the dabbrev style completion.
58  ;;  ;;
59  ;;   You automatically save the completions you use to a file between  ;;   You automatically save the completions you use to a file between
60  ;; sessions.    ;; sessions.
61  ;;  ;;
62  ;;   Completion enables programmers to enter longer, more descriptive  ;;   Completion enables programmers to enter longer, more descriptive
63  ;; variable names while typing fewer keystrokes than they normally would.  ;; variable names while typing fewer keystrokes than they normally would.
64  ;;  ;;
65  ;;  ;;
66  ;; Full documentation  ;; Full documentation
67  ;;---------------------  ;;---------------------
68  ;;  ;;
69  ;;   A "word" is any string containing characters with either word or symbol  ;;   A "word" is any string containing characters with either word or symbol
70  ;; syntax.  [E.G. Any alphanumeric string with hyphens, underscores, etc.]  ;; syntax.  [E.G. Any alphanumeric string with hyphens, underscores, etc.]
71  ;; Unless you change the constants, you must type at least three characters  ;; Unless you change the constants, you must type at least three characters
72  ;; for the word to be recognized.  Only words longer than 6 characters are  ;; for the word to be recognized.  Only words longer than 6 characters are
# Line 82  Line 82 
82  ;;   Completions are automatically saved from one session to another  ;;   Completions are automatically saved from one session to another
83  ;; (unless save-completions-flag or enable-completion is nil).  ;; (unless save-completions-flag or enable-completion is nil).
84  ;; Loading this file (or calling initialize-completions) causes EMACS  ;; Loading this file (or calling initialize-completions) causes EMACS
85  ;; to load a completions database for a saved completions file  ;; to load a completions database for a saved completions file
86  ;; (default: ~/.completions).  When you exit, EMACS saves a copy of the  ;; (default: ~/.completions).  When you exit, EMACS saves a copy of the
87  ;; completions that you  ;; completions that you
88  ;; often use.  When you next start, EMACS loads in the saved completion file.  ;; often use.  When you next start, EMACS loads in the saved completion file.
89  ;;  ;;
90  ;;   The number of completions saved depends loosely on  ;;   The number of completions saved depends loosely on
91  ;; *saved-completions-decay-factor*.  Completions that have never been  ;; *saved-completions-decay-factor*.  Completions that have never been
92  ;; inserted via "complete" are not saved.  You are encouraged to experiment  ;; inserted via "complete" are not saved.  You are encouraged to experiment
93  ;; with different functions (see compute-completion-min-num-uses).  ;; with different functions (see compute-completion-min-num-uses).
94  ;;  ;;
95  ;;   Some completions are permanent and are always saved out.  These  ;;   Some completions are permanent and are always saved out.  These
96  ;; completions have their num-uses slot set to T.  Use  ;; completions have their num-uses slot set to T.  Use
97  ;; add-permanent-completion to do this  ;; add-permanent-completion to do this
98  ;;  ;;
99  ;;   Completions are saved only if enable-completion is T.  The number of old  ;;   Completions are saved only if enable-completion is T.  The number of old
100  ;; versions kept of the saved completions file is controlled by  ;; versions kept of the saved completions file is controlled by
101  ;; completions-file-versions-kept.  ;; completions-file-versions-kept.
102  ;;  ;;
103  ;; COMPLETE KEY OPTIONS  ;; COMPLETE KEY OPTIONS
104  ;;   The complete function takes a numeric arguments.    ;;   The complete function takes a numeric arguments.
105  ;;  control-u :: leave the point at the beginning of the completion rather  ;;  control-u :: leave the point at the beginning of the completion rather
106  ;;               than the middle.  ;;               than the middle.
107  ;;  a number  :: rotate through the possible completions by that amount  ;;  a number  :: rotate through the possible completions by that amount
108  ;;  `-'       :: same as -1 (insert previous completion)  ;;  `-'       :: same as -1 (insert previous completion)
# Line 111  Line 111 
111  ;;  <write>  ;;  <write>
112  ;;  ;;
113  ;; UPDATING THE DATABASE MANUALLY  ;; UPDATING THE DATABASE MANUALLY
114  ;;   m-x kill-completion  ;;   m-x kill-completion
115  ;;     kills the completion at point.  ;;     kills the completion at point.
116  ;;   m-x add-completion  ;;   m-x add-completion
117  ;;   m-x add-permanent-completion  ;;   m-x add-permanent-completion
118  ;;    ;;
119  ;; UPDATING THE DATABASE FROM A SOURCE CODE FILE  ;; UPDATING THE DATABASE FROM A SOURCE CODE FILE
120  ;;   m-x add-completions-from-buffer  ;;   m-x add-completions-from-buffer
121  ;;     Parses all the definition names from a C or LISP mode buffer and  ;;     Parses all the definition names from a C or LISP mode buffer and
122  ;;     adds them to the completion database.  ;;     adds them to the completion database.
123  ;;  ;;
124  ;;   m-x add-completions-from-lisp-file  ;;   m-x add-completions-from-lisp-file
125  ;;     Parses all the definition names from a C or Lisp mode file and  ;;     Parses all the definition names from a C or Lisp mode file and
126  ;;     adds them to the completion database.  ;;     adds them to the completion database.
127  ;;  ;;
# Line 133  Line 133 
133  ;;  <write>  ;;  <write>
134  ;;  ;;
135  ;; STRING CASING  ;; STRING CASING
136  ;;   Completion is string case independent if case-fold-search has its  ;;   Completion is string case independent if case-fold-search has its
137  ;;  normal default of T.  Also when the completion is inserted the case of the  ;;  normal default of T.  Also when the completion is inserted the case of the
138  ;;  entry is coerced appropriately.    ;;  entry is coerced appropriately.
139  ;;  [E.G.  APP --> APPROPRIATELY     app --> appropriately    ;;  [E.G.  APP --> APPROPRIATELY     app --> appropriately
140  ;;         App --> Appropriately]  ;;         App --> Appropriately]
141  ;;  ;;
142  ;; INITIALIZATION  ;; INITIALIZATION
143  ;;  The form `(initialize-completions)' initializes the completion system by  ;;  The form `(initialize-completions)' initializes the completion system by
144  ;; trying to load in the user's completions.  After the first cal, further  ;; trying to load in the user's completions.  After the first cal, further
145  ;; calls have no effect so one should be careful not to put the form in a  ;; calls have no effect so one should be careful not to put the form in a
146  ;; site's standard site-init file.  ;; site's standard site-init file.
147  ;;  ;;
148  ;;---------------------------------------------------------------------------  ;;---------------------------------------------------------------------------
# Line 180  Line 180 
180  ;;    Inserts a completion at point  ;;    Inserts a completion at point
181  ;;  ;;
182  ;;  initialize-completions  ;;  initialize-completions
183  ;;    Loads the completions file and sets up so that exiting emacs will  ;;    Loads the completions file and sets up so that exiting emacs will
184  ;;  save them.  ;;  save them.
185  ;;  ;;
186  ;;  save-completions-to-file &optional filename    ;;  save-completions-to-file &optional filename
187  ;;  load-completions-from-file &optional filename  ;;  load-completions-from-file &optional filename
188  ;;  ;;
189  ;;-----------------------------------------------  ;;-----------------------------------------------
# Line 194  Line 194 
194  ;;  ;;
195  ;; These things are for manipulating the structure  ;; These things are for manipulating the structure
196  ;;  make-completion string num-uses  ;;  make-completion string num-uses
197  ;;  completion-num-uses completion  ;;  completion-num-uses completion
198  ;;  completion-string completion  ;;  completion-string completion
199  ;;  set-completion-num-uses completion num-uses  ;;  set-completion-num-uses completion num-uses
200  ;;  set-completion-string completion string  ;;  set-completion-string completion string
201  ;;    ;;
202  ;;  ;;
203    
204  ;;-----------------------------------------------  ;;-----------------------------------------------
# Line 215  Line 215 
215  ;;-----------------------------------------------  ;;-----------------------------------------------
216  ;;; Change Log:  ;;; Change Log:
217  ;;-----------------------------------------------  ;;-----------------------------------------------
218  ;;    Sometime in '84 Brewster implemented a somewhat buggy version for  ;;    Sometime in '84 Brewster implemented a somewhat buggy version for
219  ;; Symbolics LISPMs.  ;; Symbolics LISPMs.
220  ;;    Jan. '85 Jim became enamored of the idea and implemented a faster,  ;;    Jan. '85 Jim became enamored of the idea and implemented a faster,
221  ;; more robust version.  ;; more robust version.
222  ;;    With input from many users at TMC, (rose, craig, and gls come to mind),  ;;    With input from many users at TMC, (rose, craig, and gls come to mind),
223  ;; the current style of interface was developed.  ;; the current style of interface was developed.
224  ;;    9/87, Jim and Brewster took terminals home.  Yuck.  After  ;;    9/87, Jim and Brewster took terminals home.  Yuck.  After
225  ;; complaining for a while Brewster implemented a subset of the current  ;; complaining for a while Brewster implemented a subset of the current
226  ;; LISPM version for GNU Emacs.    ;; LISPM version for GNU Emacs.
227  ;;    8/88  After complaining for a while (and with sufficient  ;;    8/88  After complaining for a while (and with sufficient
228  ;; promised rewards), Jim reimplemented a version of GNU completion  ;; promised rewards), Jim reimplemented a version of GNU completion
229  ;; superior to that of the LISPM version.  ;; superior to that of the LISPM version.
230  ;;  ;;
# Line 269  Line 269 
269  ;;  - minor fix to capitalization code  ;;  - minor fix to capitalization code
270  ;;  - added *completion-auto-save-period* to variables recorded.  ;;  - added *completion-auto-save-period* to variables recorded.
271  ;;  - added reenter protection to cmpl-record-statistics-filter  ;;  - added reenter protection to cmpl-record-statistics-filter
272  ;;  - added backup protection to save-completions-to-file (prevents  ;;  - added backup protection to save-completions-to-file (prevents
273  ;;    problems with disk full errors)  ;;    problems with disk full errors)
274    
275  ;;; Code:  ;;; Code:
# Line 375  DON'T CHANGE WITHOUT RECOMPILING !  This Line 375  DON'T CHANGE WITHOUT RECOMPILING !  This
375     (setq completion-prefix-min-length 3)))     (setq completion-prefix-min-length 3)))
376    
377  (completion-eval-when)  (completion-eval-when)
378    
379  ;;---------------------------------------------------------------------------  ;;---------------------------------------------------------------------------
380  ;; Internal Variables  ;; Internal Variables
381  ;;---------------------------------------------------------------------------  ;;---------------------------------------------------------------------------
# Line 476  Used to decide whether to save completio Line 476  Used to decide whether to save completio
476  ;; of syntax in these "symbol" syntax tables ::  ;; of syntax in these "symbol" syntax tables ::
477  ;;  ;;
478  ;; syntax (?_) - "symbol" chars (e.g. alphanumerics)  ;; syntax (?_) - "symbol" chars (e.g. alphanumerics)
479  ;; syntax (?w) - symbol chars to ignore at end of words (e.g. period).    ;; syntax (?w) - symbol chars to ignore at end of words (e.g. period).
480  ;; syntax (? ) - everything else  ;; syntax (? ) - everything else
481  ;;  ;;
482  ;; Thus by judicious use of scan-sexps and forward-word, we can get  ;; Thus by judicious use of scan-sexps and forward-word, we can get
483  ;; the word we want relatively fast and without consing.    ;; the word we want relatively fast and without consing.
484  ;;  ;;
485  ;; Why do we need a separate category for "symbol chars to ignore at ends" ?  ;; Why do we need a separate category for "symbol chars to ignore at ends" ?
486  ;; For example, in LISP we want starting :'s trimmed  ;; For example, in LISP we want starting :'s trimmed
487  ;; so keyword argument specifiers also define the keyword completion.  And,  ;; so keyword argument specifiers also define the keyword completion.  And,
488  ;; for example, in C we want `.' appearing in a structure ref. to  ;; for example, in C we want `.' appearing in a structure ref. to
489  ;; be kept intact in order to store the whole structure ref.; however, if  ;; be kept intact in order to store the whole structure ref.; however, if
490  ;; it appears at the end of a symbol it should be discarded because it is  ;; it appears at the end of a symbol it should be discarded because it is
491  ;; probably used as a period.  ;; probably used as a period.
492    
# Line 503  Used to decide whether to save completio Line 503  Used to decide whether to save completio
503  ;; C diffs ->  ;; C diffs ->
504  ;;   Separator chars :: + * / : %  ;;   Separator chars :: + * / : %
505  ;;  A note on the hyphen (`-').  Perhaps the hyphen should also be a separator  ;;  A note on the hyphen (`-').  Perhaps the hyphen should also be a separator
506  ;; char., however, we wanted to have completion symbols include pointer  ;; char., however, we wanted to have completion symbols include pointer
507  ;; references.  For example, "foo->bar" is a symbol as far as completion is  ;; references.  For example, "foo->bar" is a symbol as far as completion is
508  ;; concerned.  ;; concerned.
509  ;;  ;;
# Line 556  Used to decide whether to save completio Line 556  Used to decide whether to save completio
556      (dolist (char symbol-chars)      (dolist (char symbol-chars)
557        (modify-syntax-entry char "_" table))        (modify-syntax-entry char "_" table))
558      table))      table))
559              
560  (defun cmpl-make-c-completion-syntax-table ()  (defun cmpl-make-c-completion-syntax-table ()
561    (let ((table (copy-syntax-table cmpl-standard-syntax-table))    (let ((table (copy-syntax-table cmpl-standard-syntax-table))
562          (separator-chars '(?+ ?* ?/ ?: ?%)))          (separator-chars '(?+ ?* ?/ ?: ?%)))
# Line 598  But only if it is longer than `completio Line 598  But only if it is longer than `completio
598    (unwind-protect    (unwind-protect
599        (progn        (progn
600          (set-syntax-table cmpl-syntax-table)          (set-syntax-table cmpl-syntax-table)
601          (cond          (cond
602          ;; Cursor is on following-char and after preceding-char          ;; Cursor is on following-char and after preceding-char
603            ((memq (char-syntax (following-char)) '(?w ?_))                ((memq (char-syntax (following-char)) '(?w ?_))
604             (setq cmpl-saved-point (point)             (setq cmpl-saved-point (point)
605                   cmpl-symbol-start (scan-sexps (1+ cmpl-saved-point) -1)                   cmpl-symbol-start (scan-sexps (1+ cmpl-saved-point) -1)
606                   cmpl-symbol-end (scan-sexps cmpl-saved-point 1))                   cmpl-symbol-end (scan-sexps cmpl-saved-point 1))
# Line 638  But only if it is longer than `completio Line 638  But only if it is longer than `completio
638    
639  (defun symbol-before-point ()  (defun symbol-before-point ()
640    "Returns a string of the symbol immediately before point.    "Returns a string of the symbol immediately before point.
641  Returns nil if there isn't one longer than `completion-min-length'."        Returns nil if there isn't one longer than `completion-min-length'."
642    ;; This is called when a word separator is typed so it must be FAST !    ;; This is called when a word separator is typed so it must be FAST !
643    (setq cmpl-saved-syntax (syntax-table))    (setq cmpl-saved-syntax (syntax-table))
644    (unwind-protect    (unwind-protect
# Line 774  Returns nil if there isn't one longer th Line 774  Returns nil if there isn't one longer th
774  ;;  "Only executes body if we are recording statistics."  ;;  "Only executes body if we are recording statistics."
775  ;;  (list 'cond  ;;  (list 'cond
776  ;;      (list* '*record-cmpl-statistics-p* body)  ;;      (list* '*record-cmpl-statistics-p* body)
777  ;;      ))                ;;      ))
778    
779  ;;-----------------------------------------------  ;;-----------------------------------------------
780  ;; Completion Sources  ;; Completion Sources
# Line 797  Returns nil if there isn't one longer th Line 797  Returns nil if there isn't one longer th
797  ;; Completion Method #2: dabbrev-expand style  ;; Completion Method #2: dabbrev-expand style
798  ;;---------------------------------------------------------------------------  ;;---------------------------------------------------------------------------
799  ;;  ;;
800  ;;   This method is used if there are no useful stored completions.  It is  ;;   This method is used if there are no useful stored completions.  It is
801  ;; based on dabbrev-expand with these differences :  ;; based on dabbrev-expand with these differences :
802  ;;   1) Faster (we don't use regexps)  ;;   1) Faster (we don't use regexps)
803  ;;   2) case coercion handled correctly  ;;   2) case coercion handled correctly
# Line 880  This is sensitive to `case-fold-search'. Line 880  This is sensitive to `case-fold-search'.
880    ;; note that case-fold-search affects the behavior of this function    ;; note that case-fold-search affects the behavior of this function
881    ;; Bug: won't pick up an expansion that starts at the top of buffer    ;; Bug: won't pick up an expansion that starts at the top of buffer
882    (if cdabbrev-current-window    (if cdabbrev-current-window
883        (let (saved-point        (let (saved-point
884              saved-syntax              saved-syntax
885              (expansion nil)              (expansion nil)
886              downcase-expansion tried-list syntax saved-point-2)              downcase-expansion tried-list syntax saved-point-2)
# Line 1004  Each symbol is bound to a single complet Line 1004  Each symbol is bound to a single complet
1004  ;; last-use-time is t if the string should be kept permanently  ;; last-use-time is t if the string should be kept permanently
1005  ;; num-uses is incremented every time the completion is used.  ;; num-uses is incremented every time the completion is used.
1006    
1007  ;; We chose lists because (car foo) is faster than (aref foo 0) and the  ;; We chose lists because (car foo) is faster than (aref foo 0) and the
1008  ;; creation time is about the same.  ;; creation time is about the same.
1009    
1010  ;; READER MACROS  ;; READER MACROS
# Line 1013  Each symbol is bound to a single complet Line 1013  Each symbol is bound to a single complet
1013    (list 'car completion-entry))    (list 'car completion-entry))
1014    
1015  (defmacro completion-num-uses (completion-entry)  (defmacro completion-num-uses (completion-entry)
1016    ;;  "The number of times it has used.  Used to decide whether to save    ;;  "The number of times it has used.  Used to decide whether to save
1017    ;; it."    ;; it."
1018    (list 'car (list 'cdr completion-entry)))    (list 'car (list 'cdr completion-entry)))
1019    
# Line 1291  Returns the completion entry." Line 1291  Returns the completion entry."
1291          (note-added-completion))          (note-added-completion))
1292        ;; Add it to the symbol        ;; Add it to the symbol
1293        (set cmpl-db-symbol (car entry)))))        (set cmpl-db-symbol (car entry)))))
1294          
1295  (defun delete-completion (completion-string)  (defun delete-completion (completion-string)
1296    "Delete the completion from the database.    "Delete the completion from the database.
1297  String must be longer than `completion-prefix-min-length'."  String must be longer than `completion-prefix-min-length'."
# Line 1299  String must be longer than `completion-p Line 1299  String must be longer than `completion-p
1299    (if completion-to-accept (accept-completion))    (if completion-to-accept (accept-completion))
1300    (if (setq cmpl-db-entry (find-exact-completion completion-string))    (if (setq cmpl-db-entry (find-exact-completion completion-string))
1301        ;; found        ;; found
1302        (let* ((prefix-entry (find-cmpl-prefix-entry        (let* ((prefix-entry (find-cmpl-prefix-entry
1303                               (substring cmpl-db-downcase-string 0                               (substring cmpl-db-downcase-string 0
1304                                          (cmpl-read-time-eval                                          (cmpl-read-time-eval
1305                                           completion-prefix-min-length))))                                           completion-prefix-min-length))))
# Line 1339  String must be longer than `completion-p Line 1339  String must be longer than `completion-p
1339  ;;  ;;
1340  ;;  - Deleting -  ;;  - Deleting -
1341  ;; (add-completion-to-head "banner")     --> ("banner" 0 nil 0)  ;; (add-completion-to-head "banner")     --> ("banner" 0 nil 0)
1342  ;; (delete-completion "banner")          ;; (delete-completion "banner")
1343  ;; (find-exact-completion "banner")      --> nil  ;; (find-exact-completion "banner")      --> nil
1344  ;; (car (find-cmpl-prefix-entry "ban"))  --> (("banana" ...) ("banish" ...))  ;; (car (find-cmpl-prefix-entry "ban"))  --> (("banana" ...) ("banish" ...))
1345  ;; (cdr (find-cmpl-prefix-entry "ban"))  --> (("banish" ...))  ;; (cdr (find-cmpl-prefix-entry "ban"))  --> (("banish" ...))
1346  ;; (add-completion-to-head "banner")     --> ("banner" 0 nil 0)  ;; (add-completion-to-head "banner")     --> ("banner" 0 nil 0)
1347  ;; (delete-completion "banana")          ;; (delete-completion "banana")
1348  ;; (car (find-cmpl-prefix-entry "ban"))  --> (("banner" ...) ("banish" ...))  ;; (car (find-cmpl-prefix-entry "ban"))  --> (("banner" ...) ("banish" ...))
1349  ;; (cdr (find-cmpl-prefix-entry "ban"))  --> (("banish" ...))  ;; (cdr (find-cmpl-prefix-entry "ban"))  --> (("banish" ...))
1350  ;; (delete-completion "banner")          ;; (delete-completion "banner")
1351  ;; (delete-completion "banish")                  ;; (delete-completion "banish")
1352  ;; (find-cmpl-prefix-entry "ban")        --> nil  ;; (find-cmpl-prefix-entry "ban")        --> nil
1353  ;; (delete-completion "banner")          --> error  ;; (delete-completion "banner")          --> error
1354  ;;  ;;
# Line 1365  String must be longer than `completion-p Line 1365  String must be longer than `completion-p
1365  ;;---------------------------------------------------------------------------  ;;---------------------------------------------------------------------------
1366  ;; Database Update :: Interface level routines  ;; Database Update :: Interface level routines
1367  ;;---------------------------------------------------------------------------  ;;---------------------------------------------------------------------------
1368  ;;  ;;
1369  ;; These lie on top of the database ref. functions but below the standard  ;; These lie on top of the database ref. functions but below the standard
1370  ;; user interface level  ;; user interface level
1371    
# Line 1388  String must be longer than `completion-p Line 1388  String must be longer than `completion-p
1388    
1389  (defun add-completion (string &optional num-uses last-use-time)  (defun add-completion (string &optional num-uses last-use-time)
1390    "Add STRING to completion list, or move it to head of list.    "Add STRING to completion list, or move it to head of list.
1391  The completion is altered appropriately if num-uses and/or last-use-time is  The completion is altered appropriately if num-uses and/or last-use-time is
1392  specified."  specified."
1393    (interactive (interactive-completion-string-reader "Completion to add"))    (interactive (interactive-completion-string-reader "Completion to add"))
1394    (check-completion-length string)    (check-completion-length string)
# Line 1396  specified." Line 1396  specified."
1396                                          cmpl-source-interactive                                          cmpl-source-interactive
1397                                          current-completion-source))                                          current-completion-source))
1398           (entry (add-completion-to-head string)))           (entry (add-completion-to-head string)))
1399        
1400      (if num-uses (set-completion-num-uses entry num-uses))      (if num-uses (set-completion-num-uses entry num-uses))
1401      (if last-use-time      (if last-use-time
1402          (set-completion-last-use-time entry last-use-time))))          (set-completion-last-use-time entry last-use-time))))
# Line 1417  specified." Line 1417  specified."
1417    
1418  (defun accept-completion ()  (defun accept-completion ()
1419    "Accepts the pending completion in `completion-to-accept'.    "Accepts the pending completion in `completion-to-accept'.
1420  This bumps num-uses.  Called by `add-completion-to-head' and  This bumps num-uses.  Called by `add-completion-to-head' and
1421  `completion-search-reset'."  `completion-search-reset'."
1422    (let ((string completion-to-accept)    (let ((string completion-to-accept)
1423          ;; if this is added afresh here, then it must be a cdabbrev          ;; if this is added afresh here, then it must be a cdabbrev
# Line 1433  This bumps num-uses.  Called by `add-com Line 1433  This bumps num-uses.  Called by `add-com
1433    (let ((string (and enable-completion (symbol-under-point)))    (let ((string (and enable-completion (symbol-under-point)))
1434          (current-completion-source cmpl-source-cursor-moves))          (current-completion-source cmpl-source-cursor-moves))
1435      (if string (add-completion-to-head string))))      (if string (add-completion-to-head string))))
1436            
1437  (defun use-completion-before-point ()  (defun use-completion-before-point ()
1438    "Add the completion symbol before point into the completion buffer."    "Add the completion symbol before point into the completion buffer."
1439    (let ((string (and enable-completion (symbol-before-point)))    (let ((string (and enable-completion (symbol-before-point)))
# Line 1465  Completions added this way will automati Line 1465  Completions added this way will automati
1465    
1466  ;; Tests --  ;; Tests --
1467  ;;  - Add and Find -  ;;  - Add and Find -
1468  ;; (add-completion "banana" 5 10)    ;; (add-completion "banana" 5 10)
1469  ;; (find-exact-completion "banana")  --> ("banana" 5 10 0)  ;; (find-exact-completion "banana")  --> ("banana" 5 10 0)
1470  ;; (add-completion "banana" 6)      ;; (add-completion "banana" 6)
1471  ;; (find-exact-completion "banana")  --> ("banana" 6 10 0)  ;; (find-exact-completion "banana")  --> ("banana" 6 10 0)
1472  ;; (add-completion "banish")  ;; (add-completion "banish")
1473  ;; (car (find-cmpl-prefix-entry "ban"))  --> (("banish" ...) ("banana" ...))  ;; (car (find-cmpl-prefix-entry "ban"))  --> (("banish" ...) ("banana" ...))
1474  ;;  ;;
1475  ;;  - Accepting -  ;;  - Accepting -
1476  ;; (setq completion-to-accept "banana")  ;; (setq completion-to-accept "banana")
1477  ;; (accept-completion)                    ;; (accept-completion)
1478  ;; (find-exact-completion "banana")      --> ("banana" 7 10)  ;; (find-exact-completion "banana")      --> ("banana" 7 10)
1479  ;; (car (find-cmpl-prefix-entry "ban"))  --> (("banana" ...) ("banish" ...))  ;; (car (find-cmpl-prefix-entry "ban"))  --> (("banana" ...) ("banish" ...))
1480  ;; (setq completion-to-accept "banish")  ;; (setq completion-to-accept "banish")
1481  ;; (add-completion "banner")            ;; (add-completion "banner")
1482  ;; (car (find-cmpl-prefix-entry "ban"))  ;; (car (find-cmpl-prefix-entry "ban"))
1483  ;;        --> (("banner" ...) ("banish" 1 ...) ("banana" 7 ...))  ;;        --> (("banner" ...) ("banish" 1 ...) ("banana" 7 ...))
1484  ;;  ;;
1485  ;;  - Deleting -  ;;  - Deleting -
1486  ;; (kill-completion "banish")            ;; (kill-completion "banish")
1487  ;; (car (find-cmpl-prefix-entry "ban"))  --> (("banner" ...) ("banana" ...))  ;; (car (find-cmpl-prefix-entry "ban"))  --> (("banner" ...) ("banana" ...))
1488    
1489    
# Line 1499  Completions added this way will automati Line 1499  Completions added this way will automati
1499  (defvar cmpl-test-string "")  (defvar cmpl-test-string "")
1500  ;;  "The current string used by completion-search-next."  ;;  "The current string used by completion-search-next."
1501  (defvar cmpl-test-regexp "")  (defvar cmpl-test-regexp "")
1502  ;;  "The current regexp used by completion-search-next.  ;;  "The current regexp used by completion-search-next.
1503  ;;   (derived from cmpl-test-string)"  ;;   (derived from cmpl-test-string)"
1504  (defvar cmpl-last-index 0)  (defvar cmpl-last-index 0)
1505  ;;  "The last index that completion-search-next was called with."  ;;  "The last index that completion-search-next was called with."
# Line 1554  If there are no more entries, try cdabbr Line 1554  If there are no more entries, try cdabbr
1554       (cond ((not cmpl-next-possibilities))       (cond ((not cmpl-next-possibilities))
1555              ;; If no more possibilities, leave it that way              ;; If no more possibilities, leave it that way
1556             ((= -1 cmpl-last-index)             ((= -1 cmpl-last-index)
1557              ;; next completion is at index 0.  reset next-possibility list              ;; next completion is at index 0.  reset next-possibility list
1558              ;; to start at beginning              ;; to start at beginning
1559              (setq cmpl-next-possibilities cmpl-starting-possibilities))              (setq cmpl-next-possibilities cmpl-starting-possibilities))
1560             (t             (t
# Line 1574  If there are no more entries, try cdabbr Line 1574  If there are no more entries, try cdabbr
1574    (prog1    (prog1
1575        cmpl-next-possibility        cmpl-next-possibility
1576      (setq cmpl-next-possibility nil)))      (setq cmpl-next-possibility nil)))
1577          
1578    
1579  (defun completion-search-peek (use-cdabbrev)  (defun completion-search-peek (use-cdabbrev)
1580    "Returns the next completion entry without actually moving the pointers.    "Returns the next completion entry without actually moving the pointers.
1581  Calling this again or calling `completion-search-next' results in the same  Calling this again or calling `completion-search-next' results in the same
1582  string being returned.  Depends on `case-fold-search'.  string being returned.  Depends on `case-fold-search'.
1583  If there are no more entries, try cdabbrev and then return only a string."  If there are no more entries, try cdabbrev and then return only a string."
1584    (cond    (cond
# Line 1609  If there are no more entries, try cdabbr Line 1609  If there are no more entries, try cdabbr
1609    
1610  ;; Tests --  ;; Tests --
1611  ;;  - Add and Find -  ;;  - Add and Find -
1612  ;; (add-completion "banana")        ;; (add-completion "banana")
1613  ;; (completion-search-reset "ban")    ;; (completion-search-reset "ban")
1614  ;; (completion-search-next 0)        --> "banana"  ;; (completion-search-next 0)        --> "banana"
1615  ;;  ;;
1616  ;;  - Discrimination -  ;;  - Discrimination -
1617  ;; (add-completion "cumberland")        ;; (add-completion "cumberland")
1618  ;; (add-completion "cumberbund")        ;; (add-completion "cumberbund")
1619  ;; cumbering    ;; cumbering
1620  ;; (completion-search-reset "cumb")  ;; (completion-search-reset "cumb")
1621  ;; (completion-search-peek t)        --> "cumberbund"  ;; (completion-search-peek t)        --> "cumberbund"
1622  ;; (completion-search-next 0)        --> "cumberbund"  ;; (completion-search-next 0)        --> "cumberbund"
# Line 1637  If there are no more entries, try cdabbr Line 1637  If there are no more entries, try cdabbr
1637  ;;  ;;
1638  ;;  - Deleting -  ;;  - Deleting -
1639  ;; (kill-completion "cumberland")  ;; (kill-completion "cumberland")
1640  ;; cummings      ;; cummings
1641  ;; (completion-search-reset "cum")  ;; (completion-search-reset "cum")
1642  ;; (completion-search-next 0)        --> "cumberbund"  ;; (completion-search-next 0)        --> "cumberbund"
1643  ;; (completion-search-next 1)        --> "cummings"  ;; (completion-search-next 1)        --> "cummings"
# Line 1657  If there are no more entries, try cdabbr Line 1657  If there are no more entries, try cdabbr
1657    (interactive)    (interactive)
1658    (setq enable-completion (not enable-completion))    (setq enable-completion (not enable-completion))
1659    (message "Completion mode is now %s." (if enable-completion "ON" "OFF")))    (message "Completion mode is now %s." (if enable-completion "ON" "OFF")))
1660            
1661  (defvar cmpl-current-index 0)  (defvar cmpl-current-index 0)
1662  (defvar cmpl-original-string nil)  (defvar cmpl-original-string nil)
1663  (defvar cmpl-last-insert-location -1)  (defvar cmpl-last-insert-location -1)
1664  (defvar cmpl-leave-point-at-start nil)  (defvar cmpl-leave-point-at-start nil)
1665    
1666  (defun complete (&optional arg)  (defun complete (&optional arg)
1667    "Fill out a completion of the word before point.      "Fill out a completion of the word before point.
1668  Point is left at end.  Consecutive calls rotate through all possibilities.  Point is left at end.  Consecutive calls rotate through all possibilities.
1669  Prefix args ::  Prefix args ::
1670    control-u :: leave the point at the beginning of the completion rather    control-u :: leave the point at the beginning of the completion rather
1671                 than at the end.                 than at the end.
1672    a number  :: rotate through the possible completions by that amount    a number  :: rotate through the possible completions by that amount
1673    `-'       :: same as -1 (insert previous completion)    `-'       :: same as -1 (insert previous completion)
# Line 1693  Prefix args :: Line 1693  Prefix args ::
1693                  (setq this-command 'failed-complete)                  (setq this-command 'failed-complete)
1694                  (error "To complete, point must be after a symbol at least %d character long"                  (error "To complete, point must be after a symbol at least %d character long"
1695                         completion-prefix-min-length)))                         completion-prefix-min-length)))
1696           ;; get index                   ;; get index
1697           (setq cmpl-current-index (if current-prefix-arg arg 0))           (setq cmpl-current-index (if current-prefix-arg arg 0))
1698           ;; statistics           ;; statistics
1699           (cmpl-statistics-block           (cmpl-statistics-block
# Line 1748  Prefix args :: Line 1748  Prefix args ::
1748                (setq string (cmpl-merge-string-cases                (setq string (cmpl-merge-string-cases
1749                               string cmpl-original-string))                               string cmpl-original-string))
1750                (message "Next completion: %s" string))))                (message "Next completion: %s" string))))
1751            (t;; none found, insert old            (t;; none found, insert old
1752             (insert cmpl-original-string)             (insert cmpl-original-string)
1753             ;; Don't accept completions             ;; Don't accept completions
1754             (setq completion-to-accept nil)             (setq completion-to-accept nil)
# Line 1862  Prefix args :: Line 1862  Prefix args ::
1862  ;;  (and (string-match *lisp-def-regexp* "\n(def-bar foo")(match-end 0)) -> 10  ;;  (and (string-match *lisp-def-regexp* "\n(def-bar foo")(match-end 0)) -> 10
1863  ;;  (and (string-match *lisp-def-regexp* "\n(defun (foo") (match-end 0)) -> 9  ;;  (and (string-match *lisp-def-regexp* "\n(defun (foo") (match-end 0)) -> 9
1864    
1865  ;; Parses all the definition names from a Lisp mode buffer and adds them to  ;; Parses all the definition names from a Lisp mode buffer and adds them to
1866  ;; the completion database.  ;; the completion database.
1867  (defun add-completions-from-lisp-buffer ()  (defun add-completions-from-lisp-buffer ()
1868    ;;; Benchmarks    ;;; Benchmarks
# Line 1955  Prefix args :: Line 1955  Prefix args ::
1955  ;;  (test-c-def-regexp *c-cont-regexp* "oo {trout =1} my_carp;") -> 14  ;;  (test-c-def-regexp *c-cont-regexp* "oo {trout =1} my_carp;") -> 14
1956  ;;  (test-c-def-regexp *c-cont-regexp* "truct_p complex foon") -> nil  ;;  (test-c-def-regexp *c-cont-regexp* "truct_p complex foon") -> nil
1957    
1958  ;; Parses all the definition names from a C mode buffer and adds them to the  ;; Parses all the definition names from a C mode buffer and adds them to the
1959  ;; completion database.  ;; completion database.
1960  (defun add-completions-from-c-buffer ()  (defun add-completions-from-c-buffer ()
1961    ;; Benchmark --    ;; Benchmark --
# Line 2089  If file name is not specified, use `save Line 2089  If file name is not specified, use `save
2089                 (total-perm 0)                 (total-perm 0)
2090                 (total-saved 0)                 (total-saved 0)
2091                 (backup-filename (completion-backup-filename filename)))                 (backup-filename (completion-backup-filename filename)))
2092        
2093            (save-excursion            (save-excursion
2094              (get-buffer-create " *completion-save-buffer*")              (get-buffer-create " *completion-save-buffer*")
2095              (set-buffer  " *completion-save-buffer*")              (set-buffer  " *completion-save-buffer*")
# Line 2130  If file name is not specified, use `save Line 2130  If file name is not specified, use `save
2130                       (setq total-saved (1+ total-saved))                       (setq total-saved (1+ total-saved))
2131                       (insert (prin1-to-string (cons (completion-string completion)                       (insert (prin1-to-string (cons (completion-string completion)
2132                                                      last-use-time)) "\n"))))                                                      last-use-time)) "\n"))))
2133            
2134              ;; write the buffer              ;; write the buffer
2135              (condition-case e              (condition-case e
2136                  (let ((file-exists-p (file-exists-p filename)))                  (let ((file-exists-p (file-exists-p filename)))
# Line 2139  If file name is not specified, use `save Line 2139  If file name is not specified, use `save
2139                          ;; If file exists . . .                          ;; If file exists . . .
2140                          ;; Save a backup(so GNU doesn't screw us when we're out of disk)                          ;; Save a backup(so GNU doesn't screw us when we're out of disk)
2141                          ;; (GNU leaves a 0 length file if it gets a disk full error!)                          ;; (GNU leaves a 0 length file if it gets a disk full error!)
2142                  
2143                          ;; If backup doesn't exit, Rename current to backup                          ;; If backup doesn't exit, Rename current to backup
2144                          ;;  {If backup exists the primary file is probably messed up}                          ;;  {If backup exists the primary file is probably messed up}
2145                          (or (file-exists-p backup-filename)                          (or (file-exists-p backup-filename)
# Line 2189  If file is not specified, then use `save Line 2189  If file is not specified, then use `save
2189              ;; prepare the buffer to be modified              ;; prepare the buffer to be modified
2190              (clear-visited-file-modtime)              (clear-visited-file-modtime)
2191              (erase-buffer)              (erase-buffer)
2192      
2193              (let ((insert-okay-p nil)              (let ((insert-okay-p nil)
2194                    (buffer (current-buffer))                    (buffer (current-buffer))
2195                    (current-time (cmpl-hours-since-origin))                    (current-time (cmpl-hours-since-origin))
# Line 2205  If file is not specified, then use `save Line 2205  If file is not specified, then use `save
2205                    (progn (insert-file-contents filename t)                    (progn (insert-file-contents filename t)
2206                           (setq insert-okay-p t))                           (setq insert-okay-p t))
2207    
2208                  (file-error                  (file-error
2209                   (message "File error trying to load completion file %s."                   (message "File error trying to load completion file %s."
2210                            filename)))                            filename)))
2211                ;; parse it                ;; parse it
2212                (if insert-okay-p                (if insert-okay-p
2213                    (progn                    (progn
2214                      (goto-char (point-min))                      (goto-char (point-min))
# Line 2234  If file is not specified, then use `save Line 2234  If file is not specified, then use `save
2234                                    (completion-last-use-time                                    (completion-last-use-time
2235                                     (setq cmpl-entry                                     (setq cmpl-entry
2236                                           (add-completion-to-tail-if-new string))))                                           (add-completion-to-tail-if-new string))))
2237                              (if (or (eq last-use-time t)                              (if (or (eq last-use-time t)
2238                                      (and (> last-use-time 1000);;backcompatibility                                      (and (> last-use-time 1000);;backcompatibility
2239                                           (not (eq cmpl-last-use-time t))                                           (not (eq cmpl-last-use-time t))
2240                                           (or (not cmpl-last-use-time)                                           (or (not cmpl-last-use-time)
# Line 2290  If the previous command was also a kill Line 2290  If the previous command was also a kill
2290  the text killed this time appends to the text killed last time  the text killed this time appends to the text killed last time
2291  to make one entry in the kill ring.  to make one entry in the kill ring.
2292  Patched to remove the most recent completion."  Patched to remove the most recent completion."
2293    (interactive "r")      (interactive "r")
2294    (cond ((eq last-command 'complete)    (cond ((eq last-command 'complete)
2295           (delete-region (point) cmpl-last-insert-location)           (delete-region (point) cmpl-last-insert-location)
2296           (insert cmpl-original-string)           (insert cmpl-original-string)
# Line 2311  Patched to remove the most recent comple Line 2311  Patched to remove the most recent comple
2311  ;; All common separators (eg. space "(" ")" """) characters go through a  ;; All common separators (eg. space "(" ")" """) characters go through a
2312  ;; function to add new words to the list of words to complete from:  ;; function to add new words to the list of words to complete from:
2313  ;;  COMPLETION-SEPARATOR-SELF-INSERT-COMMAND (arg).  ;;  COMPLETION-SEPARATOR-SELF-INSERT-COMMAND (arg).
2314  ;; If the character before this was an alpha-numeric then this adds the  ;; If the character before this was an alpha-numeric then this adds the
2315  ;; symbol before point to the completion list (using ADD-COMPLETION).  ;; symbol before point to the completion list (using ADD-COMPLETION).
2316    
2317  (defun completion-separator-self-insert-command (arg)  (defun completion-separator-self-insert-command (arg)
# Line 2330  Patched to remove the most recent comple Line 2330  Patched to remove the most recent comple
2330  ;; Wrapping Macro  ;; Wrapping Macro
2331  ;;-----------------------------------------------  ;;-----------------------------------------------
2332    
2333  ;; Note that because of the way byte compiling works, none of  ;; Note that because of the way byte compiling works, none of
2334  ;; the functions defined with this macro get byte compiled.  ;; the functions defined with this macro get byte compiled.
2335    
2336  (defmacro def-completion-wrapper (function-name type &optional new-name)  (defmacro def-completion-wrapper (function-name type &optional new-name)
# Line 2397  TYPE is the type of the wrapper to be ad Line 2397  TYPE is the type of the wrapper to be ad
2397    (define-key fortran-mode-map "/" 'completion-separator-self-insert-command))    (define-key fortran-mode-map "/" 'completion-separator-self-insert-command))
2398    
2399  ;;; Enable completion mode.  ;;; Enable completion mode.
2400      
2401  ;;;###autoload  ;;;###autoload
2402  (defun dynamic-completion-mode ()  (defun dynamic-completion-mode ()
2403    "Enable dynamic word-completion."    "Enable dynamic word-completion."
# Line 2522  TYPE is the type of the wrapper to be ad Line 2522  TYPE is the type of the wrapper to be ad
2522    
2523    ;; Tests --    ;; Tests --
2524    ;; foobarbiz    ;; foobarbiz
2525    ;; foobar    ;; foobar
2526    ;; fooquux    ;; fooquux
2527    ;; fooper    ;; fooper
2528    
2529    (cmpl-statistics-block    (cmpl-statistics-block

Legend:
Removed from v.1.45  
changed lines
  Added in v.1.46

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26