comparison lisp/hippie-exp.el @ 49549:99be3a1e2589

Cygwin support patch.
author Juanma Barranquero <lekktu@gmail.com>
date Fri, 31 Jan 2003 15:24:20 +0000
parents 7308bbc423d5
children 695cf19ef79e d7ddb3e565de
comparison
equal deleted inserted replaced
49548:8b1c605f8c9b 49549:99be3a1e2589
26 26
27 ;;; Commentary: 27 ;;; Commentary:
28 28
29 ;; `hippie-expand' is a single function for a lot of different kinds 29 ;; `hippie-expand' is a single function for a lot of different kinds
30 ;; of completions and expansions. Called repeatedly it tries all 30 ;; of completions and expansions. Called repeatedly it tries all
31 ;; possible completions in succession. 31 ;; possible completions in succession.
32 ;; Which kinds of completions to try, and in which order, is 32 ;; Which kinds of completions to try, and in which order, is
33 ;; determined by the contents of `hippie-expand-try-functions-list'. 33 ;; determined by the contents of `hippie-expand-try-functions-list'.
34 ;; Much customization of `hippie-expand' can be made by changing the 34 ;; Much customization of `hippie-expand' can be made by changing the
35 ;; order of, removing, or inserting new functions in this list. 35 ;; order of, removing, or inserting new functions in this list.
36 ;; Given a positive numeric argument, `hippie-expand' jumps directly 36 ;; Given a positive numeric argument, `hippie-expand' jumps directly
59 ;; which then gives the same behavior as the original `dabbrev-expand'. 59 ;; which then gives the same behavior as the original `dabbrev-expand'.
60 ;; The variable `hippie-expand-dabbrev-as-symbol' controls whether 60 ;; The variable `hippie-expand-dabbrev-as-symbol' controls whether
61 ;; characters of syntax '_' is considered part of the words to expand 61 ;; characters of syntax '_' is considered part of the words to expand
62 ;; dynamically. 62 ;; dynamically.
63 ;; See also the macro `make-hippie-expand-function' below. 63 ;; See also the macro `make-hippie-expand-function' below.
64 ;; 64 ;;
65 ;; A short description of the current try-functions in this file: 65 ;; A short description of the current try-functions in this file:
66 ;; `try-complete-file-name' : very convenient to have in any buffer, 66 ;; `try-complete-file-name' : very convenient to have in any buffer,
67 ;; and not just in the minibuffer or (some) shell-mode. It goes 67 ;; and not just in the minibuffer or (some) shell-mode. It goes
68 ;; through all possible completions instead of just completing as 68 ;; through all possible completions instead of just completing as
69 ;; much as is unique. 69 ;; much as is unique.
70 ;; `try-complete-file-name-partially' : To insert in the list just 70 ;; `try-complete-file-name-partially' : To insert in the list just
71 ;; before `try-complete-file-name' for those who want first to get 71 ;; before `try-complete-file-name' for those who want first to get
72 ;; a file name completed only as many characters as is unique. 72 ;; a file name completed only as many characters as is unique.
73 ;; `try-expand-all-abbrevs' : can be removed if you don't use abbrevs. 73 ;; `try-expand-all-abbrevs' : can be removed if you don't use abbrevs.
74 ;; Otherwise it looks through all abbrev-tables, starting with 74 ;; Otherwise it looks through all abbrev-tables, starting with
75 ;; the local followed by the global. 75 ;; the local followed by the global.
76 ;; `try-expand-line' : Searches the buffer for an entire line that 76 ;; `try-expand-line' : Searches the buffer for an entire line that
77 ;; begins exactly as the current line. Convenient sometimes, for 77 ;; begins exactly as the current line. Convenient sometimes, for
78 ;; example as a substitute for (or complement to) the history 78 ;; example as a substitute for (or complement to) the history
79 ;; list in shell-like buffers. At other times, only confusing. 79 ;; list in shell-like buffers. At other times, only confusing.
80 ;; `try-expand-line-all-buffers' : Like `try-expand-line' but searches 80 ;; `try-expand-line-all-buffers' : Like `try-expand-line' but searches
81 ;; in all buffers (except the current). (This may be a little 81 ;; in all buffers (except the current). (This may be a little
82 ;; slow, don't use it unless you are really fond of `hippie-expand'.) 82 ;; slow, don't use it unless you are really fond of `hippie-expand'.)
83 ;; `try-expand-list' : Tries to expand the text back to the nearest 83 ;; `try-expand-list' : Tries to expand the text back to the nearest
84 ;; open delimiter, to a whole list from the buffer. Convenient for 84 ;; open delimiter, to a whole list from the buffer. Convenient for
85 ;; example when writing lisp or TeX. 85 ;; example when writing lisp or TeX.
86 ;; `try-expand-list-all-buffers' : Like `try-expand-list' but searches 86 ;; `try-expand-list-all-buffers' : Like `try-expand-list' but searches
87 ;; in all buffers (except the current). 87 ;; in all buffers (except the current).
88 ;; `try-expand-dabbrev' : works exactly as dabbrev-expand (but of 88 ;; `try-expand-dabbrev' : works exactly as dabbrev-expand (but of
89 ;; course in a way compatible with the other try-functions). 89 ;; course in a way compatible with the other try-functions).
90 ;; `try-expand-dabbrev-all-buffers' : perhaps the most useful of them, 90 ;; `try-expand-dabbrev-all-buffers' : perhaps the most useful of them,
91 ;; like `dabbrev-expand' but searches all Emacs buffers (except the 91 ;; like `dabbrev-expand' but searches all Emacs buffers (except the
92 ;; current) for matching words. (No, I don't find this one 92 ;; current) for matching words. (No, I don't find this one
93 ;; particularly slow.) 93 ;; particularly slow.)
94 ;; `try-expand-dabbrev-visible': Searches the currently visible parts of 94 ;; `try-expand-dabbrev-visible': Searches the currently visible parts of
95 ;; all windows. Can be put before `try-expand-dabbrev-all-buffers' to 95 ;; all windows. Can be put before `try-expand-dabbrev-all-buffers' to
96 ;; first try the expansions you can see. 96 ;; first try the expansions you can see.
97 ;; `try-expand-dabbrev-from-kill': Searches the kill ring for a suitable 97 ;; `try-expand-dabbrev-from-kill': Searches the kill ring for a suitable
98 ;; completion of the word. Good to have, just in case the word was not 98 ;; completion of the word. Good to have, just in case the word was not
106 ;; Might be tedious (usually a lot of possible completions) and 106 ;; Might be tedious (usually a lot of possible completions) and
107 ;; since its function is much like `lisp-complete-symbol', which 107 ;; since its function is much like `lisp-complete-symbol', which
108 ;; already has a key of its own, you might want to remove this. 108 ;; already has a key of its own, you might want to remove this.
109 ;; `try-complete-lisp-symbol-partially' : To insert in the list just 109 ;; `try-complete-lisp-symbol-partially' : To insert in the list just
110 ;; before `try-complete-lisp-symbol' for those who first want to get 110 ;; before `try-complete-lisp-symbol' for those who first want to get
111 ;; completion of what is unique in the name. 111 ;; completion of what is unique in the name.
112 ;; 112 ;;
113 ;; Not all of the above functions are by default in 113 ;; Not all of the above functions are by default in
114 ;; `hippie-expand-try-functions-list'. This variable is better set 114 ;; `hippie-expand-try-functions-list'. This variable is better set
115 ;; in ".emacs" to make `hippie-expand' behave maximally convenient 115 ;; in ".emacs" to make `hippie-expand' behave maximally convenient
116 ;; according to personal taste. Also, instead of loading the 116 ;; according to personal taste. Also, instead of loading the
141 ;; TRANS-CASE non-nil, means transfer of case from the abbreviation 141 ;; TRANS-CASE non-nil, means transfer of case from the abbreviation
142 ;; to the expansion is ok if that is enabled in the buffer.) 142 ;; to the expansion is ok if that is enabled in the buffer.)
143 ;; `he-reset-string' : Resets the initialized region to its original 143 ;; `he-reset-string' : Resets the initialized region to its original
144 ;; contents. 144 ;; contents.
145 ;; There is also a variable: `he-tried-table' which is meant to contain 145 ;; There is also a variable: `he-tried-table' which is meant to contain
146 ;; all tried expansions so far. The try-function can check this 146 ;; all tried expansions so far. The try-function can check this
147 ;; variable to see whether an expansion has already been tried 147 ;; variable to see whether an expansion has already been tried
148 ;; (hint: `he-string-member'). 148 ;; (hint: `he-string-member').
149 ;; 149 ;;
150 ;; Known bugs 150 ;; Known bugs
151 ;; 151 ;;
152 ;; It may happen that some completion suggestion occurs twice, in 152 ;; It may happen that some completion suggestion occurs twice, in
153 ;; spite of the use of `he-tried-table' to prevent that. This is 153 ;; spite of the use of `he-tried-table' to prevent that. This is
154 ;; because different try-functions may try to complete different 154 ;; because different try-functions may try to complete different
155 ;; lengths of text, and thus put different amounts of the 155 ;; lengths of text, and thus put different amounts of the
156 ;; text in `he-tried-table'. Anyway this seems to occur seldom enough 156 ;; text in `he-tried-table'. Anyway this seems to occur seldom enough
157 ;; not to be too disturbing. Also it should NOT be possible for the 157 ;; not to be too disturbing. Also it should NOT be possible for the
158 ;; opposite situation to occur, that `hippie-expand' misses some 158 ;; opposite situation to occur, that `hippie-expand' misses some
272 (defun hippie-expand (arg) 272 (defun hippie-expand (arg)
273 "Try to expand text before point, using multiple methods. 273 "Try to expand text before point, using multiple methods.
274 The expansion functions in `hippie-expand-try-functions-list' are 274 The expansion functions in `hippie-expand-try-functions-list' are
275 tried in order, until a possible expansion is found. Repeated 275 tried in order, until a possible expansion is found. Repeated
276 application of `hippie-expand' inserts successively possible 276 application of `hippie-expand' inserts successively possible
277 expansions. 277 expansions.
278 With a positive numeric argument, jumps directly to the ARG next 278 With a positive numeric argument, jumps directly to the ARG next
279 function in this list. With a negative argument or just \\[universal-argument], 279 function in this list. With a negative argument or just \\[universal-argument],
280 undoes the expansion." 280 undoes the expansion."
281 (interactive "P") 281 (interactive "P")
282 (if (or (not arg) 282 (if (or (not arg)
283 (and (integerp arg) (> arg 0))) 283 (and (integerp arg) (> arg 0)))
284 (let ((first (or (= he-num -1) 284 (let ((first (or (= he-num -1)
285 (not (equal this-command last-command))))) 285 (not (equal this-command last-command)))))
286 (if first 286 (if first
287 (progn 287 (progn
290 (if arg 290 (if arg
291 (if (not first) (he-reset-string)) 291 (if (not first) (he-reset-string))
292 (setq arg 0)) 292 (setq arg 0))
293 (let ((i (max (+ he-num arg) 0))) 293 (let ((i (max (+ he-num arg) 0)))
294 (while (not (or (>= i (length hippie-expand-try-functions-list)) 294 (while (not (or (>= i (length hippie-expand-try-functions-list))
295 (apply (nth i hippie-expand-try-functions-list) 295 (apply (nth i hippie-expand-try-functions-list)
296 (list (= he-num i))))) 296 (list (= he-num i)))))
297 (setq i (1+ i))) 297 (setq i (1+ i)))
298 (setq he-num i)) 298 (setq he-num i))
299 (if (>= he-num (length hippie-expand-try-functions-list)) 299 (if (>= he-num (length hippie-expand-try-functions-list))
300 (progn 300 (progn
329 (insert he-search-string) 329 (insert he-search-string)
330 (delete-region (point) he-string-end) 330 (delete-region (point) he-string-end)
331 (goto-char newpos))) 331 (goto-char newpos)))
332 332
333 ;; Substitutes an expansion STR into the correct region (the region 333 ;; Substitutes an expansion STR into the correct region (the region
334 ;; initialized with `he-init-string'). 334 ;; initialized with `he-init-string').
335 ;; An optional argument TRANS-CASE means that it is ok to transfer case 335 ;; An optional argument TRANS-CASE means that it is ok to transfer case
336 ;; from the abbreviation to the expansion if that is possible, and is 336 ;; from the abbreviation to the expansion if that is possible, and is
337 ;; enabled in the buffer. 337 ;; enabled in the buffer.
338 (defun he-substitute-string (str &optional trans-case) 338 (defun he-substitute-string (str &optional trans-case)
339 (let ((trans-case (and trans-case 339 (let ((trans-case (and trans-case
411 ;; '(try-complete-file-name-partially 411 ;; '(try-complete-file-name-partially
412 ;; try-complete-file-name))) 412 ;; try-complete-file-name)))
413 ;; (fset 'my-complete-line (make-hippie-expand-function 413 ;; (fset 'my-complete-line (make-hippie-expand-function
414 ;; '(try-expand-line 414 ;; '(try-expand-line
415 ;; try-expand-line-all-buffers))) 415 ;; try-expand-line-all-buffers)))
416 ;; 416 ;;
417 ;;;###autoload 417 ;;;###autoload
418 (defmacro make-hippie-expand-function (try-list &optional verbose) 418 (defmacro make-hippie-expand-function (try-list &optional verbose)
419 "Construct a function similar to `hippie-expand'. 419 "Construct a function similar to `hippie-expand'.
420 Make it use the expansion functions in TRY-LIST. An optional second 420 Make it use the expansion functions in TRY-LIST. An optional second
421 argument VERBOSE non-nil makes the function verbose." 421 argument VERBOSE non-nil makes the function verbose."
422 `(function (lambda (arg) 422 `(function (lambda (arg)
423 ,(concat 423 ,(concat
424 "Try to expand text before point, using the following functions: \n" 424 "Try to expand text before point, using the following functions: \n"
425 (mapconcat 'prin1-to-string (eval try-list) ", ")) 425 (mapconcat 'prin1-to-string (eval try-list) ", "))
426 (interactive "P") 426 (interactive "P")
427 (let ((hippie-expand-try-functions-list ,try-list) 427 (let ((hippie-expand-try-functions-list ,try-list)
428 (hippie-expand-verbose ,verbose)) 428 (hippie-expand-verbose ,verbose))
436 "Try to complete text as a file name. 436 "Try to complete text as a file name.
437 The argument OLD has to be nil the first call of this function, and t 437 The argument OLD has to be nil the first call of this function, and t
438 for subsequent calls (for further possible completions of the same 438 for subsequent calls (for further possible completions of the same
439 string). It returns t if a new completion is found, nil otherwise." 439 string). It returns t if a new completion is found, nil otherwise."
440 (if (not old) 440 (if (not old)
441 (progn 441 (progn
442 (he-init-string (he-file-name-beg) (point)) 442 (he-init-string (he-file-name-beg) (point))
443 (let ((name-part (he-file-name-nondirectory he-search-string)) 443 (let ((name-part (he-file-name-nondirectory he-search-string))
444 (dir-part (expand-file-name (or (he-file-name-directory 444 (dir-part (expand-file-name (or (he-file-name-directory
445 he-search-string) "")))) 445 he-search-string) ""))))
446 (if (not (he-string-member name-part he-tried-table)) 446 (if (not (he-string-member name-part he-tried-table))
447 (setq he-tried-table (cons name-part he-tried-table))) 447 (setq he-tried-table (cons name-part he-tried-table)))
448 (if (and (not (equal he-search-string "")) 448 (if (and (not (equal he-search-string ""))
449 (he-file-directory-p dir-part)) 449 (he-file-directory-p dir-part))
450 (setq he-expand-list (sort (file-name-all-completions 450 (setq he-expand-list (sort (file-name-all-completions
451 name-part 451 name-part
452 dir-part) 452 dir-part)
453 'string-lessp)) 453 'string-lessp))
454 (setq he-expand-list ()))))) 454 (setq he-expand-list ())))))
455 455
469 t))) 469 t)))
470 470
471 (defun try-complete-file-name-partially (old) 471 (defun try-complete-file-name-partially (old)
472 "Try to complete text as a file name, as many characters as unique. 472 "Try to complete text as a file name, as many characters as unique.
473 The argument OLD has to be nil the first call of this function. It 473 The argument OLD has to be nil the first call of this function. It
474 returns t if a unique, possibly partial, completion is found, nil 474 returns t if a unique, possibly partial, completion is found, nil
475 otherwise." 475 otherwise."
476 (let ((expansion ())) 476 (let ((expansion ()))
477 (if (not old) 477 (if (not old)
478 (progn 478 (progn
479 (he-init-string (he-file-name-beg) (point)) 479 (he-init-string (he-file-name-beg) (point))
480 (let ((name-part (he-file-name-nondirectory he-search-string)) 480 (let ((name-part (he-file-name-nondirectory he-search-string))
481 (dir-part (expand-file-name (or (he-file-name-directory 481 (dir-part (expand-file-name (or (he-file-name-directory
482 he-search-string) "")))) 482 he-search-string) ""))))
483 (if (and (not (equal he-search-string "")) 483 (if (and (not (equal he-search-string ""))
501 t)))) 501 t))))
502 502
503 (defvar he-file-name-chars 503 (defvar he-file-name-chars
504 (cond ((memq system-type '(vax-vms axp-vms)) 504 (cond ((memq system-type '(vax-vms axp-vms))
505 "-a-zA-Z0-9_/.,~^#$+=:\\[\\]") 505 "-a-zA-Z0-9_/.,~^#$+=:\\[\\]")
506 ((memq system-type '(ms-dos windows-nt)) 506 ((memq system-type '(ms-dos windows-nt cygwin))
507 "-a-zA-Z0-9_/.,~^#$+=:\\\\") 507 "-a-zA-Z0-9_/.,~^#$+=:\\\\")
508 (t ;; More strange file formats ? 508 (t ;; More strange file formats ?
509 "-a-zA-Z0-9_/.,~^#$+=")) 509 "-a-zA-Z0-9_/.,~^#$+="))
510 "Characters that are considered part of the file name to expand.") 510 "Characters that are considered part of the file name to expand.")
511 511
516 (if (> (skip-syntax-backward "w") 0) ;; No words with non-file chars 516 (if (> (skip-syntax-backward "w") 0) ;; No words with non-file chars
517 op 517 op
518 (point))))) 518 (point)))))
519 519
520 ;; Thanks go to Richard Levitte <levitte@e.kth.se> who helped to make these 520 ;; Thanks go to Richard Levitte <levitte@e.kth.se> who helped to make these
521 ;; work under VMS, and to David Hughes <ukchugd@ukpmr.cs.philips.nl> who 521 ;; work under VMS, and to David Hughes <ukchugd@ukpmr.cs.philips.nl> who
522 ;; helped to make it work on PC. 522 ;; helped to make it work on PC.
523 (defun he-file-name-nondirectory (file) 523 (defun he-file-name-nondirectory (file)
524 "Fix to make `file-name-nondirectory' work for hippie-expand under VMS." 524 "Fix to make `file-name-nondirectory' work for hippie-expand under VMS."
525 (if (memq system-type '(axp-vms vax-vms)) 525 (if (memq system-type '(axp-vms vax-vms))
526 (let ((n (file-name-nondirectory file))) 526 (let ((n (file-name-nondirectory file)))
543 "Fix to make `file-directory-p' work for hippie-expand under VMS." 543 "Fix to make `file-directory-p' work for hippie-expand under VMS."
544 (if (memq system-type '(vax-vms axp-vms)) 544 (if (memq system-type '(vax-vms axp-vms))
545 (or (file-directory-p file) 545 (or (file-directory-p file)
546 (file-directory-p (concat file "[000000]"))) 546 (file-directory-p (concat file "[000000]")))
547 (file-directory-p file))) 547 (file-directory-p file)))
548 548
549 (defun he-concat-directory-file-name (dir-part name-part) 549 (defun he-concat-directory-file-name (dir-part name-part)
550 "Try to slam together two parts of a file specification, system dependently." 550 "Try to slam together two parts of a file specification, system dependently."
551 (cond ((null dir-part) name-part) 551 (cond ((null dir-part) name-part)
552 ((memq system-type '(axp-vms vax-vms)) 552 ((memq system-type '(axp-vms vax-vms))
553 (if (and (string= (substring dir-part -1) "]") 553 (if (and (string= (substring dir-part -1) "]")
558 (if (and (string-match "\\\\" dir-part) 558 (if (and (string-match "\\\\" dir-part)
559 (not (string-match "/" dir-part)) 559 (not (string-match "/" dir-part))
560 (= (aref name-part (1- (length name-part))) ?/)) 560 (= (aref name-part (1- (length name-part))) ?/))
561 (aset name-part (1- (length name-part)) ?\\)) 561 (aset name-part (1- (length name-part)) ?\\))
562 (concat dir-part name-part)) 562 (concat dir-part name-part))
563 (t 563 (t
564 (concat dir-part name-part)))) 564 (concat dir-part name-part))))
565 565
566 (defun try-complete-lisp-symbol (old) 566 (defun try-complete-lisp-symbol (old)
567 "Try to complete word as an Emacs Lisp symbol. 567 "Try to complete word as an Emacs Lisp symbol.
568 The argument OLD has to be nil the first call of this function, and t 568 The argument OLD has to be nil the first call of this function, and t
569 for subsequent calls (for further possible completions of the same 569 for subsequent calls (for further possible completions of the same
570 string). It returns t if a new completion is found, nil otherwise." 570 string). It returns t if a new completion is found, nil otherwise."
571 (if (not old) 571 (if (not old)
572 (progn 572 (progn
573 (he-init-string (he-lisp-symbol-beg) (point)) 573 (he-init-string (he-lisp-symbol-beg) (point))
574 (if (not (he-string-member he-search-string he-tried-table)) 574 (if (not (he-string-member he-search-string he-tried-table))
575 (setq he-tried-table (cons he-search-string he-tried-table))) 575 (setq he-tried-table (cons he-search-string he-tried-table)))
576 (setq he-expand-list 576 (setq he-expand-list
577 (and (not (equal he-search-string "")) 577 (and (not (equal he-search-string ""))
578 (sort (all-completions he-search-string obarray 578 (sort (all-completions he-search-string obarray
579 (function (lambda (sym) 579 (function (lambda (sym)
580 (or (boundp sym) 580 (or (boundp sym)
581 (fboundp sym) 581 (fboundp sym)
594 t))) 594 t)))
595 595
596 (defun try-complete-lisp-symbol-partially (old) 596 (defun try-complete-lisp-symbol-partially (old)
597 "Try to complete as an Emacs Lisp symbol, as many characters as unique. 597 "Try to complete as an Emacs Lisp symbol, as many characters as unique.
598 The argument OLD has to be nil the first call of this function. It 598 The argument OLD has to be nil the first call of this function. It
599 returns t if a unique, possibly partial, completion is found, nil 599 returns t if a unique, possibly partial, completion is found, nil
600 otherwise." 600 otherwise."
601 (let ((expansion ())) 601 (let ((expansion ()))
602 (if (not old) 602 (if (not old)
603 (progn 603 (progn
604 (he-init-string (he-lisp-symbol-beg) (point)) 604 (he-init-string (he-lisp-symbol-beg) (point))
605 (if (not (string= he-search-string "")) 605 (if (not (string= he-search-string ""))
606 (setq expansion 606 (setq expansion
607 (try-completion he-search-string obarray 607 (try-completion he-search-string obarray
608 (function (lambda (sym) 608 (function (lambda (sym)
609 (or (boundp sym) 609 (or (boundp sym)
610 (fboundp sym) 610 (fboundp sym)
611 (symbol-plist sym))))))) 611 (symbol-plist sym)))))))
647 (save-restriction 647 (save-restriction
648 (if hippie-expand-no-restriction 648 (if hippie-expand-no-restriction
649 (widen)) 649 (widen))
650 ;; Try looking backward unless inhibited. 650 ;; Try looking backward unless inhibited.
651 (if he-search-bw 651 (if he-search-bw
652 (progn 652 (progn
653 (goto-char he-search-loc) 653 (goto-char he-search-loc)
654 (setq expansion (he-line-search he-search-string 654 (setq expansion (he-line-search he-search-string
655 strip-prompt t)) 655 strip-prompt t))
656 (set-marker he-search-loc (point)) 656 (set-marker he-search-loc (point))
657 (if (not expansion) 657 (if (not expansion)
658 (progn 658 (progn
659 (set-marker he-search-loc he-string-end) 659 (set-marker he-search-loc he-string-end)
660 (setq he-search-bw ()))))) 660 (setq he-search-bw ())))))
661 661
662 (if (not expansion) ; Then look forward. 662 (if (not expansion) ; Then look forward.
663 (progn 663 (progn
664 (goto-char he-search-loc) 664 (goto-char he-search-loc)
665 (setq expansion (he-line-search he-search-string 665 (setq expansion (he-line-search he-search-string
666 strip-prompt nil)) 666 strip-prompt nil))
667 (set-marker he-search-loc (point))))))) 667 (set-marker he-search-loc (point)))))))
668 668
669 (if (not expansion) 669 (if (not expansion)
670 (progn 670 (progn
691 (setq he-search-bufs (buffer-list)) 691 (setq he-search-bufs (buffer-list))
692 (setq he-searched-n-bufs 0) 692 (setq he-searched-n-bufs 0)
693 (set-marker he-search-loc 1 (car he-search-bufs)))) 693 (set-marker he-search-loc 1 (car he-search-bufs))))
694 694
695 (if (not (equal he-search-string "")) 695 (if (not (equal he-search-string ""))
696 (while (and he-search-bufs 696 (while (and he-search-bufs
697 (not expansion) 697 (not expansion)
698 (or (not hippie-expand-max-buffers) 698 (or (not hippie-expand-max-buffers)
699 (< he-searched-n-bufs hippie-expand-max-buffers))) 699 (< he-searched-n-bufs hippie-expand-max-buffers)))
700 (set-buffer (car he-search-bufs)) 700 (set-buffer (car he-search-bufs))
701 (if (and (not (eq (current-buffer) buf)) 701 (if (and (not (eq (current-buffer) buf))
708 (widen)) 708 (widen))
709 (goto-char he-search-loc) 709 (goto-char he-search-loc)
710 (setq strip-prompt (and (get-buffer-process (current-buffer)) 710 (setq strip-prompt (and (get-buffer-process (current-buffer))
711 comint-use-prompt-regexp-instead-of-fields 711 comint-use-prompt-regexp-instead-of-fields
712 comint-prompt-regexp)) 712 comint-prompt-regexp))
713 (setq expansion 713 (setq expansion
714 (let ((case-fold-search orig-case-fold-search)) 714 (let ((case-fold-search orig-case-fold-search))
715 (he-line-search he-search-string 715 (he-line-search he-search-string
716 strip-prompt nil))) 716 strip-prompt nil)))
717 (set-marker he-search-loc (point)) 717 (set-marker he-search-loc (point))
718 (if (not expansion) 718 (if (not expansion)
730 ()) 730 ())
731 (progn 731 (progn
732 (he-substitute-string expansion t) 732 (he-substitute-string expansion t)
733 t)))) 733 t))))
734 734
735 (defun he-line-search (str strip-prompt reverse) 735 (defun he-line-search (str strip-prompt reverse)
736 (let ((result ())) 736 (let ((result ()))
737 (while (and (not result) 737 (while (and (not result)
738 (if reverse 738 (if reverse
739 (re-search-backward 739 (re-search-backward
740 (he-line-search-regexp str strip-prompt) 740 (he-line-search-regexp str strip-prompt)
741 nil t) 741 nil t)
742 (re-search-forward 742 (re-search-forward
743 (he-line-search-regexp str strip-prompt) 743 (he-line-search-regexp str strip-prompt)
744 nil t))) 744 nil t)))
748 (setq result nil))) ; if already in table, ignore 748 (setq result nil))) ; if already in table, ignore
749 result)) 749 result))
750 750
751 (defun he-line-beg (strip-prompt) 751 (defun he-line-beg (strip-prompt)
752 (save-excursion 752 (save-excursion
753 (if (re-search-backward (he-line-search-regexp "" strip-prompt) 753 (if (re-search-backward (he-line-search-regexp "" strip-prompt)
754 (save-excursion (beginning-of-line) 754 (save-excursion (beginning-of-line)
755 (point)) t) 755 (point)) t)
756 (match-beginning 2) 756 (match-beginning 2)
757 (point)))) 757 (point))))
758 758
759 (defun he-line-search-regexp (pat strip-prompt) 759 (defun he-line-search-regexp (pat strip-prompt)
760 (if strip-prompt 760 (if strip-prompt
761 (concat "\\(" comint-prompt-regexp "\\|^\\s-*\\)\\(" 761 (concat "\\(" comint-prompt-regexp "\\|^\\s-*\\)\\("
762 (regexp-quote pat) 762 (regexp-quote pat)
763 "[^\n]*[^ \t\n]\\)") 763 "[^\n]*[^ \t\n]\\)")
764 (concat "^\\(\\s-*\\)\\(" 764 (concat "^\\(\\s-*\\)\\("
765 (regexp-quote pat) 765 (regexp-quote pat)
766 "[^\n]*[^ \t\n]\\)"))) 766 "[^\n]*[^ \t\n]\\)")))
767 767
768 (defun try-expand-list (old) 768 (defun try-expand-list (old)
769 "Try to complete the current beginning of a list. 769 "Try to complete the current beginning of a list.
782 (save-restriction 782 (save-restriction
783 (if hippie-expand-no-restriction 783 (if hippie-expand-no-restriction
784 (widen)) 784 (widen))
785 ;; Try looking backward unless inhibited. 785 ;; Try looking backward unless inhibited.
786 (if he-search-bw 786 (if he-search-bw
787 (progn 787 (progn
788 (goto-char he-search-loc) 788 (goto-char he-search-loc)
789 (setq expansion (he-list-search he-search-string t)) 789 (setq expansion (he-list-search he-search-string t))
790 (set-marker he-search-loc (point)) 790 (set-marker he-search-loc (point))
791 (if (not expansion) 791 (if (not expansion)
792 (progn 792 (progn
793 (set-marker he-search-loc he-string-end) 793 (set-marker he-search-loc he-string-end)
794 (setq he-search-bw ()))))) 794 (setq he-search-bw ())))))
795 795
796 (if (not expansion) ; Then look forward. 796 (if (not expansion) ; Then look forward.
797 (progn 797 (progn
798 (goto-char he-search-loc) 798 (goto-char he-search-loc)
799 (setq expansion (he-list-search he-search-string nil)) 799 (setq expansion (he-list-search he-search-string nil))
800 (set-marker he-search-loc (point))))))) 800 (set-marker he-search-loc (point)))))))
801 801
802 (if (not expansion) 802 (if (not expansion)
821 (setq he-search-bufs (buffer-list)) 821 (setq he-search-bufs (buffer-list))
822 (setq he-searched-n-bufs 0) 822 (setq he-searched-n-bufs 0)
823 (set-marker he-search-loc 1 (car he-search-bufs)))) 823 (set-marker he-search-loc 1 (car he-search-bufs))))
824 824
825 (if (not (equal he-search-string "")) 825 (if (not (equal he-search-string ""))
826 (while (and he-search-bufs 826 (while (and he-search-bufs
827 (not expansion) 827 (not expansion)
828 (or (not hippie-expand-max-buffers) 828 (or (not hippie-expand-max-buffers)
829 (< he-searched-n-bufs hippie-expand-max-buffers))) 829 (< he-searched-n-bufs hippie-expand-max-buffers)))
830 (set-buffer (car he-search-bufs)) 830 (set-buffer (car he-search-bufs))
831 (if (and (not (eq (current-buffer) buf)) 831 (if (and (not (eq (current-buffer) buf))
835 (save-excursion 835 (save-excursion
836 (save-restriction 836 (save-restriction
837 (if hippie-expand-no-restriction 837 (if hippie-expand-no-restriction
838 (widen)) 838 (widen))
839 (goto-char he-search-loc) 839 (goto-char he-search-loc)
840 (setq expansion 840 (setq expansion
841 (let ((case-fold-search orig-case-fold-search)) 841 (let ((case-fold-search orig-case-fold-search))
842 (he-list-search he-search-string nil))) 842 (he-list-search he-search-string nil)))
843 (set-marker he-search-loc (point)) 843 (set-marker he-search-loc (point))
844 (if (not expansion) 844 (if (not expansion)
845 (progn 845 (progn
856 ()) 856 ())
857 (progn 857 (progn
858 (he-substitute-string expansion t) 858 (he-substitute-string expansion t)
859 t)))) 859 t))))
860 860
861 (defun he-list-search (str reverse) 861 (defun he-list-search (str reverse)
862 (let ((result ()) 862 (let ((result ())
863 beg pos err) 863 beg pos err)
864 (while (and (not result) 864 (while (and (not result)
865 (if reverse 865 (if reverse
866 (search-backward str nil t) 866 (search-backward str nil t)
870 (goto-char beg) 870 (goto-char beg)
871 (setq err ()) 871 (setq err ())
872 (condition-case () 872 (condition-case ()
873 (forward-list 1) 873 (forward-list 1)
874 (error (setq err t))) 874 (error (setq err t)))
875 (if (and reverse 875 (if (and reverse
876 (> (point) he-string-beg)) 876 (> (point) he-string-beg))
877 (setq err t)) 877 (setq err t))
878 (if (not err) 878 (if (not err)
879 (progn 879 (progn
880 (setq result (buffer-substring-no-properties beg (point))) 880 (setq result (buffer-substring-no-properties beg (point)))
896 for subsequent calls (for further possible expansions of the same 896 for subsequent calls (for further possible expansions of the same
897 string). It returns t if a new expansion is found, nil otherwise." 897 string). It returns t if a new expansion is found, nil otherwise."
898 (if (not old) 898 (if (not old)
899 (progn 899 (progn
900 (he-init-string (he-dabbrev-beg) (point)) 900 (he-init-string (he-dabbrev-beg) (point))
901 (setq he-expand-list 901 (setq he-expand-list
902 (and (not (equal he-search-string "")) 902 (and (not (equal he-search-string ""))
903 (mapcar (function (lambda (sym) 903 (mapcar (function (lambda (sym)
904 (if (and (boundp sym) (vectorp (eval sym))) 904 (if (and (boundp sym) (vectorp (eval sym)))
905 (abbrev-expansion (downcase he-search-string) 905 (abbrev-expansion (downcase he-search-string)
906 (eval sym))))) 906 (eval sym)))))
907 (append '(local-abbrev-table 907 (append '(local-abbrev-table
908 global-abbrev-table) 908 global-abbrev-table)
909 abbrev-table-name-list)))))) 909 abbrev-table-name-list))))))
910 (while (and he-expand-list 910 (while (and he-expand-list
911 (or (not (car he-expand-list)) 911 (or (not (car he-expand-list))
912 (he-string-member (car he-expand-list) he-tried-table t))) 912 (he-string-member (car he-expand-list) he-tried-table t)))
937 (save-restriction 937 (save-restriction
938 (if hippie-expand-no-restriction 938 (if hippie-expand-no-restriction
939 (widen)) 939 (widen))
940 ;; Try looking backward unless inhibited. 940 ;; Try looking backward unless inhibited.
941 (if he-search-bw 941 (if he-search-bw
942 (progn 942 (progn
943 (goto-char he-search-loc) 943 (goto-char he-search-loc)
944 (setq expansion (he-dabbrev-search he-search-string t)) 944 (setq expansion (he-dabbrev-search he-search-string t))
945 (set-marker he-search-loc (point)) 945 (set-marker he-search-loc (point))
946 (if (not expansion) 946 (if (not expansion)
947 (progn 947 (progn
948 (set-marker he-search-loc he-string-end) 948 (set-marker he-search-loc he-string-end)
949 (setq he-search-bw ()))))) 949 (setq he-search-bw ())))))
950 950
951 (if (not expansion) ; Then look forward. 951 (if (not expansion) ; Then look forward.
952 (progn 952 (progn
953 (goto-char he-search-loc) 953 (goto-char he-search-loc)
954 (setq expansion (he-dabbrev-search he-search-string nil)) 954 (setq expansion (he-dabbrev-search he-search-string nil))
955 (set-marker he-search-loc (point))))))) 955 (set-marker he-search-loc (point)))))))
956 956
957 (if (not expansion) 957 (if (not expansion)
958 (progn 958 (progn
959 (if old (he-reset-string)) 959 (if old (he-reset-string))
960 ()) 960 ())
961 (progn 961 (progn
976 (setq he-search-bufs (buffer-list)) 976 (setq he-search-bufs (buffer-list))
977 (setq he-searched-n-bufs 0) 977 (setq he-searched-n-bufs 0)
978 (set-marker he-search-loc 1 (car he-search-bufs)))) 978 (set-marker he-search-loc 1 (car he-search-bufs))))
979 979
980 (if (not (equal he-search-string "")) 980 (if (not (equal he-search-string ""))
981 (while (and he-search-bufs 981 (while (and he-search-bufs
982 (not expansion) 982 (not expansion)
983 (or (not hippie-expand-max-buffers) 983 (or (not hippie-expand-max-buffers)
984 (< he-searched-n-bufs hippie-expand-max-buffers))) 984 (< he-searched-n-bufs hippie-expand-max-buffers)))
985 (set-buffer (car he-search-bufs)) 985 (set-buffer (car he-search-bufs))
986 (if (and (not (eq (current-buffer) buf)) 986 (if (and (not (eq (current-buffer) buf))
1045 (eq (marker-position he-string-beg) (match-beginning 0))) 1045 (eq (marker-position he-string-beg) (match-beginning 0)))
1046 (setq expansion (he-dabbrev-search he-search-string () 1046 (setq expansion (he-dabbrev-search he-search-string ()
1047 (window-end he-search-window)))) 1047 (window-end he-search-window))))
1048 (set-marker he-search-loc (point) (current-buffer))) 1048 (set-marker he-search-loc (point) (current-buffer)))
1049 (if (not expansion) 1049 (if (not expansion)
1050 (progn 1050 (progn
1051 (setq he-search-window (next-window he-search-window nil flag)) 1051 (setq he-search-window (next-window he-search-window nil flag))
1052 (if (eq he-search-window (selected-window)) 1052 (if (eq he-search-window (selected-window))
1053 (set-marker he-search-loc nil) 1053 (set-marker he-search-loc nil)
1054 (set-marker he-search-loc (window-start he-search-window) 1054 (set-marker he-search-loc (window-start he-search-window)
1055 (window-buffer he-search-window)))))) 1055 (window-buffer he-search-window))))))
1056 1056
1057 (set-buffer buf) 1057 (set-buffer buf)
1058 (if (not expansion) 1058 (if (not expansion)
1059 (progn 1059 (progn
1060 (if old (he-reset-string)) 1060 (if old (he-reset-string))
1061 ()) 1061 ())
1070 ((eq (char-syntax (aref pattern 0)) ?_) 1070 ((eq (char-syntax (aref pattern 0)) ?_)
1071 (concat (regexp-quote pattern) "\\(\\sw\\|\\s_\\)+")) 1071 (concat (regexp-quote pattern) "\\(\\sw\\|\\s_\\)+"))
1072 (t 1072 (t
1073 (concat "\\<" (regexp-quote pattern) 1073 (concat "\\<" (regexp-quote pattern)
1074 "\\(\\sw\\|\\s_\\)+"))))) 1074 "\\(\\sw\\|\\s_\\)+")))))
1075 (while (and (not result) 1075 (while (and (not result)
1076 (if reverse 1076 (if reverse
1077 (re-search-backward regpat limit t) 1077 (re-search-backward regpat limit t)
1078 (re-search-forward regpat limit t))) 1078 (re-search-forward regpat limit t)))
1079 (setq result (buffer-substring-no-properties (match-beginning 0) 1079 (setq result (buffer-substring-no-properties (match-beginning 0)
1080 (match-end 0))) 1080 (match-end 0)))
1102 The argument OLD has to be nil the first call of this function, and t 1102 The argument OLD has to be nil the first call of this function, and t
1103 for subsequent calls (for further possible completions of the same 1103 for subsequent calls (for further possible completions of the same
1104 string). It returns t if a new completion is found, nil otherwise." 1104 string). It returns t if a new completion is found, nil otherwise."
1105 (let ((expansion ())) 1105 (let ((expansion ()))
1106 (if (not old) 1106 (if (not old)
1107 (progn 1107 (progn
1108 (he-init-string (he-dabbrev-beg) (point)) 1108 (he-init-string (he-dabbrev-beg) (point))
1109 (setq he-expand-list 1109 (setq he-expand-list
1110 (if (not (equal he-search-string "")) 1110 (if (not (equal he-search-string ""))
1111 kill-ring)) 1111 kill-ring))
1112 (setq he-search-loc2 0))) 1112 (setq he-search-loc2 0)))
1128 (concat (regexp-quote pattern) "\\(\\sw\\|\\s_\\)+")) 1128 (concat (regexp-quote pattern) "\\(\\sw\\|\\s_\\)+"))
1129 (t 1129 (t
1130 (concat "\\<" (regexp-quote pattern) 1130 (concat "\\<" (regexp-quote pattern)
1131 "\\(\\sw\\|\\s_\\)+")))) 1131 "\\(\\sw\\|\\s_\\)+"))))
1132 (killstr (car he-expand-list))) 1132 (killstr (car he-expand-list)))
1133 (while (and (not result) 1133 (while (and (not result)
1134 he-expand-list) 1134 he-expand-list)
1135 (while (and (not result) 1135 (while (and (not result)
1136 (string-match regpat killstr he-search-loc2)) 1136 (string-match regpat killstr he-search-loc2))
1137 (setq result (substring killstr (match-beginning 0) (match-end 0))) 1137 (setq result (substring killstr (match-beginning 0) (match-end 0)))
1138 (set-text-properties 0 (length result) () result) 1138 (set-text-properties 0 (length result) () result)
1141 (> (match-beginning 0) 0) 1141 (> (match-beginning 0) 0)
1142 (memq (char-syntax (aref killstr (1- (match-beginning 0)))) 1142 (memq (char-syntax (aref killstr (1- (match-beginning 0))))
1143 '(?_ ?w))) 1143 '(?_ ?w)))
1144 (he-string-member result he-tried-table t)) 1144 (he-string-member result he-tried-table t))
1145 (setq result nil))) ; ignore if bad prefix or already in table 1145 (setq result nil))) ; ignore if bad prefix or already in table
1146 (if (and (not result) 1146 (if (and (not result)
1147 he-expand-list) 1147 he-expand-list)
1148 (progn 1148 (progn
1149 (setq he-expand-list (cdr he-expand-list)) 1149 (setq he-expand-list (cdr he-expand-list))
1150 (setq killstr (car he-expand-list)) 1150 (setq killstr (car he-expand-list))
1151 (setq he-search-loc2 0)))) 1151 (setq he-search-loc2 0))))
1152 result)) 1152 result))
1153 1153
1154 (defun try-expand-whole-kill (old) 1154 (defun try-expand-whole-kill (old)
1156 The argument OLD has to be nil the first call of this function, and t 1156 The argument OLD has to be nil the first call of this function, and t
1157 for subsequent calls (for further possible completions of the same 1157 for subsequent calls (for further possible completions of the same
1158 string). It returns t if a new completion is found, nil otherwise." 1158 string). It returns t if a new completion is found, nil otherwise."
1159 (let ((expansion ())) 1159 (let ((expansion ()))
1160 (if (not old) 1160 (if (not old)
1161 (progn 1161 (progn
1162 (he-init-string (he-kill-beg) (point)) 1162 (he-init-string (he-kill-beg) (point))
1163 (if (not (he-string-member he-search-string he-tried-table)) 1163 (if (not (he-string-member he-search-string he-tried-table))
1164 (setq he-tried-table (cons he-search-string he-tried-table))) 1164 (setq he-tried-table (cons he-search-string he-tried-table)))
1165 (setq he-expand-list 1165 (setq he-expand-list
1166 (if (not (equal he-search-string "")) 1166 (if (not (equal he-search-string ""))
1167 kill-ring)) 1167 kill-ring))
1168 (setq he-search-loc2 ()))) 1168 (setq he-search-loc2 ())))
1169 (if (not (equal he-search-string "")) 1169 (if (not (equal he-search-string ""))
1170 (setq expansion (he-whole-kill-search he-search-string))) 1170 (setq expansion (he-whole-kill-search he-search-string)))
1204 (he-string-member result he-tried-table)) 1204 (he-string-member result he-tried-table))
1205 (setq result nil))) ; ignore if already in table 1205 (setq result nil))) ; ignore if already in table
1206 (if (and (not result) 1206 (if (and (not result)
1207 he-expand-list) 1207 he-expand-list)
1208 (progn 1208 (progn
1209 (setq he-expand-list (cdr he-expand-list)) 1209 (setq he-expand-list (cdr he-expand-list))
1210 (setq killstr (car he-expand-list)) 1210 (setq killstr (car he-expand-list))
1211 (setq pos -1)))) 1211 (setq pos -1))))
1212 result)) 1212 result))
1213 1213
1214 (defun he-kill-beg () 1214 (defun he-kill-beg ()