emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C-r and C-s in minibuffer should search completion


From: Juri Linkov
Subject: Re: C-r and C-s in minibuffer should search completion
Date: Sun, 20 Apr 2008 01:46:55 +0300
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (x86_64-pc-linux-gnu)

>> by having both in Lisp with removing possible problems of using
>> Vbuffer_alist that you mentioned.
>
> Yes, except that your proposal doesn't remove possible problems with using
> Vbuffer_alist (that problem is if someone gets hold of this list
> and does things like "rplcd" (i.e. setcdr) on it).

That is why I propose creating a function `buffer-alist' that returns
a copy of Vbuffer_alist, not using this variable directly.  So modifications
on this alist would be impossible.

>>> Or you could define it on top of the internal-complete-buffer code,
>>> using the `predicate' argument.
>
>> Do you mean something like
>
>> (defun internal-complete-buffer-sans-current (string predicate flag)
>>   "Perform completion on buffer names excluding the current buffer.
>> Like `internal-complete-buffer', but removes the current buffer from
>> the completion list."
>>   (let ((current-buffer (buffer-name (other-buffer (current-buffer) t))))
>>     (internal-complete-buffer
>>      string (lambda (buffer) (not (equal current-buffer buffer))) flag)))
>
> Yes, except it should not ignore `predicate'.
> You could define it in terms of completion-table-with-predicate (100%
> untested code, of course):
>
> (defun internal-complete-buffer-except (&optional buf)
>   (lexical-let ((except (if (stringp buf) buf (buffer-name buf))))
>     (apply-partially 'completion-table-with-predicate
>                      'internal-complete-buffer
>                      (lambda (name) (not (equal name except)))
>                      nil)))

This works correctly in the following patch:

Index: lisp/minibuffer.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/minibuffer.el,v
retrieving revision 1.18
diff -c -r1.18 minibuffer.el
*** lisp/minibuffer.el  19 Apr 2008 03:34:02 -0000      1.18
--- lisp/minibuffer.el  19 Apr 2008 22:46:29 -0000
***************
*** 758,763 ****
--- 758,772 ----
                              'completion--file-name-table)
    "Internal subroutine for `read-file-name'.  Do not call this.")
  
+ (defun internal-complete-buffer-except (&optional buffer)
+   "Perform completion on all buffers excluding BUFFER.
+ Like `internal-complete-buffer', but removes BUFFER from the completion list."
+   (lexical-let ((except (if (stringp buffer) buffer (buffer-name buffer))))
+     (apply-partially 'completion-table-with-predicate
+                    'internal-complete-buffer
+                    (lambda (name) (not (equal name except)))
+                    nil)))
+ 
  (provide 'minibuffer)
  
  ;; arch-tag: ef8a0a15-1080-4790-a754-04017c02f08f

Index: lisp/files.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/files.el,v
retrieving revision 1.971
diff -c -r1.971 files.el
*** lisp/files.el       19 Apr 2008 03:33:12 -0000      1.971
--- lisp/files.el       19 Apr 2008 22:46:42 -0000
***************
*** 1039,1044 ****
--- 1039,1054 ----
      (rename-file encoded new-encoded ok-if-already-exists)
      newname))
  
+ (defun read-buffer-to-switch (prompt)
+   "Read the name of a buffer to switch to and return as a string.
+ It is intended for `switch-to-buffer' family of commands since they
+ need to omit the name of current buffer from the list of defaults."
+   (minibuffer-with-setup-hook
+       (lambda ()
+       (set (make-local-variable 'minibuffer-completion-table)
+            (internal-complete-buffer-except (other-buffer (current-buffer) 
t))))
+     (read-buffer prompt (other-buffer (current-buffer)))))
+ 
  (defun switch-to-buffer-other-window (buffer &optional norecord)
    "Select buffer BUFFER in another window.
  If BUFFER does not identify an existing buffer, then this function
***************
*** 1053,1059 ****
  
  This uses the function `display-buffer' as a subroutine; see its
  documentation for additional customization information."
!   (interactive "BSwitch to buffer in other window: ")
    (let ((pop-up-windows t)
        ;; Don't let these interfere.
        same-window-buffer-names same-window-regexps)
--- 1063,1070 ----
  
  This uses the function `display-buffer' as a subroutine; see its
  documentation for additional customization information."
!   (interactive
!    (list (read-buffer-to-switch "Switch to buffer in other window: ")))
    (let ((pop-up-windows t)
        ;; Don't let these interfere.
        same-window-buffer-names same-window-regexps)
***************
*** 1067,1073 ****
  
  This uses the function `display-buffer' as a subroutine; see its
  documentation for additional customization information."
!   (interactive "BSwitch to buffer in other frame: ")
    (let ((pop-up-frames t)
        same-window-buffer-names same-window-regexps)
      (prog1
--- 1078,1085 ----
  
  This uses the function `display-buffer' as a subroutine; see its
  documentation for additional customization information."
!   (interactive
!    (list (read-buffer-to-switch "Switch to buffer in other frame: ")))
    (let ((pop-up-frames t)
        same-window-buffer-names same-window-regexps)
      (prog1
***************
*** 1978,1984 ****
    (if (fboundp 'ucs-set-table-for-input) ; don't lose when building
        (ucs-set-table-for-input)))
  
! (defcustom auto-mode-case-fold nil
    "Non-nil means to try second pass through `auto-mode-alist'.
  This means that if the first case-sensitive search through the alist fails
  to find a matching major mode, a second case-insensitive search is made.
--- 1990,1996 ----
    (if (fboundp 'ucs-set-table-for-input) ; don't lose when building
        (ucs-set-table-for-input)))
  
! (defcustom auto-mode-case-fold t
    "Non-nil means to try second pass through `auto-mode-alist'.
  This means that if the first case-sensitive search through the alist fails
  to find a matching major mode, a second case-insensitive search is made.

-- 
Juri Linkov
http://www.jurta.org/emacs/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]