home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / languages / elisp / packages / mini-compl.el < prev    next >
Encoding:
Text File  |  1990-07-22  |  4.2 KB  |  101 lines

  1. ;From ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!bbn!jr@bbn.com Thu Apr 19 12:40:58 EDT 1990
  2. ;Article 1787 of comp.emacs:
  3. ;Path: ark1!uakari.primate.wisc.edu!zaphod.mps.ohio-state.edu!usc!bbn!jr@bbn.com
  4. ;From: jr@bbn.com (John Robinson)
  5. ;Newsgroups: comp.emacs
  6. ;Subject: Re: switch-to-buffer mode request
  7. ;Message-ID: <54985@bbn.COM>
  8. ;Date: 17 Apr 90 21:43:10 GMT
  9. ;References: <1697@sas.UUCP>
  10. ;Sender: news@bbn.COM
  11. ;Reply-To: jr@bbn.com (John Robinson)
  12. ;Organization: BBN Systems and Technologies Corporation, Cambridge MA
  13. ;Lines: 83
  14. ;In-reply-to: sasjaa@sas.UUCP (Jim Adams)
  15. ;
  16. ;In article <1697@sas.UUCP>, sasjaa@sas (Jim Adams) writes:
  17. ;>I am looking for a way to enhance the switch-to-buffer command.
  18. ;>I would like to do it (or get it) in lisp code as I don't have the
  19. ;>ability to modify our emacs. (I am using GNU emacs 18.54 on the
  20. ;>apollo). Here's what I want. When I press \C-x b, the message window
  21. ;>displays the default buffer to switch to. I would like to be able
  22. ;>to press SPC to cycle to the next buffer on the list. Is this
  23. ;>possible?
  24. ;
  25. ;Well, this sort of request has come up often enough that I thought I'd
  26. ;dive in and attempt it.  With only 15 minutes of hackery, I came up
  27. ;with the following, modified from the minibuffer-complete-exit-backup
  28. ;function (included) that came across the net many moons ago.  I use
  29. ;SPC for the completer, and M-n, M-p to navigate through the
  30. ;completions list.  Warning: this is gruesome slow in the middle of,
  31. ;for example, ^H f or ^H v :-).  Please offer improvements (esp in the
  32. ;list searching loop).  Byte compile for speed of course.  For blinding
  33. ;speed, code the C functions Fnext-completion and Fprev-completion like
  34. ;the built-in (all-completions), and toss the lisp loops altogether.
  35. ;========8<----------------------------------------------------------------
  36. (defun minibuffer-complete-exit-backup nil
  37.    "Minibuffer completion, exiting on unique completion with backup."
  38.    (interactive)
  39.    (let (comp (complete t))
  40.      (while (null (setq comp (all-completions
  41.                               (buffer-substring (point-min) (point))
  42.                               minibuffer-completion-table
  43.                               minibuffer-completion-predicate)))
  44.        (setq complete nil)
  45.        (delete-backward-char 1 nil))
  46.      (and complete (if (null (cdr comp)) (minibuffer-complete-and-exit)
  47.                         (minibuffer-complete)))))
  48.  
  49. (defun minibuffer-complete-next (dir)
  50.    "Minibuffer complete, then go to next choice, or prev if negative ARG.
  51. Look in completion table for unique completion with backup."
  52.    (interactive "p")
  53.    (let (comp (complete t) head)
  54.      (while (null (setq comp (all-completions
  55.                               (buffer-substring (point-min) (point))
  56.                               minibuffer-completion-table
  57.                               minibuffer-completion-predicate)))
  58.        (setq complete nil)
  59.        (delete-backward-char 1 nil))
  60.      (and complete 
  61.       (if (cdr comp)
  62.           (minibuffer-complete)
  63.         (setq complete (car comp))
  64.         (setq comp (all-completions
  65.             ""
  66.             minibuffer-completion-table
  67.             minibuffer-completion-predicate))
  68.         (if (< dir 0)
  69.         (setq comp (nreverse comp)))
  70.         (setq head (car comp))
  71.         (while (and comp (not (equal complete (car comp))))
  72.           (setq comp (cdr comp)))
  73.         (erase-buffer)
  74.         (if (null (cdr comp))
  75.         (insert head)
  76.           (insert (car (cdr comp))))))))
  77.  
  78. (defun minibuffer-complete-prev ()
  79.    "Minibuffer complete, then go to next prev choice.
  80. Look in completion table for unique completion with backup."
  81.    (interactive)
  82.    (minibuffer-complete-next -1))
  83.  
  84. (define-key minibuffer-local-must-match-map " "
  85.      (define-key minibuffer-local-completion-map " "
  86.           'minibuffer-complete-exit-backup))
  87. (define-key minibuffer-local-must-match-map "\en"
  88.      (define-key minibuffer-local-completion-map "\en"
  89.           'minibuffer-complete-next))
  90. (define-key minibuffer-local-must-match-map "\ep"
  91.      (define-key minibuffer-local-completion-map "\ep"
  92.           'minibuffer-complete-prev))
  93. ;========8<----------------------------------------------------------------
  94. ;
  95. ;Enjoy,
  96. ;--
  97. ;/jr, nee John Robinson     Life did not take over the globe by combat,
  98. ;jr@bbn.com or bbn!jr          but by networking -- Lynn Margulis
  99. ;
  100.  
  101.