* C-r and C-s in minibuffer should search completion @ 2008-03-20 19:13 Stefan Monnier 2008-03-20 19:35 ` Juri Linkov ` (2 more replies) 0 siblings, 3 replies; 64+ messages in thread From: Stefan Monnier @ 2008-03-20 19:13 UTC (permalink / raw) To: emacs-devel I believe C-s and C-r in the minibuffer should not only search the history but the completion table as well (at least when it's not a function). Could someone implement this feature? Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-20 19:13 C-r and C-s in minibuffer should search completion Stefan Monnier @ 2008-03-20 19:35 ` Juri Linkov 2008-03-20 20:07 ` Lennart Borgman (gmail) ` (2 more replies) 2008-03-20 20:44 ` Drew Adams 2008-03-25 21:44 ` Juri Linkov 2 siblings, 3 replies; 64+ messages in thread From: Juri Linkov @ 2008-03-20 19:35 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel > I believe C-s and C-r in the minibuffer should not only search the > history but the completion table as well (at least when it's not > a function). There is one problem: what to search first - the history or the completion table. Either preference will cause inconveniences. If the user wants to search the history (like implemented in shells), we should not let isearch to go thru all completion matches before starting to search the history, and vice versa. But really there is no need to mix two separate search spaces. There exist already a convenient key sequence to search the completion table: `PgUp C-s'. PgUp switches to the *Completions* buffer and C-s starts searching among completion candidates. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-20 19:35 ` Juri Linkov @ 2008-03-20 20:07 ` Lennart Borgman (gmail) 2008-03-20 20:38 ` Juri Linkov 2008-03-20 22:13 ` Stefan Monnier 2008-03-29 1:00 ` Xavier Maillard 2 siblings, 1 reply; 64+ messages in thread From: Lennart Borgman (gmail) @ 2008-03-20 20:07 UTC (permalink / raw) To: Juri Linkov; +Cc: Stefan Monnier, emacs-devel Juri Linkov wrote: >> I believe C-s and C-r in the minibuffer should not only search the >> history but the completion table as well (at least when it's not >> a function). > > There is one problem: what to search first - the history or the > completion table. Either preference will cause inconveniences. > If the user wants to search the history (like implemented in shells), > we should not let isearch to go thru all completion matches before > starting to search the history, and vice versa. > > But really there is no need to mix two separate search spaces. > There exist already a convenient key sequence to search the completion > table: `PgUp C-s'. PgUp switches to the *Completions* buffer and > C-s starts searching among completion candidates. Why not let PgDn switch between searching history and completions? Or maybe cycling history/completions/history+completions? ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-20 20:07 ` Lennart Borgman (gmail) @ 2008-03-20 20:38 ` Juri Linkov 2008-03-20 20:54 ` Drew Adams 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-20 20:38 UTC (permalink / raw) To: Lennart Borgman (gmail); +Cc: Stefan Monnier, emacs-devel >> But really there is no need to mix two separate search spaces. >> There exist already a convenient key sequence to search the completion >> table: `PgUp C-s'. PgUp switches to the *Completions* buffer and >> C-s starts searching among completion candidates. > > Why not let PgDn switch between searching history and completions? Or > maybe cycling history/completions/history+completions? This would be very clumsy user interface since it is not an intuitive key for switching search modes, and also will require an indication somewhere for the current mode. However, I think PgDn is a good candidate for a new command that just like PgUp displays a list of completions in a separate buffer, will display a list of elements from the history list in a separate buffer. I think this would be a useful feature. It will allow browsing all elements of the history list in one buffer and using normal isearch to search them. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* RE: C-r and C-s in minibuffer should search completion 2008-03-20 20:38 ` Juri Linkov @ 2008-03-20 20:54 ` Drew Adams 2008-03-20 23:07 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Drew Adams @ 2008-03-20 20:54 UTC (permalink / raw) To: 'Juri Linkov', 'Lennart Borgman (gmail)' Cc: 'Stefan Monnier', emacs-devel > However, I think PgDn is a good candidate for a new command that > just like PgUp displays a list of completions in a separate buffer, > will display a list of elements from the history list in a > separate buffer. I think this would be a useful feature. > It will allow browsing all elements of the history list in one buffer > and using normal isearch to search them. I proposed M-o, but which key you choose is not so important. However, I would argue to reserve the pair of keys `next' and `prior' (sometimes labeled PgDn and PgUp) for something that, well, comes in pairs and has some notion of, well, next and previous. That just makes sense. There is no need to use a different buffer from *Completions*. When the user hits M-o (or whatever), the current history list should simply become the *Completions* set; that's all. Nothing special. You don't need to use isearch to search the completion candidates (you can complete against them, as usual), but you of course can (as always), just by moving the cursor to buffer *Completions* and then using C-s. ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-20 20:54 ` Drew Adams @ 2008-03-20 23:07 ` Juri Linkov 0 siblings, 0 replies; 64+ messages in thread From: Juri Linkov @ 2008-03-20 23:07 UTC (permalink / raw) To: Drew Adams Cc: 'Lennart Borgman (gmail)', 'Stefan Monnier', emacs-devel >> However, I think PgDn is a good candidate for a new command that >> just like PgUp displays a list of completions in a separate buffer, >> will display a list of elements from the history list in a >> separate buffer. I think this would be a useful feature. >> It will allow browsing all elements of the history list in one buffer >> and using normal isearch to search them. > > I proposed M-o, but which key you choose is not so important. > > However, I would argue to reserve the pair of keys `next' and `prior' > (sometimes labeled PgDn and PgUp) for something that, well, comes in pairs > and has some notion of, well, next and previous. That just makes sense. I agree that PgUp and PgDn are not the best keys since when there is no completion they just do the same as M-n and M-p, so they behave differently when there is a completion list. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-20 19:35 ` Juri Linkov 2008-03-20 20:07 ` Lennart Borgman (gmail) @ 2008-03-20 22:13 ` Stefan Monnier 2008-03-20 22:27 ` Drew Adams 2008-03-20 23:03 ` Juri Linkov 2008-03-29 1:00 ` Xavier Maillard 2 siblings, 2 replies; 64+ messages in thread From: Stefan Monnier @ 2008-03-20 22:13 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel >> I believe C-s and C-r in the minibuffer should not only search the >> history but the completion table as well (at least when it's not >> a function). Sorry, I meant M-r/M-s. > There is one problem: what to search first - the history or the > completion table. Either preference will cause inconveniences. No problem: Make sure you start the search in between the two sets, so that M-r will first search one and M-s will first search the other. I'd guess M-r should first search through history, while M-s should first search through the completion table. BTW, once this is done, we can revert the recent change to the `read-buffer' that adds all the buffers to the list of defaults. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* RE: C-r and C-s in minibuffer should search completion 2008-03-20 22:13 ` Stefan Monnier @ 2008-03-20 22:27 ` Drew Adams 2008-03-20 23:03 ` Juri Linkov 1 sibling, 0 replies; 64+ messages in thread From: Drew Adams @ 2008-03-20 22:27 UTC (permalink / raw) To: 'Stefan Monnier', 'Juri Linkov'; +Cc: emacs-devel > >> I believe C-s and C-r in the minibuffer should not only search the > >> history but the completion table as well (at least when it's not > >> a function). > > Sorry, I meant M-r/M-s. Ah, I wondered about that. Thanks for clarifying. ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-20 22:13 ` Stefan Monnier 2008-03-20 22:27 ` Drew Adams @ 2008-03-20 23:03 ` Juri Linkov 2008-03-21 1:26 ` Stefan Monnier 1 sibling, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-20 23:03 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >>> I believe C-s and C-r in the minibuffer should not only search the >>> history but the completion table as well (at least when it's not >>> a function). > > Sorry, I meant M-r/M-s. > >> There is one problem: what to search first - the history or the >> completion table. Either preference will cause inconveniences. > > No problem: Make sure you start the search in between the two sets, so > that M-r will first search one and M-s will first search the other. > I'd guess M-r should first search through history, while M-s should > first search through the completion table. I think it would be unnatural to use M-s to search a list of elements not available for navigation in the minibuffer using M-p and M-n, because a set of keys M-p/M-n/M-r/M-s should operate on the same space for consistency. Otherwise, it would be confusing when M-s will insert in the minibuffer an element not from the list where M-p and M-n navigate. One solution is to add a new key to switch dimensions like proposed by Drew and Lennart, i.e. after typing a special key to change the current mode, M-n/M-p will navigate to the next/previous completion candidate in the minibuffer, M-s/M-r will search the completion list forward/backward in the minibuffer. > BTW, once this is done, we can revert the recent change to the > `read-buffer' that adds all the buffers to the list of defaults. Why? The buffer list in the list of defaults is useful not only for searching, but also for browsing, i.e. switching to the penultimate buffer is easy with `C-x b M-n M-n RET', to the third-to-last buffer - `C-x b M-n M-n M-n RET', etc. This is harmless improvement since it doesn't change the existing behavior, just adds more buffers sorted by recency beyond a single most recent buffer. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-20 23:03 ` Juri Linkov @ 2008-03-21 1:26 ` Stefan Monnier 2008-03-22 1:17 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-03-21 1:26 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel >> BTW, once this is done, we can revert the recent change to the >> `read-buffer' that adds all the buffers to the list of defaults. > Why? Because it's a special case and I'm not convinced it's justified. I expect most people who like this will prefer iswitchb anyway. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-21 1:26 ` Stefan Monnier @ 2008-03-22 1:17 ` Juri Linkov 2008-03-22 17:04 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-22 1:17 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >>> BTW, once this is done, we can revert the recent change to the >>> `read-buffer' that adds all the buffers to the list of defaults. > >> Why? > > Because it's a special case and I'm not convinced it's justified. The intention of adding a list of default values was to allow selecting more than one default value extracted from the context of the command. So after running a command the user can type M-n to see if the first proposed default value is that the user likes. If not, the user can then type M-n again to see the next proposed value and accept it or type M-n to see a few next useful values. However, I agree that putting all buffers pushes this features to the extreme because then the list of defaults is the same as the completion list. But there is one significant difference: the list of defaults is sorted by recency, so switching between several work buffers (more than two) is much easier with `C-x b M-n M-n M-n RET'. OTOH, searching the completion list would be useful in itself independent of searching the history list or the list of defaults because often these three are disjoint sets, and the list of defaults can be presented even when the completion list is empty. > I expect most people who like this will prefer iswitchb anyway. iswitchb radically changes the user interface of the minibuffer, so I highly recommend providing most features of iswitchb to the users who don't like the user interface of iswitchb. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-22 1:17 ` Juri Linkov @ 2008-03-22 17:04 ` Stefan Monnier 2008-03-23 2:17 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-03-22 17:04 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel >>>> BTW, once this is done, we can revert the recent change to the >>>> `read-buffer' that adds all the buffers to the list of defaults. >> >>> Why? >> >> Because it's a special case and I'm not convinced it's justified. > The intention of adding a list of default values was to allow selecting > more than one default value extracted from the context of the command. Yes, I said nothing about this. > However, I agree that putting all buffers pushes this features to the > extreme because then the list of defaults is the same as the completion > list. But there is one significant difference: the list of defaults is > sorted by recency, so switching between several work buffers (more than > two) is much easier with `C-x b M-n M-n M-n RET'. I never said there's no difference. I just think this special case is not justified. Most likely `C-x b M-p M-p M-p RET' would work just as well. > OTOH, searching the completion list would be useful in itself > independent of searching the history list or the list of defaults > because often these three are disjoint sets, and the list of defaults > can be presented even when the completion list is empty. If you like it, feel free to customize your Emacs to provide you this kind of refinement with different commands to search the history, the list of defaults, and the list of completions. But I think the default search function bound to M-r/M-s would benefit from searching all of them. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-22 17:04 ` Stefan Monnier @ 2008-03-23 2:17 ` Juri Linkov 2008-03-23 3:24 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-23 2:17 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> However, I agree that putting all buffers pushes this features to the >> extreme because then the list of defaults is the same as the completion >> list. But there is one significant difference: the list of defaults is >> sorted by recency, so switching between several work buffers (more than >> two) is much easier with `C-x b M-n M-n M-n RET'. > > I never said there's no difference. I just think this special case is > not justified. Most likely `C-x b M-p M-p M-p RET' would work just > as well. This assumes that the user prefers C-x b to switch to a new buffer. But it is not the case since more often many other commands switch to a buffer that don't leave a new buffer name in the history list. >> OTOH, searching the completion list would be useful in itself >> independent of searching the history list or the list of defaults >> because often these three are disjoint sets, and the list of defaults >> can be presented even when the completion list is empty. > > If you like it, feel free to customize your Emacs to provide you this > kind of refinement with different commands to search the history, the > list of defaults, and the list of completions. But I think the default > search function bound to M-r/M-s would benefit from searching all > of them. Hmm, now I tend to agree with you that M-s could search the list of completions as well. Since the list of defaults usually is very short, we could search it first and after that search the list of completions. When the list of defaults is not very short then often there is no completions at all, so this should work quite well. The only problem with C-x b is that the buffer list is sorted alphabetically in the list of completions, but it would be much more useful to search them in the order of recency. I see they are sorted in the function `minibuffer-completion-help' as /* Sort and remove duplicates. */ Lisp_Object tmp = completions = Fsort (completions, Qstring_lessp); Maybe we should create a new function `minibuffer-completion-help-unsorted' for C-x b and possibly other commands that might need to keep the original order of elements too? -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-23 2:17 ` Juri Linkov @ 2008-03-23 3:24 ` Stefan Monnier 0 siblings, 0 replies; 64+ messages in thread From: Stefan Monnier @ 2008-03-23 3:24 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel > The only problem with C-x b is that the buffer list is sorted > alphabetically in the list of completions, but it would be much more > useful to search them in the order of recency. > I see they are sorted in the function `minibuffer-completion-help' as > /* Sort and remove duplicates. */ > Lisp_Object tmp = completions = Fsort (completions, Qstring_lessp); I'm not sure I understand the relevance: M-r and M-s would not use minibuffer-completion-help anyway. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-20 19:35 ` Juri Linkov 2008-03-20 20:07 ` Lennart Borgman (gmail) 2008-03-20 22:13 ` Stefan Monnier @ 2008-03-29 1:00 ` Xavier Maillard 2008-03-29 12:30 ` Juri Linkov 2 siblings, 1 reply; 64+ messages in thread From: Xavier Maillard @ 2008-03-29 1:00 UTC (permalink / raw) To: Juri Linkov; +Cc: monnier, emacs-devel But really there is no need to mix two separate search spaces. There exist already a convenient key sequence to search the completion table: `PgUp C-s'. PgUp switches to the *Completions* buffer and C-s starts searching among completion candidates. Gotcha ! I now understand why sometimes there is this *Completion* buffer that pops up when I do something wrong on my tiny keyboard :) Thank you for the tip ! Xavier -- http://www.gnu.org http://www.april.org http://www.lolica.org ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-29 1:00 ` Xavier Maillard @ 2008-03-29 12:30 ` Juri Linkov 2008-03-29 16:23 ` Drew Adams 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-29 12:30 UTC (permalink / raw) To: Xavier Maillard; +Cc: monnier, emacs-devel > But really there is no need to mix two separate search spaces. > There exist already a convenient key sequence to search the completion > table: `PgUp C-s'. PgUp switches to the *Completions* buffer and > C-s starts searching among completion candidates. > > Gotcha ! I now understand why sometimes there is this > *Completion* buffer that pops up when I do something wrong on my > tiny keyboard :) Thank you for the tip ! No wonder that you sometimes accidentally get the *Completions* buffer. Normally <prior> is bound to previous-history-element, but in some minibuffers it is bound to switch-to-completions. Maybe we should avoid this inconsistency by using another key for switch-to-completions? What about binding switch-to-completions to <M-down> because typing simply <down> starts moving to the next item in a list of defaults and completions. And also to bind a new command switch-to-history (that will display a list of history items in a separate window) to <M-up> because simply <up> moves to the previous history item. Note that these keys are already used in many other programs to open a pop-up list of history/completion items, so they will do what a typical user would expect. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* RE: C-r and C-s in minibuffer should search completion 2008-03-29 12:30 ` Juri Linkov @ 2008-03-29 16:23 ` Drew Adams 2008-03-30 0:38 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Drew Adams @ 2008-03-29 16:23 UTC (permalink / raw) To: 'Juri Linkov', 'Xavier Maillard'; +Cc: monnier, emacs-devel > Normally <prior> is bound to previous-history-element, but in some > minibuffers it is bound to switch-to-completions. Yes, that is poor design, IMO. Not the fact that it has a different meaning in different minibuffer maps (completion vs no completion), but the fact that the `prior' key is naturally associated with the `next' key, and Emacs does not exploit that association - it breaks it. > Maybe we should avoid this inconsistency by using > another key for switch-to-completions? FWIW, Icicles uses `C-insert' for this. And hitting it again takes you back to the minibuffer (and copies the completion at point in *Completions* to the minibuffer` for editing). That key won't work for emacs -nw, but `M-insert' presumably would (in the form of `ESC insert'). (Icicles uses `insert' itself for something else. And Emacs likewise should perhaps reserve `insert' for something that needs to be quick. Switching buffers need not be so quick as to deserve a single key.) > What about binding switch-to-completions to <M-down> because typing > simply <down> starts moving to the next item in a list of defaults > and completions. And also to bind a new command switch-to-history > (that will display a list of history items in a separate window) > to <M-up> because simply <up> moves to the previous history item. Your association is a bit far-fetched, IMO - you are stretching things to fit your proposal, rather than proposing something that seems natural. There is little connection between the idea of having `down' and `up' move to the next and previous items in a series and the idea of switching windows/buffers. Other things being equal: Keys that form natural pairs, such as `down'/`up', `next'/`prior', and `home'/`end' should be reserved for things that perform some sort of succession (i.e., next or previous) behavior. Or for some sort of bracketing (e.g. grouping) behavior, such as start-something...end-something. Or for some sort of complementary behavior (e.g. `insert'/`delete'). The same is true for other such natural pairs of keys: (), [], {}, <>. Succession is a natural choice for pairs, such as `next'/`prior', whose names suggest succession. Opposite behavior can be a natural choice for pairs, such as `insert'/`delete', whose names suggest that. Finally, why use a separate window for history items? Why not simply use *Completions* and let users complete against history items? IOW, use the normal completion mechanism, with everything that it provides. That is what I suggested when I mentioned `M-o', which is the key that Icicles uses for this. You can use `M-o' from any minibuffer, not just during completion. It uses a recursive minibuffer to let you choose from the current input history (using completion) - your choice is inserted in the minibuffer, where you can edit it for the original minibuffer reading. ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-29 16:23 ` Drew Adams @ 2008-03-30 0:38 ` Juri Linkov 2008-03-30 2:38 ` Drew Adams 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-30 0:38 UTC (permalink / raw) To: Drew Adams; +Cc: 'Xavier Maillard', monnier, emacs-devel >> Maybe we should avoid this inconsistency by using >> another key for switch-to-completions? > > FWIW, Icicles uses `C-insert' for this. And hitting it again takes you back to > the minibuffer (and copies the completion at point in *Completions* to the > minibuffer` for editing). That key won't work for emacs -nw, but `M-insert' > presumably would (in the form of `ESC insert'). I agree that `M-insert' makes sense for inserting the completion from the *Completions* buffer to the minibuffer. > There is little connection between the idea of having `down' and `up' move to > the next and previous items in a series and the idea of switching > windows/buffers. <M-down> and <M-up> are used by many other programs that open a pop-up list of history/completion items. So they are natural key for most users and especially for newbies. I also suggest using <M-down> for IDE-like autocompletion that opens a pop-up window with completion in a program buffer. This is usually bound to C-SPC in IDE like Eclipse, but C-SPC is already taken for set-mark-command in Emacs. > Finally, why use a separate window for history items? Why not simply use > *Completions* and let users complete against history items? IOW, use the normal > completion mechanism, with everything that it provides. As there exists already a key that open the *Completions* buffer, it makes sense to do the same for the history list. Below is a patch that implements these ideas. > That is what I suggested when I mentioned `M-o', which is the key that Icicles > uses for this. You can use `M-o' from any minibuffer, not just during > completion. It uses a recursive minibuffer to let you choose from the current > input history (using completion) - your choice is inserted in the minibuffer, > where you can edit it for the original minibuffer reading. You earlier objected to using the same keys that have different bindings in the minibuffer and outside it (cf. using `TAB' in the minibuffer). Since by default M-o is a prefix key for font-lock-fontify function, I think we should find another key. One candidate I propose is C-M-TAB. Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.913 diff -c -r1.913 simple.el *** lisp/simple.el 29 Mar 2008 22:56:17 -0000 1.913 --- lisp/simple.el 30 Mar 2008 00:38:48 -0000 *************** *** 5520,5525 **** --- 5574,5604 ---- (goto-char (point-min)) (search-forward "\n\n" nil t) (forward-line 1)))) + + (defun switch-to-history-completions () + "Select the completion list window for elements of the minibuffer history." + (interactive) + (let ((minibuffer-completion-table + (symbol-value minibuffer-history-variable)) + (minibuffer-completion-predicate nil)) + (switch-to-completions))) + + (define-key minibuffer-local-completion-map [(meta down)] 'switch-to-completions) + (define-key minibuffer-local-completion-map [(meta up)] 'switch-to-history-completions) + + (defun minibuffer-history-complete () + "Complete the minibuffer input against the history list. + Locally bind the current value of `minibuffer-history-variable' + to the completion table `minibuffer-completion-table' before + calling `minibuffer-complete'." + (interactive) + (let ((minibuffer-completion-table + (symbol-value minibuffer-history-variable)) + (minibuffer-completion-predicate nil)) + (minibuffer-complete))) + + (define-key minibuffer-local-map [(meta control tab)] 'minibuffer-history-complete) + \f ;;; Support keyboard commands to turn on various modifiers. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* RE: C-r and C-s in minibuffer should search completion 2008-03-30 0:38 ` Juri Linkov @ 2008-03-30 2:38 ` Drew Adams 0 siblings, 0 replies; 64+ messages in thread From: Drew Adams @ 2008-03-30 2:38 UTC (permalink / raw) To: 'Juri Linkov'; +Cc: 'Xavier Maillard', monnier, emacs-devel > >> Maybe we should avoid this inconsistency by using > >> another key for switch-to-completions? > > > > FWIW, Icicles uses `C-insert' for this. And hitting it > > again takes you back to the minibuffer (and copies the > > completion at point in *Completions* to the > > minibuffer` for editing). That key won't work for emacs > > -nw, but `M-insert' presumably would (in the form of > > `ESC insert'). > > I agree that `M-insert' makes sense for inserting the completion from > the *Completions* buffer to the minibuffer. It makes sense to use the same key to go both directions (minibuffer <--> *Completions*), as I mentioned. Why not? > > There is little connection between the idea of having > > `down' and `up' move to the next and previous items in > > a series and the idea of switching windows/buffers. > > <M-down> and <M-up> are used by many other programs that open a pop-up > list of history/completion items. So they are natural key > for most users and especially for newbies. As I said, there is little connection with the meaning of "next" and "previous". That's the point. Slavishly copying other programs is not a sufficient argument, especially when it comes to key bindings. It can be a secondary argument, but it shouldn't be the only or the primary argument. Otherwise, Emacs would quickly resemble the lowest common denominator, or worse. Other programs are for the most part inferior to Emacs wrt key bindings. Emacs generally chooses key bindings in a reasoned way. I gave arguments why down/up should be reserved for successor/predecessor operations, if possible. You've given no argument for using them for something that is unrelated to that, beyond saying that some other programs use them to open a popup list. There is no reason to have two different keys for switching to *Completions*, which is what you are proposing, AFAICT. If there is already a key that switches to *Completions*, then why can't users also use it to switch to *Completions* when it contains the history list? Why do they need another key for that? That's like saying that although we already have `C-f' for forward-char, we should add `C-<whatever>' for forward-char whenever the buffer contains lines of poetry. > I also suggest using <M-down> for IDE-like autocompletion that opens > a pop-up window with completion in a program buffer. This is usually > bound to C-SPC in IDE like Eclipse, but C-SPC is already taken for > set-mark-command in Emacs. > > > Finally, why use a separate window for history items? Why > > not simply use *Completions* and let users complete against > > history items? IOW, use the normal completion mechanism, > > with everything that it provides. > > As there exists already a key that open the *Completions* buffer, > it makes sense to do the same for the history list. Makes sense to do what "the same"? Add another key, just for switching to *Completions* whenever it contains a history list? Why not really "do the same for the history list" - treat it exactly the same as every other list in *Completions*? When you say "same" it seems you mean "different". Unless I'm missing something, all you've done is fill *Completions* with a set of completions that come from the history list. That's useful, but there is nothing special about it. Completing previous inputs is no different from completing command names or file names or buffer names or anything else. Why add key bindings unnecessarily (Occam)? You need one minibuffer key binding to let users complete against the history list; that's all. > Below is a patch that implements these ideas. > > > That is what I suggested when I mentioned `M-o', which is > > the key that Icicles uses for this. You can use `M-o' from > > any minibuffer, not just during completion. It uses a > > recursive minibuffer to let you choose from the current > > input history (using completion) - your choice is inserted > > in the minibuffer, where you can edit it for the original > > minibuffer reading. > > You earlier objected to using the same keys that have different > bindings in the minibuffer and outside it (cf. using `TAB' in the > minibuffer). Because the indentation binding of TAB is useful in the minibuffer. I made a specific argument about TAB. You cannot generalize from my opposition to changing the meaning of TAB in the minibuffer to suppose that I oppose the reuse of any keys by giving them different minibuffer bindings. And TAB is a particular case in another sense: it is apparently in demand for everything under the sun. I argued to reserve it for things that are related to its existing meanings. > Since by default M-o is a prefix key for font-lock-fontify > function, I think we should find another key. I chose `M-o' precisely because its global binding is not useful in the minibuffer. (Do you think it is?) This is not about blanket rules; you have to consider the details - TAB is not `M-o'. But I don't care whether you use `M-o' or not. It was just a suggestion. I do care that you not use TAB for that, with or without modifiers. > One candidate I propose is C-M-TAB. When will you guys leave TAB alone? Save M-TAB, S-TAB, C-M-TAB, C-S-TAB, and so on for operations that are more closely related to TAB's existing behaviors (and there are already enough of those!). Yes, you could make an argument that this behavior is slightly related, but tomorrow we will find 23 other possible uses for TAB that are all more closely related. I also suggested that completion against the current history use a recursive minibuffer, and that the choice be inserted into the parent minibuffer for editing. That is useful, especially for minibuffer input that does not involve completion. You don't want to be limited to completing the current input against a previous input. You might want to insert more than one previous input (using completion), and edit the combination. I don't agree with any of the proposed changes, but I have no illusions that my disagreement will make any difference. On n'arrete pas le "progres". ^ permalink raw reply [flat|nested] 64+ messages in thread
* RE: C-r and C-s in minibuffer should search completion 2008-03-20 19:13 C-r and C-s in minibuffer should search completion Stefan Monnier 2008-03-20 19:35 ` Juri Linkov @ 2008-03-20 20:44 ` Drew Adams 2008-03-25 21:44 ` Juri Linkov 2 siblings, 0 replies; 64+ messages in thread From: Drew Adams @ 2008-03-20 20:44 UTC (permalink / raw) To: 'Stefan Monnier', emacs-devel > I believe C-s and C-r in the minibuffer should not > only search the history but the completion table > as well (at least when it's not a function). > > Could someone implement this feature? 1. What's wrong with keeping C-s and C-r for searching minibuffer text? That's useful. 2. We have M-s and M-r for searching the history. 3. I proposed M-o for completion against the history: > > Could you propose a different key to complete > > history lists in *all* minibuffers? > > Yes, I could. The key that Icicles uses for this is M-o. > > http://www.emacswiki.org/cgi-bin/wiki/ > Icicles_-_History_Enhancements#toc4 (That link also describes other useful ways to access history items.) Pick a different key from M-o, if you like, but a separate binding for history completion is better than co-opting the isearch bindings. ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-20 19:13 C-r and C-s in minibuffer should search completion Stefan Monnier 2008-03-20 19:35 ` Juri Linkov 2008-03-20 20:44 ` Drew Adams @ 2008-03-25 21:44 ` Juri Linkov 2008-03-26 2:31 ` Stefan Monnier 2 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-25 21:44 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel > I believe C-s and C-r in the minibuffer should not only search the > history but the completion table as well (at least when it's not > a function). > > Could someone implement this feature? I now have an idea how to implement this feature. Some time ago I submitted a patch that introduces a new variable `minibuffer-default-set-function' that extends a list of defaults when minibuffer position hits the bottom of the list of defaults. http://lists.gnu.org/archive/html/emacs-devel/2007-12/msg00179.html This patch was approved by Richard but not installed because it was undecided where to move mailcap.el. The patch uses this variable for `shell-command' to append a list of available mailcap commands to the list of defaults only when the user types M-n below the default value. The same could be done for the list of completions. The patch below implements a new function `minibuffer-default-add-completions' that appends a list of all completions to the end of the list of defaults. It would be good to use this function by default since it is useful to search the completion table in all minibuffers that have it. Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.911 diff -c -r1.911 simple.el *** lisp/simple.el 23 Mar 2008 22:52:20 -0000 1.911 --- lisp/simple.el 25 Mar 2008 21:43:34 -0000 *************** *** 1304,1313 **** --- 1305,1339 ---- (defvar minibuffer-temporary-goal-position nil) + (defvar minibuffer-default-set-function 'minibuffer-default-add-completions + "*Function run by `goto-history-element' before using `minibuffer-default'. + This is useful to dynamically set the value of `minibuffer-default' + before `goto-history-element' reads it when moves into the future.") + + (make-variable-buffer-local 'minibuffer-default-set-function) + + (defun minibuffer-default-add-completions () + "Return a list of all completions without the default value. + This function is used to add all elements of the completion table to + the end of the list of defaults after the default value." + (interactive) + (let ((def minibuffer-default) + (all (all-completions "" + minibuffer-completion-table + minibuffer-completion-predicate + t))) + (if (listp def) + (append def all) + (setq all (cons def (delete def all)))))) + (defun goto-history-element (nabs) "Puts element of the minibuffer history in the minibuffer. The argument NABS specifies the absolute history position." (interactive "p") + (when (and (functionp minibuffer-default-set-function) + (< nabs (if (stringp minibuffer-default) -1 0))) + (setq minibuffer-default (funcall minibuffer-default-set-function) + minibuffer-default-set-function nil)) (let ((minimum (if minibuffer-default (- (if (listp minibuffer-default) (length minibuffer-default) -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-25 21:44 ` Juri Linkov @ 2008-03-26 2:31 ` Stefan Monnier 2008-03-26 7:01 ` Drew Adams 2008-03-26 10:56 ` Juri Linkov 0 siblings, 2 replies; 64+ messages in thread From: Stefan Monnier @ 2008-03-26 2:31 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel >> I believe C-s and C-r in the minibuffer should not only search the >> history but the completion table as well (at least when it's not >> a function). >> >> Could someone implement this feature? > I now have an idea how to implement this feature. > Some time ago I submitted a patch that introduces a new variable > `minibuffer-default-set-function' that extends a list of defaults > when minibuffer position hits the bottom of the list of defaults. How would that help? M-r/M-s doesn't seem to search minibuffer-default. But I guess it does help with C-s, which is what I mistyped. Actually, now that I take a closer look. Why do we have both C-s/C-r and M-r/M-s? They seem redundant. > + (defun minibuffer-default-add-completions () > + "Return a list of all completions without the default value. > + This function is used to add all elements of the completion table to > + the end of the list of defaults after the default value." > + (interactive) > + (let ((def minibuffer-default) > + (all (all-completions "" > + minibuffer-completion-table > + minibuffer-completion-predicate > + t))) > + (if (listp def) > + (append def all) > + (setq all (cons def (delete def all)))))) This is not good when the completion table is a function that takes a long time, because then you have to wait for the completion table to be built before you can get the actual real DEF. Better would be to call the function only after we consumed minibuffer-default. Or maybe only do it when the completion-table is not a function. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* RE: C-r and C-s in minibuffer should search completion 2008-03-26 2:31 ` Stefan Monnier @ 2008-03-26 7:01 ` Drew Adams 2008-03-26 14:41 ` Stefan Monnier 2008-03-26 10:56 ` Juri Linkov 1 sibling, 1 reply; 64+ messages in thread From: Drew Adams @ 2008-03-26 7:01 UTC (permalink / raw) To: 'Stefan Monnier', 'Juri Linkov'; +Cc: emacs-devel > Actually, now that I take a closer look. Why do we have both C-s/C-r > and M-r/M-s? They seem redundant. They are not redundant now, and I hope we don't make them redundant or combine them. C-s searches the text in the minibuffer. M-s searches the input history. M-s is a regexp search; C-s is not (but C-M-s is). I'm sure you know that, so I probably misunderstand your proposal. > This is not good when the completion table is a function that takes > a long time, because then you have to wait for the completion table to > be built before you can get the actual real DEF. > > Better would be to call the function only after we consumed > minibuffer-default. Or maybe only do it when the completion-table is > not a function. I really do not see any gain by confounding history-list search with completion-table search (and now with minibuffer-text search also?). I think the proposed amalgam is a mistake. What problem is it trying to solve? [What is useful, however, is adding a key to _complete_ against the current history - in all minibuffer maps. I suggested M-o for that.] ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-26 7:01 ` Drew Adams @ 2008-03-26 14:41 ` Stefan Monnier 2008-03-26 17:07 ` Drew Adams 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-03-26 14:41 UTC (permalink / raw) To: Drew Adams; +Cc: 'Juri Linkov', emacs-devel > C-s searches the text in the minibuffer. It used to do it in Emacs-22, but it's not doing just that any more now. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* RE: C-r and C-s in minibuffer should search completion 2008-03-26 14:41 ` Stefan Monnier @ 2008-03-26 17:07 ` Drew Adams 0 siblings, 0 replies; 64+ messages in thread From: Drew Adams @ 2008-03-26 17:07 UTC (permalink / raw) To: 'Stefan Monnier'; +Cc: 'Juri Linkov', emacs-devel > > C-s searches the text in the minibuffer. > > It used to do it in Emacs-22, but it's not doing just that > any more now. I haven't seen the details, but my first impression is, "Pity". Cursory reading (apologies for not digging in more earnestly) hints that completion is willy nilly becoming a chimera. Some things belong together and work well together; other things don't. How about summarizing the changes made since Emacs 22 as well as the proposed behavior and its rationale? ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-26 2:31 ` Stefan Monnier 2008-03-26 7:01 ` Drew Adams @ 2008-03-26 10:56 ` Juri Linkov 2008-03-26 14:47 ` Stefan Monnier 1 sibling, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-26 10:56 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> I now have an idea how to implement this feature. > >> Some time ago I submitted a patch that introduces a new variable >> `minibuffer-default-set-function' that extends a list of defaults >> when minibuffer position hits the bottom of the list of defaults. > > How would that help? M-r/M-s doesn't seem to search minibuffer-default. It would be trivial to add in `previous-matching-history-element' the same extending a list of defaults with a list of completions when M-s hits the bottom of the list. > But I guess it does help with C-s, which is what I mistyped. > Actually, now that I take a closer look. Why do we have both C-s/C-r > and M-r/M-s? They seem redundant. As everywhere in normal modes there are two search types: incremental and non-incremental, in the minibuffer C-s/C-r provides incremental search, and M-r/M-s - non-incremental. In normal modes non-incremental search is provided by `C-s RET' but in the minibuffer it displays a different prompt ("Search: ") than M-s "Next element matching (regexp): ". Also M-s is a backward-compatible keybinding for users that already use it for many years. > This is not good when the completion table is a function that takes > a long time, because then you have to wait for the completion table to > be built before you can get the actual real DEF. Just as when the user needs to see a full list of completions, the user can bear a long time to built the completion table, when the user needs to search a full list of completions, it is exactly the same situation: the user have to wait when the user wants to search the completion list (though I don't know where in Emacs building the completion table takes too long time, even C-h f takes less than 1 sec on modern hardware, and woman takes 2 sec to build her very large completion table but does before displaying the minibuffer.) > Better would be to call the function only after we consumed > minibuffer-default. Or maybe only do it when the completion-table is > not a function. It now calls the function after moved below minibuffer-default so it seems this is good, and also it seems good to build the completion-table even from a function because I think it is not a problem to wait a few seconds if there is a need to search the completion-table built from a function. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-26 10:56 ` Juri Linkov @ 2008-03-26 14:47 ` Stefan Monnier 2008-03-27 0:44 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-03-26 14:47 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel >> How would that help? M-r/M-s doesn't seem to search minibuffer-default. > It would be trivial to add in `previous-matching-history-element' the > same extending a list of defaults with a list of completions when M-s > hits the bottom of the list. Oh, I see, so I didn't miss anything. I guess that's OK, except that part is still missing ;-) And since C-s works better anyway (who wants non-incremental search when you can have isearch instead). >> This is not good when the completion table is a function that takes >> a long time, because then you have to wait for the completion table to >> be built before you can get the actual real DEF. > Just as when the user needs to see a full list of completions, the user > can bear a long time to build the completion table, when the user needs > to search a full list of completions, it is exactly the same situation: The difference is that in this case the user may not want to search anything at all, she just wants her M-n to bring up the default which was already provided and doesn't require any computation. > (though I don't know where in Emacs building the completion table takes > too long time, even C-h f takes less than 1 sec on modern hardware, and > woman takes 2 sec to build her very large completion table but does before > displaying the minibuffer.) Believe me there are such cases. Info-lookup is one, M-. is another, Tramp is yet another, tags-completion in PCL-CVS, .... the list goes on and on. >> Better would be to call the function only after we consumed >> minibuffer-default. Or maybe only do it when the completion-table is >> not a function. > It now calls the function after moved below minibuffer-default so it seems > this is good, There seem to be some typo or something missing from your sentence, but IIUC you have implemented what I suggested so that M-n only computes the completion table after having consumed the normal defaults? Can you send the new code? Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-26 14:47 ` Stefan Monnier @ 2008-03-27 0:44 ` Juri Linkov 2008-03-27 2:43 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-27 0:44 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel > There seem to be some typo or something missing from your sentence, but > IIUC you have implemented what I suggested so that M-n only computes the > completion table after having consumed the normal defaults? Can you > send the new code? Yep, this was already implemented in my previous patch. If there exist a default value, then the first M-n just inserts this default value to the minibuffer without any computation, and only next M-n (that would otherwise signal an error) computes the completion table. Below is a new patch with a small improvement: it introduces a new variable `minibuffer-default-add-p' useful to add more elements to the list of defaults several times in chunks when needed (it can keep the current state of added elements to the list of defaults): Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.912 diff -c -r1.912 simple.el *** lisp/simple.el 26 Mar 2008 03:40:40 -0000 1.912 --- lisp/simple.el 27 Mar 2008 00:42:03 -0000 *************** *** 1304,1313 **** --- 1305,1352 ---- (defvar minibuffer-temporary-goal-position nil) + (defvar minibuffer-default-add-function 'minibuffer-default-add-completions + "Function run by `goto-history-element' before consuming `minibuffer-default'. + This is useful to dynamically set the value of `minibuffer-default' + before `goto-history-element' reads it when it moves into the future.") + + (make-variable-buffer-local 'minibuffer-default-add-function) + + (defvar minibuffer-default-add-p t + "When non-nil, add more elements to the end of the list of default values. + Any non-nil value causes `goto-history-element' to add more elements + to a list of defaults by calling a function defined by + `minibuffer-default-add-function'. When this function + doesn't need to add more elements after its call, it should + set this variable to nil.") + + (make-variable-buffer-local 'minibuffer-default-add-p) + + (defun minibuffer-default-add-completions () + "Return a list of all completions without the default value. + This function is used to add all elements of the completion table to + the end of the list of defaults after the default value." + (interactive) + (let ((def minibuffer-default) + (all (all-completions "" + minibuffer-completion-table + minibuffer-completion-predicate + t))) + (setq minibuffer-default-add-p nil) + (if (listp def) + (append def all) + (cons def (delete def all))))) + (defun goto-history-element (nabs) "Puts element of the minibuffer history in the minibuffer. The argument NABS specifies the absolute history position." (interactive "p") + (when (and minibuffer-default-add-p + (functionp minibuffer-default-add-function) + (< nabs (- (if (listp minibuffer-default) + (length minibuffer-default) + 1)))) + (setq minibuffer-default (funcall minibuffer-default-add-function))) (let ((minimum (if minibuffer-default (- (if (listp minibuffer-default) (length minibuffer-default) -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-27 0:44 ` Juri Linkov @ 2008-03-27 2:43 ` Stefan Monnier 2008-03-27 23:43 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-03-27 2:43 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel >> There seem to be some typo or something missing from your sentence, but >> IIUC you have implemented what I suggested so that M-n only computes the >> completion table after having consumed the normal defaults? Can you >> send the new code? > Yep, this was already implemented in my previous patch. I must have missed it. > If there exist a default value, then the first M-n just inserts this > default value to the minibuffer without any computation, and only next > M-n (that would otherwise signal an error) computes the > completion table. Yes, that's good. > Below is a new patch with a small improvement: it introduces a new > variable `minibuffer-default-add-p' useful to add more elements to the > list of defaults several times in chunks when needed (it can keep the > current state of added elements to the list of defaults): OK, then please remove (make-variable-buffer-local 'minibuffer-default-add-function). And I suggest to change minibuffer-default-add-p into minibuffer-default-add-done (and to reverse its default to nil). Also the docstring of minibuffer-default-add-function needs to mention that the function should set minibuffer-default-add-done. This said, I'm wondering when the chunked computation makes sense. Do you have an example in mind? Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-27 2:43 ` Stefan Monnier @ 2008-03-27 23:43 ` Juri Linkov 2008-03-29 4:03 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-27 23:43 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> Below is a new patch with a small improvement: it introduces a new >> variable `minibuffer-default-add-p' useful to add more elements to the >> list of defaults several times in chunks when needed (it can keep the >> current state of added elements to the list of defaults): > > OK, then please remove (make-variable-buffer-local > 'minibuffer-default-add-function). And I suggest to change > minibuffer-default-add-p into minibuffer-default-add-done (and to > reverse its default to nil). In the patch below I renamed minibuffer-default-add-p into minibuffer-default-add-done, changed its default to nil, and removed make-variable-buffer-local for minibuffer-default-add-function. Also I moved (setq minibuffer-default-add-done t) to goto-history-element just before the call to minibuffer-default-add-function, so there is no need to set this variable to t in minibuffer-default-add-function explicitly in normal cases. When necessary, minibuffer-default-add-function can nullify minibuffer-default-add-done to be able call this function more than once. > Also the docstring of minibuffer-default-add-function needs to mention > that the function should set minibuffer-default-add-done. minibuffer-default-add-function now doesn't need to set minibuffer-default-add-done any more, so I updated the docstrings accordingly. > This said, I'm wondering when the chunked computation makes sense. > Do you have an example in mind? I don't have a concrete example. When the chunked computation makes sense, a function defined by minibuffer-default-add-function can use a new specific global variable that will count the number of function calls. But this is not necessary now, and the main thing I added is the possibility to call this function more than once, when this functions sets minibuffer-default-add-done to nil. This patch also changes the error message "End of history; no next item" to "End of defaults; no next item" for the end of the list of defaults. Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.912 diff -c -r1.912 simple.el *** lisp/simple.el 26 Mar 2008 03:40:40 -0000 1.912 --- lisp/simple.el 27 Mar 2008 23:35:05 -0000 *************** *** 1304,1313 **** --- 1305,1353 ---- (defvar minibuffer-temporary-goal-position nil) + (defvar minibuffer-default-add-function 'minibuffer-default-add-completions + "Function run by `goto-history-element' before consuming `minibuffer-default'. + This is useful to dynamically add more elements to the list `minibuffer-default' + when `goto-history-element' reaches the end of this list. + Before calling this function `goto-history-element' sets the variable + `minibuffer-default-add-done' to t, so it will call this function only + once. In special cases, when this function needs to be called more + than once, it can set `minibuffer-default-add-done' to nil explicitly, + overriding the setting of this variable to t in `goto-history-element'.") + + (defvar minibuffer-default-add-done nil + "When nil, add more elements to the end of the list of default values. + The value nil causes `goto-history-element' to add more elements to + the list of defaults when it reaches the end of this list. It does + this by calling a function defined by `minibuffer-default-add-function'.") + + (make-variable-buffer-local 'minibuffer-default-add-done) + + (defun minibuffer-default-add-completions () + "Return a list of all completions without the default value. + This function is used to add all elements of the completion table to + the end of the list of defaults just after the default value." + (interactive) + (let ((def minibuffer-default) + (all (all-completions "" + minibuffer-completion-table + minibuffer-completion-predicate + t))) + (if (listp def) + (append def all) + (cons def (delete def all))))) + (defun goto-history-element (nabs) "Puts element of the minibuffer history in the minibuffer. The argument NABS specifies the absolute history position." (interactive "p") + (when (and (not minibuffer-default-add-done) + (functionp minibuffer-default-add-function) + (< nabs (- (if (listp minibuffer-default) + (length minibuffer-default) + 1)))) + (setq minibuffer-default-add-done t + minibuffer-default (funcall minibuffer-default-add-function))) (let ((minimum (if minibuffer-default (- (if (listp minibuffer-default) (length minibuffer-default) *************** *** 1320,1326 **** (minibuffer-contents-no-properties))) (if (< nabs minimum) (if minibuffer-default ! (error "End of history; no next item") (error "End of history; no default available"))) (if (> nabs (length (symbol-value minibuffer-history-variable))) (error "Beginning of history; no preceding item")) --- 1360,1366 ---- (minibuffer-contents-no-properties))) (if (< nabs minimum) (if minibuffer-default ! (error "End of defaults; no next item") (error "End of history; no default available"))) (if (> nabs (length (symbol-value minibuffer-history-variable))) (error "Beginning of history; no preceding item")) Index: lisp/bindings.el =================================================================== RCS file: /sources/emacs/emacs/lisp/bindings.el,v retrieving revision 1.202 diff -c -r1.202 bindings.el *** lisp/bindings.el 26 Mar 2008 03:32:46 -0000 1.202 --- lisp/bindings.el 27 Mar 2008 23:35:36 -0000 *************** *** 650,656 **** "^No later matching history item$" "^No earlier matching history item$" "^End of history; no default available$" ! "^End of history; no next item$" "^Beginning of history; no preceding item$" "^No recursive edit is in progress$" "^Changes to be undone are outside visible portion of buffer$" --- 650,656 ---- "^No later matching history item$" "^No earlier matching history item$" "^End of history; no default available$" ! "^End of defaults; no next item$" "^Beginning of history; no preceding item$" "^No recursive edit is in progress$" "^Changes to be undone are outside visible portion of buffer$" -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-27 23:43 ` Juri Linkov @ 2008-03-29 4:03 ` Stefan Monnier 2008-03-30 0:44 ` Juri Linkov 2008-03-30 0:44 ` minibuffer-default-add-shell-commands (was: C-r and C-s in minibuffer should search completion) Juri Linkov 0 siblings, 2 replies; 64+ messages in thread From: Stefan Monnier @ 2008-03-29 4:03 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel > In the patch below I renamed minibuffer-default-add-p into > minibuffer-default-add-done, changed its default to nil, and > removed make-variable-buffer-local for minibuffer-default-add-function. Thanks, please install it. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-29 4:03 ` Stefan Monnier @ 2008-03-30 0:44 ` Juri Linkov 2008-03-30 4:01 ` Stefan Monnier 2008-03-30 0:44 ` minibuffer-default-add-shell-commands (was: C-r and C-s in minibuffer should search completion) Juri Linkov 1 sibling, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-30 0:44 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> In the patch below I renamed minibuffer-default-add-p into >> minibuffer-default-add-done, changed its default to nil, and >> removed make-variable-buffer-local for minibuffer-default-add-function. > > Thanks, please install it. Done. I also reverted the recent change in `call-interactively' that adds buffers to the list of defaults. However, there is one problem now: `C-x b M-n M-n' puts in the minibuffer the name of the current buffer because the current buffer is in the front of the buffer list acquired from the completion table in read-buffer. But it makes no sense to switch to the current buffer, so the case 'B' in `call-interactively' specially removes the current buffer from the default value by using `Fother_buffer' specially for the command `switch-to-buffer'. I see no other way of removing the current buffer from the list for M-n than using the following patch for `minibuffer-default-add-completions'. It seems there is no other suitable place to remove the current buffer in the call chain: `C-x b' -> `call-interactively' -> `read-buffer' -> `completing-read' with `internal-complete-buffer' -> `minibuffer-default-add-completions'. This change should also work for all commands that read a buffer name because when they need the current buffer, they usually put the current buffer to the default value. So it would be ok to remove it from the list. Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.913 diff -c -r1.913 simple.el *** lisp/simple.el 29 Mar 2008 22:56:17 -0000 1.913 --- lisp/simple.el 30 Mar 2008 00:43:14 -0000 *************** *** 1332,1337 **** --- 1333,1343 ---- minibuffer-completion-table minibuffer-completion-predicate t))) + + ;; Remove the current buffer from the list of buffer completions + (when (eq minibuffer-completion-table 'internal-complete-buffer) + (setq all (cdr all))) + (if (listp def) (append def all) (cons def (delete def all))))) -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-30 0:44 ` Juri Linkov @ 2008-03-30 4:01 ` Stefan Monnier 2008-03-30 18:32 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-03-30 4:01 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel > Done. > I also reverted the recent change in `call-interactively' that adds > buffers to the list of defaults. Thanks. > However, there is one problem now: `C-x b M-n M-n' puts in the minibuffer > the name of the current buffer because the current buffer is in the front > of the buffer list acquired from the completion table in read-buffer. This is a very minor problem. > But it makes no sense to switch to the current buffer, so the case 'B' Then switch-to-buffer should use a completion predicate that rules out the current-buffer. And the history functions should pay attention to it. > *************** > *** 1332,1337 **** > --- 1333,1343 ---- > minibuffer-completion-table > minibuffer-completion-predicate > t))) > + > + ;; Remove the current buffer from the list of buffer completions > + (when (eq minibuffer-completion-table 'internal-complete-buffer) > + (setq all (cdr all))) > + > (if (listp def) > (append def all) > (cons def (delete def all))))) No, this is a hack that will surely bite us down the road. The minor problem it's trying to fix does not justify breaking abstraction in this way. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-30 4:01 ` Stefan Monnier @ 2008-03-30 18:32 ` Juri Linkov 2008-03-30 22:41 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-30 18:32 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> However, there is one problem now: `C-x b M-n M-n' puts in the minibuffer >> the name of the current buffer because the current buffer is in the front >> of the buffer list acquired from the completion table in read-buffer. > > This is a very minor problem. This is a usability problem for users who will prefer using `C-x b M-n M-n' to switch buffers by recency. And the current buffer will be annoying in this list. >> But it makes no sense to switch to the current buffer, so the case 'B' > > Then switch-to-buffer should use a completion predicate that rules out > the current-buffer. And the history functions should pay attention to it. The completion list still should contain the current buffer for other commands that read a buffer name and whose semantics may require the presence of the current buffer in the completion list. Since removing the current buffer from the list of defaults is necessary only for three commands `C-x b', `C-x 4 b' and `C-x 5 b', I propose just to check for their names before removing the current buffer from the list: Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.913 diff -c -r1.913 simple.el *** lisp/simple.el 29 Mar 2008 22:56:17 -0000 1.913 --- lisp/simple.el 30 Mar 2008 18:32:11 -0000 *************** *** 1304,1309 **** --- 1305,1318 ---- (defvar minibuffer-temporary-goal-position nil) + (defvar minibuffer-original-command nil + "Name of the command that invoked this minibuffer.") + + (add-hook 'minibuffer-setup-hook 'minibuffer-initialize) + + (defun minibuffer-initialize () + (set (make-local-variable 'minibuffer-original-command) this-command)) + (defvar minibuffer-default-add-function 'minibuffer-default-add-completions "Function run by `goto-history-element' before consuming `minibuffer-default'. This is useful to dynamically add more elements to the list `minibuffer-default' *************** *** 1332,1337 **** --- 1341,1354 ---- minibuffer-completion-table minibuffer-completion-predicate t))) + + ;; Remove the current buffer from the list of buffer completions + (when (member minibuffer-original-command + '(switch-to-buffer + switch-to-buffer-other-window + switch-to-buffer-other-frame)) + (setq all (cdr all))) + (if (listp def) (append def all) (cons def (delete def all))))) -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-30 18:32 ` Juri Linkov @ 2008-03-30 22:41 ` Stefan Monnier 2008-03-30 23:50 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-03-30 22:41 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel >>> However, there is one problem now: `C-x b M-n M-n' puts in the minibuffer >>> the name of the current buffer because the current buffer is in the front >>> of the buffer list acquired from the completion table in read-buffer. >> >> This is a very minor problem. > This is a usability problem for users who will prefer using `C-x b M-n M-n' > to switch buffers by recency. And the current buffer will be annoying > in this list. Again, a very minor problem. >>> But it makes no sense to switch to the current buffer, so the case 'B' >> >> Then switch-to-buffer should use a completion predicate that rules out >> the current-buffer. And the history functions should pay attention to it. > The completion list still should contain the current buffer for other > commands that read a buffer name and whose semantics may require > the presence of the current buffer in the completion list. Is that supposed to disagree with what I wrote? > Since removing the current buffer from the list of defaults is necessary > only for three commands `C-x b', `C-x 4 b' and `C-x 5 b', I propose just > to check for their names before removing the current buffer from the list: No, this is the wrong way to go about it. The special code should be in C-x b, C-x 4 b, and C-x 5 b. Checking the caller inside the minibuffer is *bad*. I already suggested a much better solution: use a minibuffer-completion-predicate. That's what it's for. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-30 22:41 ` Stefan Monnier @ 2008-03-30 23:50 ` Juri Linkov 2008-03-31 2:11 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-30 23:50 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel > The special code should be in C-x b, C-x 4 b, and C-x 5 b. > Checking the caller inside the minibuffer is *bad*. I already > suggested a much better solution: use a minibuffer-completion-predicate. > That's what it's for. C-x b switch-to-buffer has an interactive spec in buffer.c "BSwitch to buffer: ". Do you mean replacing it with an expression that uses `minibuffer-with-setup-hook' to bind `minibuffer-completion-predicate' to a new predicate that rules out the current-buffer? -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-30 23:50 ` Juri Linkov @ 2008-03-31 2:11 ` Stefan Monnier 2008-04-03 22:59 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-03-31 2:11 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel >> The special code should be in C-x b, C-x 4 b, and C-x 5 b. >> Checking the caller inside the minibuffer is *bad*. I already >> suggested a much better solution: use a minibuffer-completion-predicate. >> That's what it's for. > C-x b switch-to-buffer has an interactive spec in buffer.c > "BSwitch to buffer: ". Do you mean replacing it with an > expression that uses `minibuffer-with-setup-hook' to bind > `minibuffer-completion-predicate' to a new predicate that > rules out the current-buffer? Actually, looking at the code some more, I'd suggest to add a `predicate' arg to `read-buffer' and then use it in switch-to-buffer (which would clearly need to be changed not to use a string-spec but a lisp-spec for its interactive spec). Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-03-31 2:11 ` Stefan Monnier @ 2008-04-03 22:59 ` Juri Linkov 2008-04-04 1:18 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-04-03 22:59 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel > Actually, looking at the code some more, I'd suggest to add > a `predicate' arg to `read-buffer' and then use it in switch-to-buffer > (which would clearly need to be changed not to use a string-spec but > a lisp-spec for its interactive spec). Adding a new argument to `read-buffer' will cause the argument list mismatch between `read-buffer' and `read-buffer-function', and calling `read-buffer-function' with an additional argument will break existing code. But I now have an idea how to accomplish this task without adding a new argument to `read-buffer'. The patch below adds a new function `read-buffer-to-switch' that binds `minibuffer-default-add-function' to `minibuffer-default-add-buffers' that omits the current buffer from the list of defaults before calling `read-buffer': Index: src/buffer.c =================================================================== RCS file: /sources/emacs/emacs/src/buffer.c,v retrieving revision 1.557 diff -c -r1.557 buffer.c *** src/buffer.c 2 Apr 2008 20:15:11 -0000 1.557 --- src/buffer.c 3 Apr 2008 22:56:56 -0000 *************** *** 1767,1773 **** return buf; } ! DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ", doc: /* Select buffer BUFFER in the current window. If BUFFER does not identify an existing buffer, then this function creates a buffer with that name. --- 1767,1774 ---- return buf; } ! DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, ! "(list (read-buffer-to-switch \"Switch to buffer: \"))", doc: /* Select buffer BUFFER in the current window. If BUFFER does not identify an existing buffer, then this function creates a buffer with that name. Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.967 diff -c -r1.967 files.el *** lisp/files.el 3 Apr 2008 20:06:45 -0000 1.967 --- lisp/files.el 3 Apr 2008 22:57:00 -0000 *************** *** 1033,1038 **** --- 1033,1064 ---- (rename-file encoded new-encoded ok-if-already-exists) newname)) \f + (defun minibuffer-default-add-buffers () + "Return a list of all buffer completions without the current buffer. + This function is used to add all elements of the buffer name completion + table to the end of the list of defaults just after the default value." + (interactive) + (let ((def minibuffer-default) + (all (all-completions "" + minibuffer-completion-table + minibuffer-completion-predicate + t))) + ;; Remove the current buffer from the list of buffer completions + (setq all (cdr all)) + (if (listp def) + (append def all) + (cons def (delete def all))))) + + (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-default-add-function) + 'minibuffer-default-add-buffers)) + (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 *************** *** 1047,1053 **** 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) --- 1073,1080 ---- 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) *************** *** 1061,1067 **** 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 --- 1088,1095 ---- 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 -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-03 22:59 ` Juri Linkov @ 2008-04-04 1:18 ` Stefan Monnier 2008-04-06 20:45 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-04-04 1:18 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel >> Actually, looking at the code some more, I'd suggest to add >> a `predicate' arg to `read-buffer' and then use it in switch-to-buffer >> (which would clearly need to be changed not to use a string-spec but >> a lisp-spec for its interactive spec). > Adding a new argument to `read-buffer' will cause the argument list > mismatch between `read-buffer' and `read-buffer-function', and > calling `read-buffer-function' with an additional argument will > break existing code. Then lets fix the existing code. > But I now have an idea how to accomplish this task without adding a > new argument to `read-buffer'. The patch below adds a new function > `read-buffer-to-switch' that binds `minibuffer-default-add-function' to > `minibuffer-default-add-buffers' that omits the current buffer from the > list of defaults before calling `read-buffer': That's ugly. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-04 1:18 ` Stefan Monnier @ 2008-04-06 20:45 ` Juri Linkov 2008-04-07 15:32 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-04-06 20:45 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> Adding a new argument to `read-buffer' will cause the argument list >> mismatch between `read-buffer' and `read-buffer-function', and >> calling `read-buffer-function' with an additional argument will >> break existing code. > > Then lets fix the existing code. This means changing several places in Emacs and still breaking compatibility with external packages, and all this hassle just for fixing a minor problem. I think this fix is disproportional to the problem. OTOH, my latest patch implements exactly what is needed: using your suggestion to place code in the interactive spec of switch-buffer-*, it also sets a special function minibuffer-default-add-function that removes the current buffer from the list of defaults of switch-buffer-* commands. Thus, this is a very localized fix. I spent enough time trying hard to find a better solution, but I see no better. I propose to install this fix and move to more important things. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-06 20:45 ` Juri Linkov @ 2008-04-07 15:32 ` Stefan Monnier 2008-04-15 22:28 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-04-07 15:32 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel > OTOH, my latest patch implements exactly what is needed: using your > suggestion to place code in the interactive spec of switch-buffer-*, > it also sets a special function minibuffer-default-add-function > that removes the current buffer from the list of defaults of > switch-buffer-* commands. Yes, that's an acceptable solution, but really if there are only 2 buffers, C-x b TAB should select the only other buffer, so the better solution is to fix the completion table. > Thus, this is a very localized fix. I spent enough time trying hard > to find a better solution, but I see no better. I propose to install > this fix and move to more important things. Sure, Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-07 15:32 ` Stefan Monnier @ 2008-04-15 22:28 ` Juri Linkov 2008-04-16 2:08 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-04-15 22:28 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel > Yes, that's an acceptable solution, but really if there are only > 2 buffers, C-x b TAB should select the only other buffer, so the better > solution is to fix the completion table. On a par with your efforts to move minibuffer stuff to minibuffer.el, I've ported the existing function `internal-complete-buffer' to Lisp and created a new function `internal-complete-buffer-sans-current' to remove the current buffer from the completion table for `C-x b' family of commands. I also considered using `complete-with-action' internally in `internal-complete-buffer' since it uses the same code pattern, but `complete-with-action' doesn't call `all-completions' with the non-nil arg `hide-spaces'. Below is a complete patch that causes `C-x b TAB' to omit the current buffer from the completion table: Index: src/minibuf.c =================================================================== RCS file: /sources/emacs/emacs/src/minibuf.c,v retrieving revision 1.345 diff -c -r1.345 minibuf.c *** src/minibuf.c 9 Apr 2008 19:33:51 -0000 1.345 --- src/minibuf.c 15 Apr 2008 22:27:45 -0000 *************** *** 1944,1967 **** return Qt; } - DEFUN ("internal-complete-buffer", Finternal_complete_buffer, Sinternal_complete_buffer, 3, 3, 0, - doc: /* Perform completion on buffer names. - If the argument FLAG is nil, invoke `try-completion', if it's t, invoke - `all-completions', otherwise invoke `test-completion'. - - The arguments STRING and PREDICATE are as in `try-completion', - `all-completions', and `test-completion'. */) - (string, predicate, flag) - Lisp_Object string, predicate, flag; - { - if (NILP (flag)) - return Ftry_completion (string, Vbuffer_alist, predicate); - else if (EQ (flag, Qt)) - return Fall_completions (string, Vbuffer_alist, predicate, Qt); - else /* assume `lambda' */ - return Ftest_completion (string, Vbuffer_alist, predicate); - } - /* Like assoc but assumes KEY is a string, and ignores case if appropriate. */ DEFUN ("assoc-string", Fassoc_string, Sassoc_string, 2, 3, 0, --- 1944,1949 ---- *************** *** 2220,2226 **** defsubr (&Sread_string); defsubr (&Sread_command); defsubr (&Sread_variable); - defsubr (&Sinternal_complete_buffer); defsubr (&Sread_buffer); defsubr (&Sread_no_blanks_input); defsubr (&Sminibuffer_depth); --- 2202,2207 ---- Index: lisp/minibuffer.el =================================================================== RCS file: /sources/emacs/emacs/lisp/minibuffer.el,v retrieving revision 1.13 diff -c -r1.13 minibuffer.el *** lisp/minibuffer.el 14 Apr 2008 22:04:38 -0000 1.13 --- lisp/minibuffer.el 15 Apr 2008 22:27:03 -0000 *************** *** 730,734 **** --- 730,758 ---- 'completion--file-name-table) "Internal subroutine for `read-file-name'. Do not call this.") + (defun internal-complete-buffer (string predicate flag) + "Perform completion on buffer names. + If the argument FLAG is nil, invoke `try-completion', if it's t, invoke + `all-completions', otherwise invoke `test-completion'. + + The arguments STRING and PREDICATE are as in `try-completion', + `all-completions', and `test-completion'." + (let ((table (mapcar 'buffer-name (buffer-list)))) + (cond + ((null flag) (try-completion string table predicate)) + ((eq flag t) (all-completions string table predicate t)) + (t (test-completion string table predicate))))) + + (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 ((table (mapcar 'buffer-name (delq (other-buffer (current-buffer) t) + (buffer-list))))) + (cond + ((null flag) (try-completion string table predicate)) + ((eq flag t) (all-completions string table predicate t)) + (t (test-completion string table predicate))))) + (provide 'minibuffer) ;;; minibuffer.el ends here Index: lisp/files.el =================================================================== RCS file: /sources/emacs/emacs/lisp/files.el,v retrieving revision 1.970 diff -c -r1.970 files.el *** lisp/files.el 12 Apr 2008 03:14:56 -0000 1.970 --- lisp/files.el 15 Apr 2008 22:27:11 -0000 *************** *** 1033,1038 **** --- 1033,1048 ---- (rename-file encoded new-encoded ok-if-already-exists) newname)) \f + (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-sans-current)) + (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 *************** *** 1047,1053 **** 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) --- 1057,1064 ---- 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) *************** *** 1061,1067 **** 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 --- 1072,1079 ---- 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 Index: src/buffer.c =================================================================== RCS file: /sources/emacs/emacs/src/buffer.c,v retrieving revision 1.557 diff -c -r1.557 buffer.c *** src/buffer.c 2 Apr 2008 20:15:11 -0000 1.557 --- src/buffer.c 15 Apr 2008 22:27:01 -0000 *************** *** 1767,1773 **** return buf; } ! DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, "BSwitch to buffer: ", doc: /* Select buffer BUFFER in the current window. If BUFFER does not identify an existing buffer, then this function creates a buffer with that name. --- 1767,1774 ---- return buf; } ! DEFUN ("switch-to-buffer", Fswitch_to_buffer, Sswitch_to_buffer, 1, 2, ! "(list (read-buffer-to-switch \"Switch to buffer: \"))", doc: /* Select buffer BUFFER in the current window. If BUFFER does not identify an existing buffer, then this function creates a buffer with that name. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-15 22:28 ` Juri Linkov @ 2008-04-16 2:08 ` Stefan Monnier 2008-04-16 23:16 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-04-16 2:08 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel > + (defun internal-complete-buffer (string predicate flag) > + (let ((table (mapcar 'buffer-name (buffer-list)))) Why not just use (mapcar 'buffer-name (buffer-list)) rather than using a function as the completion table? If it's because of the hide-spaces argument to all-completions, then please write a comment about it, Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-16 2:08 ` Stefan Monnier @ 2008-04-16 23:16 ` Juri Linkov 2008-04-17 1:41 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-04-16 23:16 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> + (defun internal-complete-buffer (string predicate flag) >> + (let ((table (mapcar 'buffer-name (buffer-list)))) > > Why not just use (mapcar 'buffer-name (buffer-list)) rather than using > a function as the completion table? > > If it's because of the hide-spaces argument to all-completions, then > please write a comment about it, The reason of adding the C version of internal-complete-buffer was the dynamic nature of the buffer list. This is described in detail in http://thread.gmane.org/gmane.emacs.devel/58453 Date: Wed, 16 Aug 2006 13:55:32 -0700 (PDT) From: "Stuart D. Herring" <herring@lanl.gov> To: emacs-devel@gnu.org Fread_buffer directly uses Vbuffer_alist in its call to Fcompleting_read. This breaks if, while the minibuffer is active, the user switches buffers around. The cons which was the head of the list when Fread_buffer was called will in general no longer be at the head, and so part of the list will vanish for completion purposes. (Of course, it's slightly worse when REQUIRE-MATCH is set.) Similar problems result from creating or killing buffers during the call. I also have a vague suspicion that this procedure exposes the alist to modification by user code, but I can't think of how at the moment. Copying the alist for the call to Fcompleting_read (which is trivial to implement) would solve the reordering problems but not the ones involving creation/destruction; the real solution is to write a `complete-buffer' completion function that would re-consult the buffer list each time completion was needed. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-16 23:16 ` Juri Linkov @ 2008-04-17 1:41 ` Stefan Monnier 2008-04-17 9:18 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-04-17 1:41 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel > The reason of adding the C version of internal-complete-buffer was the > dynamic nature of the buffer list. This is described in detail in > http://thread.gmane.org/gmane.emacs.devel/58453 Oh, that's right. So I suggest to leave the internal-complete-buffer in its C form (it works well and makes sense there since it accesses the internal Vbuffer_list variable). We can still provide a new internal-complete-buffer-sans-current. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-17 1:41 ` Stefan Monnier @ 2008-04-17 9:18 ` Juri Linkov 2008-04-18 1:07 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-04-17 9:18 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> The reason of adding the C version of internal-complete-buffer was the >> dynamic nature of the buffer list. This is described in detail in >> http://thread.gmane.org/gmane.emacs.devel/58453 > > Oh, that's right. So I suggest to leave the internal-complete-buffer in > its C form (it works well and makes sense there since it accesses the > internal Vbuffer_list variable). We can still provide a new > internal-complete-buffer-sans-current. If there is no equivalent of Vbuffer_alist in Lisp, then internal-complete-buffer-sans-current will produce wrong results. A comment in buffer.c says it was a Lisp variable initially: /* Alist of all buffer names vs the buffers. */ /* This used to be a variable, but is no longer, to prevent lossage due to user rplac'ing this alist or its elements. */ Lisp_Object Vbuffer_alist; Maybe then we should expose Vbuffer_alist to Lisp via a new function like `(buffer-alist)' to prevent modifying this alist, but allowing getting data from it in Lisp. This will allow implementing equivalent functionality in other related Lisp functions as well. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-17 9:18 ` Juri Linkov @ 2008-04-18 1:07 ` Stefan Monnier 2008-04-19 20:11 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-04-18 1:07 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel > If there is no equivalent of Vbuffer_alist in Lisp, then > internal-complete-buffer-sans-current will produce wrong results. I don't understand what's the problem. Your previously posted code should work just fine, for example. Or you could define it on top of the internal-complete-buffer code, using the `predicate' argument. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-18 1:07 ` Stefan Monnier @ 2008-04-19 20:11 ` Juri Linkov 2008-04-19 21:10 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-04-19 20:11 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> If there is no equivalent of Vbuffer_alist in Lisp, then >> internal-complete-buffer-sans-current will produce wrong results. > > I don't understand what's the problem. Your previously posted code > should work just fine, for example. I understood that the reason not to move `internal-complete-buffer' to Lisp is because it uses the internal variable Vbuffer_alist. Since these two functions are equivalent in behavior with the exception that one of them omits the current buffer, I thought that it would be better to have equivalent implementations by having both in Lisp with removing possible problems of using Vbuffer_alist that you mentioned. > 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))) -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-19 20:11 ` Juri Linkov @ 2008-04-19 21:10 ` Stefan Monnier 2008-04-19 22:46 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-04-19 21:10 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel >>> If there is no equivalent of Vbuffer_alist in Lisp, then >>> internal-complete-buffer-sans-current will produce wrong results. >> >> I don't understand what's the problem. Your previously posted code >> should work just fine, for example. > I understood that the reason not to move `internal-complete-buffer' > to Lisp is because it uses the internal variable Vbuffer_alist. > Since these two functions are equivalent in behavior with the exception > that one of them omits the current buffer, I thought that it would be > better to have equivalent implementations Actually it's better in that case to have one of the two implemented as a "diff" over the other. > 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). >> 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))) Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-19 21:10 ` Stefan Monnier @ 2008-04-19 22:46 ` Juri Linkov 2008-04-20 2:44 ` Stefan Monnier 2008-04-21 3:07 ` Richard Stallman 0 siblings, 2 replies; 64+ messages in thread From: Juri Linkov @ 2008-04-19 22:46 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> 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)) \f + (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/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-19 22:46 ` Juri Linkov @ 2008-04-20 2:44 ` Stefan Monnier 2008-04-21 21:51 ` Juri Linkov 2008-04-21 3:07 ` Richard Stallman 1 sibling, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-04-20 2:44 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel > This works correctly in the following patch: Looks good, feel free to install. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-20 2:44 ` Stefan Monnier @ 2008-04-21 21:51 ` Juri Linkov 2008-04-22 3:11 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-04-21 21:51 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> This works correctly in the following patch: > > Looks good, feel free to install. Ah, I accidentally tested this with a Lisp version of `internal-complete-buffer' that I created earlier. But when I restored the C version of `internal-complete-buffer', it doesn't work with it. I don't understand why it works with with the equivalent Lisp version, but not with the C version. The C version returns a full buffer list disregarding the `predicate' arg. This is a working Lisp version for your reference: (defun internal-complete-buffer (string predicate flag) (let ((table (mapcar 'buffer-name (buffer-list)))) (cond ((null flag) (try-completion string table predicate)) ((eq flag t) (all-completions string table predicate t)) (t (test-completion string table predicate))))) -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-21 21:51 ` Juri Linkov @ 2008-04-22 3:11 ` Stefan Monnier 2008-04-22 20:59 ` Juri Linkov 0 siblings, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-04-22 3:11 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel > Ah, I accidentally tested this with a Lisp version of > `internal-complete-buffer' that I created earlier. > But when I restored the C version of `internal-complete-buffer', > it doesn't work with it. > I don't understand why it works with with the equivalent > Lisp version, but not with the C version. The C version > returns a full buffer list disregarding the `predicate' arg. > This is a working Lisp version for your reference: That is strange indeed. Could you investigate? Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-22 3:11 ` Stefan Monnier @ 2008-04-22 20:59 ` Juri Linkov 2008-04-23 2:28 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-04-22 20:59 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> Ah, I accidentally tested this with a Lisp version of >> `internal-complete-buffer' that I created earlier. >> But when I restored the C version of `internal-complete-buffer', >> it doesn't work with it. > >> I don't understand why it works with with the equivalent >> Lisp version, but not with the C version. The C version >> returns a full buffer list disregarding the `predicate' arg. >> This is a working Lisp version for your reference: > > That is strange indeed. Could you investigate? It is very inconvenient to debug higher-order functions when part of functionality is implemented in C. This is another reason to move completion functions to Lisp. Nevertheless, I've found that this was caused by internal-complete-buffer that really uses a cons pair of (buffer-name . buffer) for the buffer name argument. I installed a fixed version of internal-complete-buffer-except. -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-22 20:59 ` Juri Linkov @ 2008-04-23 2:28 ` Stefan Monnier 0 siblings, 0 replies; 64+ messages in thread From: Stefan Monnier @ 2008-04-23 2:28 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel >>> Ah, I accidentally tested this with a Lisp version of >>> `internal-complete-buffer' that I created earlier. >>> But when I restored the C version of `internal-complete-buffer', >>> it doesn't work with it. >> >>> I don't understand why it works with with the equivalent >>> Lisp version, but not with the C version. The C version >>> returns a full buffer list disregarding the `predicate' arg. >>> This is a working Lisp version for your reference: >> >> That is strange indeed. Could you investigate? > It is very inconvenient to debug higher-order functions when part > of functionality is implemented in C. This is another reason to > move completion functions to Lisp. > Nevertheless, I've found that this was caused by internal-complete-buffer > that really uses a cons pair of (buffer-name . buffer) for the > buffer name argument. I installed a fixed version of > internal-complete-buffer-except. Thanks, Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-19 22:46 ` Juri Linkov 2008-04-20 2:44 ` Stefan Monnier @ 2008-04-21 3:07 ` Richard Stallman 2008-04-21 22:54 ` Juri Linkov 1 sibling, 1 reply; 64+ messages in thread From: Richard Stallman @ 2008-04-21 3:07 UTC (permalink / raw) To: Juri Linkov; +Cc: monnier, emacs-devel 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. (defun buffer-alist () (mapcar (lambda (b) (cons (buffer-name b) b)) (buffer-list))) ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-21 3:07 ` Richard Stallman @ 2008-04-21 22:54 ` Juri Linkov 2008-04-22 3:10 ` Stefan Monnier 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-04-21 22:54 UTC (permalink / raw) To: rms; +Cc: monnier, emacs-devel > 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. > > (defun buffer-alist () > (mapcar (lambda (b) (cons (buffer-name b) b)) > (buffer-list))) If this is so simple, then what problems would cause moving `internal-complete-buffer' to Lisp? -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: C-r and C-s in minibuffer should search completion 2008-04-21 22:54 ` Juri Linkov @ 2008-04-22 3:10 ` Stefan Monnier 0 siblings, 0 replies; 64+ messages in thread From: Stefan Monnier @ 2008-04-22 3:10 UTC (permalink / raw) To: Juri Linkov; +Cc: rms, emacs-devel >> 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. >> >> (defun buffer-alist () >> (mapcar (lambda (b) (cons (buffer-name b) b)) >> (buffer-list))) > If this is so simple, then what problems would cause moving > `internal-complete-buffer' to Lisp? None (other than a very minor reduction in consing), but I'm not sure what would be the benefits, Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* minibuffer-default-add-shell-commands (was: C-r and C-s in minibuffer should search completion) 2008-03-29 4:03 ` Stefan Monnier 2008-03-30 0:44 ` Juri Linkov @ 2008-03-30 0:44 ` Juri Linkov 2008-03-30 4:08 ` minibuffer-default-add-shell-commands Stefan Monnier 2008-03-30 11:30 ` minibuffer-default-add-shell-commands Reiner Steib 1 sibling, 2 replies; 64+ messages in thread From: Juri Linkov @ 2008-03-30 0:44 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel Since minibuffer-default-add-function is now in CVS, it is possible to install a feature approved by Richard in http://lists.gnu.org/archive/html/emacs-devel/2007-12/msg00179.html It adds commands from mailcap to the list of defaults of M-!. I renamed `dired-read-shell-command-default' to `mailcap-file-default-commands' as Richard suggested, and moved it to mailcap.el (a question of moving the file mailcap.el out of the gnus subdirectory should be decided by Gnus maintainers). Index: lisp/simple.el =================================================================== RCS file: /sources/emacs/emacs/lisp/simple.el,v retrieving revision 1.913 diff -c -r1.913 simple.el *** lisp/simple.el 29 Mar 2008 22:56:17 -0000 1.913 --- lisp/simple.el 30 Mar 2008 00:44:01 -0000 *************** *** 1960,1965 **** --- 1990,2014 ---- is run interactively. A value of nil means that output to stderr and stdout will be intermixed in the output stream.") + (declare-function mailcap-file-default-commands "mailcap" (files)) + + (defun minibuffer-default-add-shell-commands () + "Return a list of all commands associted with the current file. + This function is used to add all related commands retieved by `mailcap' + to the end of the list of defaults just after the default value." + (interactive) + (let* ((filename (if (listp minibuffer-default) + (car minibuffer-default) + minibuffer-default)) + (commands (and filename (require 'mailcap nil t) + (mailcap-file-default-commands (list filename))))) + (setq commands (mapcar (lambda (command) + (concat command " " filename)) + commands)) + (if (listp minibuffer-default) + (append minibuffer-default commands) + (cons minibuffer-default commands)))) + (defun minibuffer-complete-shell-command () "Dynamically complete shell command at point." (interactive) *************** *** 2034,2042 **** In an interactive call, the variable `shell-command-default-error-buffer' specifies the value of ERROR-BUFFER." ! (interactive (list (read-shell-command "Shell command: ") ! current-prefix-arg ! shell-command-default-error-buffer)) ;; Look for a handler in case default-directory is a remote file name. (let ((handler (find-file-name-handler (directory-file-name default-directory) --- 2083,2096 ---- In an interactive call, the variable `shell-command-default-error-buffer' specifies the value of ERROR-BUFFER." ! (interactive ! (let ((minibuffer-default-add-function ! 'minibuffer-default-add-shell-commands)) ! (list (read-shell-command "Shell command: " nil nil ! (and buffer-file-name ! (file-relative-name buffer-file-name))) ! current-prefix-arg ! shell-command-default-error-buffer))) ;; Look for a handler in case default-directory is a remote file name. (let ((handler (find-file-name-handler (directory-file-name default-directory) Index: lisp/dired-aux.el =================================================================== RCS file: /sources/emacs/emacs/lisp/dired-aux.el,v retrieving revision 1.164 diff -c -r1.164 dired-aux.el *** lisp/dired-aux.el 26 Mar 2008 03:34:06 -0000 1.164 --- lisp/dired-aux.el 30 Mar 2008 00:44:16 -0000 *************** *** 464,530 **** \f ;;; Shell commands ! (declare-function mailcap-parse-mailcaps "mailcap" (&optional path force)) ! (declare-function mailcap-parse-mimetypes "mailcap" (&optional path force)) ! (declare-function mailcap-extension-to-mime "mailcap" (extn)) ! (declare-function mailcap-mime-info "mailcap" ! (string &optional request no-decode)) ! ! (defun dired-read-shell-command-default (files) ! "Return a list of default commands for `dired-read-shell-command'." ! (require 'mailcap) ! (mailcap-parse-mailcaps) ! (mailcap-parse-mimetypes) ! (let* ((all-mime-type ! ;; All unique MIME types from file extensions ! (delete-dups (mapcar (lambda (file) ! (mailcap-extension-to-mime ! (file-name-extension file t))) ! files))) ! (all-mime-info ! ;; All MIME info lists ! (delete-dups (mapcar (lambda (mime-type) ! (mailcap-mime-info mime-type 'all)) ! all-mime-type))) ! (common-mime-info ! ;; Intersection of mime-infos from different mime-types; ! ;; or just the first MIME info for a single MIME type ! (if (cdr all-mime-info) ! (delq nil (mapcar (lambda (mi1) ! (unless (memq nil (mapcar ! (lambda (mi2) ! (member mi1 mi2)) ! (cdr all-mime-info))) ! mi1)) ! (car all-mime-info))) ! (car all-mime-info))) ! (commands ! ;; Command strings from `viewer' field of the MIME info ! (delq nil (mapcar (lambda (mime-info) ! (let ((command (cdr (assoc 'viewer mime-info)))) ! (if (stringp command) ! (replace-regexp-in-string ! ;; Replace mailcap's `%s' placeholder ! ;; with dired's `?' placeholder ! "%s" "?" ! (replace-regexp-in-string ! ;; Remove the final filename placeholder ! "\s*\\('\\)?%s\\1?\s*\\'" "" command nil t) ! nil t)))) ! common-mime-info)))) ! commands)) (defun dired-read-shell-command (prompt arg files) ;; "Read a dired shell command prompting with PROMPT (using read-string). ;;ARG is the prefix arg and may be used to indicate in the prompt which ;; files are affected. ;;This is an extra function so that you can redefine it, e.g., to use gmhist." ! (dired-mark-pop-up ! nil 'shell files ! (function read-string) ! (format prompt (dired-mark-prompt arg files)) ! nil 'shell-command-history ! (dired-read-shell-command-default files))) ;; The in-background argument is only needed in Emacs 18 where ;; shell-command doesn't understand an appended ampersand `&'. --- 464,494 ---- \f ;;; Shell commands ! (declare-function mailcap-file-default-commands "mailcap" (files)) ! ! (defun minibuffer-default-add-dired-shell-commands () ! "Return a list of all commands associted with current dired files. ! This function is used to add all related commands retieved by `mailcap' ! to the end of the list of defaults just after the default value." ! (interactive) ! (let ((commands (and (boundp 'files) (require 'mailcap nil t) ! (mailcap-file-default-commands files)))) ! (if (listp minibuffer-default) ! (append minibuffer-default commands) ! (cons minibuffer-default commands)))) (defun dired-read-shell-command (prompt arg files) ;; "Read a dired shell command prompting with PROMPT (using read-string). ;;ARG is the prefix arg and may be used to indicate in the prompt which ;; files are affected. ;;This is an extra function so that you can redefine it, e.g., to use gmhist." ! (let ((minibuffer-default-add-function ! 'minibuffer-default-add-dired-shell-commands)) ! (dired-mark-pop-up ! nil 'shell files ! (function read-string) ! (format prompt (dired-mark-prompt arg files)) ! nil 'shell-command-history))) ;; The in-background argument is only needed in Emacs 18 where ;; shell-command doesn't understand an appended ampersand `&'. Index: lisp/gnus/mailcap.el =================================================================== RCS file: /sources/emacs/emacs/lisp/gnus/mailcap.el,v retrieving revision 1.21 diff -c -r1.21 mailcap.el *** lisp/gnus/mailcap.el 8 Jan 2008 20:45:19 -0000 1.21 --- lisp/gnus/mailcap.el 30 Mar 2008 00:44:07 -0000 *************** *** 1007,1012 **** --- 1007,1059 ---- (cdr l)))) mailcap-mime-data))))) + ;;; + ;;; Useful functions + ;;; + + (defun mailcap-file-default-commands (files) + "Return a list of default commands for FILES." + (mailcap-parse-mailcaps) + (mailcap-parse-mimetypes) + (let* ((all-mime-type + ;; All unique MIME types from file extensions + (delete-dups (mapcar (lambda (file) + (mailcap-extension-to-mime + (file-name-extension file t))) + files))) + (all-mime-info + ;; All MIME info lists + (delete-dups (mapcar (lambda (mime-type) + (mailcap-mime-info mime-type 'all)) + all-mime-type))) + (common-mime-info + ;; Intersection of mime-infos from different mime-types; + ;; or just the first MIME info for a single MIME type + (if (cdr all-mime-info) + (delq nil (mapcar (lambda (mi1) + (unless (memq nil (mapcar + (lambda (mi2) + (member mi1 mi2)) + (cdr all-mime-info))) + mi1)) + (car all-mime-info))) + (car all-mime-info))) + (commands + ;; Command strings from `viewer' field of the MIME info + (delq nil (mapcar (lambda (mime-info) + (let ((command (cdr (assoc 'viewer mime-info)))) + (if (stringp command) + (replace-regexp-in-string + ;; Replace mailcap's `%s' placeholder + ;; with dired's `?' placeholder + "%s" "?" + (replace-regexp-in-string + ;; Remove the final filename placeholder + "\s*\\('\\)?%s\\1?\s*\\'" "" command nil t) + nil t)))) + common-mime-info)))) + commands)) + (provide 'mailcap) ;;; arch-tag: 1fd4f9c9-c305-4d2e-9747-3a4d45baa0bd -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: minibuffer-default-add-shell-commands 2008-03-30 0:44 ` minibuffer-default-add-shell-commands (was: C-r and C-s in minibuffer should search completion) Juri Linkov @ 2008-03-30 4:08 ` Stefan Monnier 2008-03-30 18:28 ` minibuffer-default-add-shell-commands Juri Linkov 2008-03-30 11:30 ` minibuffer-default-add-shell-commands Reiner Steib 1 sibling, 1 reply; 64+ messages in thread From: Stefan Monnier @ 2008-03-30 4:08 UTC (permalink / raw) To: Juri Linkov; +Cc: emacs-devel > ! (interactive > ! (let ((minibuffer-default-add-function > ! 'minibuffer-default-add-shell-commands)) > ! (list (read-shell-command "Shell command: " nil nil > ! (and buffer-file-name > ! (file-relative-name buffer-file-name))) > ! current-prefix-arg > ! shell-command-default-error-buffer))) That means that whenever if I ever leave a M-! prompt open and go do something else, all my completions will now use minibuffer-default-add-shell-commands? That's not right. Let-binding is not right for minibuffer-default-add-function. Stefan ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: minibuffer-default-add-shell-commands 2008-03-30 4:08 ` minibuffer-default-add-shell-commands Stefan Monnier @ 2008-03-30 18:28 ` Juri Linkov 0 siblings, 0 replies; 64+ messages in thread From: Juri Linkov @ 2008-03-30 18:28 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel [-- Attachment #1: Type: text/plain, Size: 376 bytes --] > That means that whenever if I ever leave a M-! prompt open and go do > something else, all my completions will now use > minibuffer-default-add-shell-commands? That's not right. > Let-binding is not right for minibuffer-default-add-function. This can be fixed by using `minibuffer-with-setup-hook'. A diff below shows differences between my previous patch and a new one: [-- Warning: decoded text below may be mangled, UTF-8 assumed --] [-- Attachment #2: Type: text/x-patch, Size: 1735 bytes --] diff --git a/lisp/simple.el b/lisp/simple.el index 06f1be9..516e475 100644 --- a/lisp/simple.el +++ b/lisp/simple.el @@ -2084,13 +2084,16 @@ (defun shell-command specifies the value of ERROR-BUFFER." (interactive - (let ((minibuffer-default-add-function - 'minibuffer-default-add-shell-commands)) - (list (read-shell-command "Shell command: " nil nil - (and buffer-file-name - (file-relative-name buffer-file-name))) - current-prefix-arg - shell-command-default-error-buffer))) + (list + (minibuffer-with-setup-hook + (lambda () + (set (make-local-variable 'minibuffer-default-add-function) + 'minibuffer-default-add-shell-commands)) + (read-shell-command "Shell command: " nil nil + (and buffer-file-name + (file-relative-name buffer-file-name)))) + current-prefix-arg + shell-command-default-error-buffer)) ;; Look for a handler in case default-directory is a remote file name. (let ((handler (find-file-name-handler (directory-file-name default-directory) diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el index b8e2872..faf515d 100644 --- a/lisp/dired-aux.el +++ b/lisp/dired-aux.el @@ -482,8 +482,10 @@ (defun dired-read-shell-command ;;ARG is the prefix arg and may be used to indicate in the prompt which ;; files are affected. ;;This is an extra function so that you can redefine it, e.g., to use gmhist." - (let ((minibuffer-default-add-function - 'minibuffer-default-add-dired-shell-commands)) + (minibuffer-with-setup-hook + (lambda () + (set (make-local-variable 'minibuffer-default-add-function) + 'minibuffer-default-add-dired-shell-commands)) (dired-mark-pop-up nil 'shell files (function read-string) [-- Attachment #3: Type: text/plain, Size: 45 bytes --] -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply related [flat|nested] 64+ messages in thread
* Re: minibuffer-default-add-shell-commands 2008-03-30 0:44 ` minibuffer-default-add-shell-commands (was: C-r and C-s in minibuffer should search completion) Juri Linkov 2008-03-30 4:08 ` minibuffer-default-add-shell-commands Stefan Monnier @ 2008-03-30 11:30 ` Reiner Steib 2008-03-30 18:31 ` minibuffer-default-add-shell-commands Juri Linkov 1 sibling, 1 reply; 64+ messages in thread From: Reiner Steib @ 2008-03-30 11:30 UTC (permalink / raw) To: Juri Linkov; +Cc: Stefan Monnier, emacs-devel On Sun, Mar 30 2008, Juri Linkov wrote: > I renamed `dired-read-shell-command-default' to > `mailcap-file-default-commands' as Richard suggested, and moved it > to mailcap.el (a question of moving the file mailcap.el out of the > gnus subdirectory should be decided by Gnus maintainers). As long as no incompatibilities (Emacs 21+ and XEmacs 21.4+) are introduced and syncing is preserved, I won't object. [I removed Gnus dependencies from `mailcap.el' in December, see also <http://thread.gmane.org/gmane.emacs.devel/80123/focus=84745>.] Bye, Reiner. -- ,,, (o o) ---ooO-(_)-Ooo--- | PGP key available | http://rsteib.home.pages.de/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: minibuffer-default-add-shell-commands 2008-03-30 11:30 ` minibuffer-default-add-shell-commands Reiner Steib @ 2008-03-30 18:31 ` Juri Linkov 2008-03-30 20:25 ` minibuffer-default-add-shell-commands Reiner Steib 0 siblings, 1 reply; 64+ messages in thread From: Juri Linkov @ 2008-03-30 18:31 UTC (permalink / raw) To: Stefan Monnier; +Cc: emacs-devel >> I renamed `dired-read-shell-command-default' to >> `mailcap-file-default-commands' as Richard suggested, and moved it >> to mailcap.el (a question of moving the file mailcap.el out of the >> gnus subdirectory should be decided by Gnus maintainers). > > As long as no incompatibilities (Emacs 21+ and XEmacs 21.4+) are > introduced and syncing is preserved, I won't object. Do you see any incompatibilities? -- Juri Linkov http://www.jurta.org/emacs/ ^ permalink raw reply [flat|nested] 64+ messages in thread
* Re: minibuffer-default-add-shell-commands 2008-03-30 18:31 ` minibuffer-default-add-shell-commands Juri Linkov @ 2008-03-30 20:25 ` Reiner Steib 0 siblings, 0 replies; 64+ messages in thread From: Reiner Steib @ 2008-03-30 20:25 UTC (permalink / raw) To: Juri Linkov; +Cc: Stefan Monnier, emacs-devel On Sun, Mar 30 2008, Juri Linkov wrote: >>> (a question of moving the file mailcap.el out of the gnus >>> subdirectory should be decided by Gnus maintainers). >> >> As long as no incompatibilities (Emacs 21+ and XEmacs 21.4+) are >> introduced and syncing is preserved, I won't object. > > Do you see any incompatibilities? Not yet. But if people start to modify the code in a way that it only works for Emacs 23 or remove compatibility code, synchronization and maintenance would get more difficult. Bye, Reiner. -- ,,, (o o) ---ooO-(_)-Ooo--- | PGP key available | http://rsteib.home.pages.de/ ^ permalink raw reply [flat|nested] 64+ messages in thread
end of thread, other threads:[~2008-04-23 2:28 UTC | newest] Thread overview: 64+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-03-20 19:13 C-r and C-s in minibuffer should search completion Stefan Monnier 2008-03-20 19:35 ` Juri Linkov 2008-03-20 20:07 ` Lennart Borgman (gmail) 2008-03-20 20:38 ` Juri Linkov 2008-03-20 20:54 ` Drew Adams 2008-03-20 23:07 ` Juri Linkov 2008-03-20 22:13 ` Stefan Monnier 2008-03-20 22:27 ` Drew Adams 2008-03-20 23:03 ` Juri Linkov 2008-03-21 1:26 ` Stefan Monnier 2008-03-22 1:17 ` Juri Linkov 2008-03-22 17:04 ` Stefan Monnier 2008-03-23 2:17 ` Juri Linkov 2008-03-23 3:24 ` Stefan Monnier 2008-03-29 1:00 ` Xavier Maillard 2008-03-29 12:30 ` Juri Linkov 2008-03-29 16:23 ` Drew Adams 2008-03-30 0:38 ` Juri Linkov 2008-03-30 2:38 ` Drew Adams 2008-03-20 20:44 ` Drew Adams 2008-03-25 21:44 ` Juri Linkov 2008-03-26 2:31 ` Stefan Monnier 2008-03-26 7:01 ` Drew Adams 2008-03-26 14:41 ` Stefan Monnier 2008-03-26 17:07 ` Drew Adams 2008-03-26 10:56 ` Juri Linkov 2008-03-26 14:47 ` Stefan Monnier 2008-03-27 0:44 ` Juri Linkov 2008-03-27 2:43 ` Stefan Monnier 2008-03-27 23:43 ` Juri Linkov 2008-03-29 4:03 ` Stefan Monnier 2008-03-30 0:44 ` Juri Linkov 2008-03-30 4:01 ` Stefan Monnier 2008-03-30 18:32 ` Juri Linkov 2008-03-30 22:41 ` Stefan Monnier 2008-03-30 23:50 ` Juri Linkov 2008-03-31 2:11 ` Stefan Monnier 2008-04-03 22:59 ` Juri Linkov 2008-04-04 1:18 ` Stefan Monnier 2008-04-06 20:45 ` Juri Linkov 2008-04-07 15:32 ` Stefan Monnier 2008-04-15 22:28 ` Juri Linkov 2008-04-16 2:08 ` Stefan Monnier 2008-04-16 23:16 ` Juri Linkov 2008-04-17 1:41 ` Stefan Monnier 2008-04-17 9:18 ` Juri Linkov 2008-04-18 1:07 ` Stefan Monnier 2008-04-19 20:11 ` Juri Linkov 2008-04-19 21:10 ` Stefan Monnier 2008-04-19 22:46 ` Juri Linkov 2008-04-20 2:44 ` Stefan Monnier 2008-04-21 21:51 ` Juri Linkov 2008-04-22 3:11 ` Stefan Monnier 2008-04-22 20:59 ` Juri Linkov 2008-04-23 2:28 ` Stefan Monnier 2008-04-21 3:07 ` Richard Stallman 2008-04-21 22:54 ` Juri Linkov 2008-04-22 3:10 ` Stefan Monnier 2008-03-30 0:44 ` minibuffer-default-add-shell-commands (was: C-r and C-s in minibuffer should search completion) Juri Linkov 2008-03-30 4:08 ` minibuffer-default-add-shell-commands Stefan Monnier 2008-03-30 18:28 ` minibuffer-default-add-shell-commands Juri Linkov 2008-03-30 11:30 ` minibuffer-default-add-shell-commands Reiner Steib 2008-03-30 18:31 ` minibuffer-default-add-shell-commands Juri Linkov 2008-03-30 20:25 ` minibuffer-default-add-shell-commands Reiner Steib
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).