comparison lisp/dabbrev.el @ 67169:e196e2160515

(dabbrev-completion): Simplify code, by getting rid of `if' whose condition always returned nil. Doc fix.
author Luc Teirlinck <teirllm@auburn.edu>
date Sun, 27 Nov 2005 23:54:40 +0000
parents 13abee3a9bc6
children 3bd95f4f2941 7beb78bc1f8e
comparison
equal deleted inserted replaced
67168:4a764117f25b 67169:e196e2160515
371 With a prefix argument, it searches all buffers accepted by the 371 With a prefix argument, it searches all buffers accepted by the
372 function pointed out by `dabbrev-friend-buffer-function' to find the 372 function pointed out by `dabbrev-friend-buffer-function' to find the
373 completions. 373 completions.
374 374
375 If the prefix argument is 16 (which comes from C-u C-u), 375 If the prefix argument is 16 (which comes from C-u C-u),
376 then it searches *all* buffers. 376 then it searches *all* buffers."
377
378 With no prefix argument, it reuses an old completion list
379 if there is a suitable one already."
380
381 (interactive "*P") 377 (interactive "*P")
382 (dabbrev--reset-global-variables) 378 (dabbrev--reset-global-variables)
383 (let* ((dabbrev-check-other-buffers (and arg t)) 379 (let* ((dabbrev-check-other-buffers (and arg t))
384 (dabbrev-check-all-buffers 380 (dabbrev-check-all-buffers
385 (and arg (= (prefix-numeric-value arg) 16))) 381 (and arg (= (prefix-numeric-value arg) 16)))
390 (or (not dabbrev-upcase-means-case-search) 386 (or (not dabbrev-upcase-means-case-search)
391 (string= abbrev (downcase abbrev))))) 387 (string= abbrev (downcase abbrev)))))
392 (my-obarray dabbrev--last-obarray) 388 (my-obarray dabbrev--last-obarray)
393 init) 389 init)
394 (save-excursion 390 (save-excursion
395 (if (and (null arg) 391 ;;--------------------------------
396 my-obarray 392 ;; New abbreviation to expand.
397 (or (eq dabbrev--last-completion-buffer (current-buffer)) 393 ;;--------------------------------
398 (and (window-minibuffer-p (selected-window)) 394 (setq dabbrev--last-abbreviation abbrev)
399 (eq dabbrev--last-completion-buffer 395 ;; Find all expansion
400 (dabbrev--minibuffer-origin)))) 396 (let ((completion-list
401 dabbrev--last-abbreviation 397 (dabbrev--find-all-expansions abbrev ignore-case-p))
402 (>= (length abbrev) (length dabbrev--last-abbreviation)) 398 (completion-ignore-case ignore-case-p))
403 (string= dabbrev--last-abbreviation 399 ;; Make an obarray with all expansions
404 (substring abbrev 0 400 (setq my-obarray (make-vector (length completion-list) 0))
405 (length dabbrev--last-abbreviation))) 401 (or (> (length my-obarray) 0)
406 (setq init (try-completion abbrev my-obarray))) 402 (error "No dynamic expansion for \"%s\" found%s"
407 ;; We can reuse the existing completion list. 403 abbrev
408 nil 404 (if dabbrev--check-other-buffers "" " in this-buffer")))
409 ;;-------------------------------- 405 (cond
410 ;; New abbreviation to expand. 406 ((or (not ignore-case-p)
411 ;;-------------------------------- 407 (not dabbrev-case-replace))
412 (setq dabbrev--last-abbreviation abbrev) 408 (mapc (function (lambda (string)
413 ;; Find all expansion 409 (intern string my-obarray)))
414 (let ((completion-list 410 completion-list))
415 (dabbrev--find-all-expansions abbrev ignore-case-p)) 411 ((string= abbrev (upcase abbrev))
416 (completion-ignore-case ignore-case-p)) 412 (mapc (function (lambda (string)
417 ;; Make an obarray with all expansions 413 (intern (upcase string) my-obarray)))
418 (setq my-obarray (make-vector (length completion-list) 0)) 414 completion-list))
419 (or (> (length my-obarray) 0) 415 ((string= (substring abbrev 0 1)
420 (error "No dynamic expansion for \"%s\" found%s" 416 (upcase (substring abbrev 0 1)))
421 abbrev 417 (mapc (function (lambda (string)
422 (if dabbrev--check-other-buffers "" " in this-buffer"))) 418 (intern (capitalize string) my-obarray)))
423 (cond 419 completion-list))
424 ((or (not ignore-case-p) 420 (t
425 (not dabbrev-case-replace)) 421 (mapc (function (lambda (string)
426 (mapc (function (lambda (string) 422 (intern (downcase string) my-obarray)))
427 (intern string my-obarray))) 423 completion-list)))
428 completion-list)) 424 (setq dabbrev--last-obarray my-obarray)
429 ((string= abbrev (upcase abbrev)) 425 (setq dabbrev--last-completion-buffer (current-buffer))
430 (mapc (function (lambda (string) 426 ;; Find the longest common string.
431 (intern (upcase string) my-obarray))) 427 (setq init (try-completion abbrev my-obarray))))
432 completion-list))
433 ((string= (substring abbrev 0 1)
434 (upcase (substring abbrev 0 1)))
435 (mapc (function (lambda (string)
436 (intern (capitalize string) my-obarray)))
437 completion-list))
438 (t
439 (mapc (function (lambda (string)
440 (intern (downcase string) my-obarray)))
441 completion-list)))
442 (setq dabbrev--last-obarray my-obarray)
443 (setq dabbrev--last-completion-buffer (current-buffer))
444 ;; Find the longest common string.
445 (setq init (try-completion abbrev my-obarray)))))
446 ;;-------------------------------- 428 ;;--------------------------------
447 ;; Let the user choose between the expansions 429 ;; Let the user choose between the expansions
448 ;;-------------------------------- 430 ;;--------------------------------
449 (or (stringp init) 431 (or (stringp init)
450 (setq init abbrev)) 432 (setq init abbrev))