unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#5952: 23.1.95; Some new ido features on top of virtual buffers
@ 2010-04-15 10:54 Leo
  2013-07-06 12:58 ` Leo Liu
  2016-02-28  5:52 ` Lars Ingebrigtsen
  0 siblings, 2 replies; 3+ messages in thread
From: Leo @ 2010-04-15 10:54 UTC (permalink / raw)
  To: 5952; +Cc: John Wiegley

[-- Attachment #1: Type: text/plain, Size: 609 bytes --]

Hello John,

Thank you for the new feature 'virtual buffers' to ido.el in the devel
repo. I have been using a similar feature locally but since discovered
your patch, I switched to it.

Here are three patches that add three features:

1. make it possible to toggle the use of virtual buffers. Bind the
   command to C-o when switching buffer (o for 'old' buffers).

2. handle files with same base names by appending one level of parent
   directory. Some files may still be ignored but the chance is much
   slimmer.

3. automatically bring in virtual buffers when user input doesn't match
   existing ones.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-New-function-ido-toggle-virtual-buffers-and-bind-to-.patch --]
[-- Type: text/x-patch, Size: 1881 bytes --]

From 9577b975915066f95ea744b54d25f594d7ceeeac Mon Sep 17 00:00:00 2001
From: Leo <sdl.web@gmail.com>
Date: Thu, 15 Apr 2010 08:39:13 +0100
Subject: [PATCH 1/3] New function ido-toggle-virtual-buffers and bind to C-o

---
 lisp/ido.el |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/lisp/ido.el b/lisp/ido.el
index ac97aed..704bf22 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -1633,6 +1633,7 @@ This function also adds a hook to the minibuffer."
     (define-key map "\C-x\C-f" 'ido-enter-find-file)
     (define-key map "\C-x\C-b" 'ido-fallback-command)
     (define-key map "\C-k" 'ido-kill-buffer-at-head)
+    (define-key map "\C-o" 'ido-toggle-virtual-buffers)
     (set-keymap-parent map ido-common-completion-map)
     (setq ido-buffer-completion-map map)))
 
@@ -2182,6 +2183,7 @@ If cursor is not at the end of the user input, move to end of input."
 	   (ido-current-directory nil)
 	   (ido-directory-nonreadable nil)
 	   (ido-directory-too-big nil)
+           (ido-use-virtual-buffers ido-use-virtual-buffers)
 	   (require-match (confirm-nonexistent-file-or-buffer))
 	   (buf (ido-read-internal 'buffer (or prompt "Buffer: ") 'ido-buffer-history default
 				   require-match initial))
@@ -2707,6 +2709,16 @@ C-x C-f ... C-d  enter `dired' on current directory."
 	(setq ido-exit 'keep)
 	(exit-minibuffer))))
 
+(defun ido-toggle-virtual-buffers ()
+  "Toggle the use of virtual buffers.
+See `ido-use-virtual-buffers' for explanation of virtual buffer."
+  (interactive)
+  (when (and ido-mode (eq ido-cur-item 'buffer))
+    (setq ido-use-virtual-buffers (not ido-use-virtual-buffers))
+    (setq ido-text-init ido-text)
+    (setq ido-exit 'refresh)
+    (exit-minibuffer)))
+
 (defun ido-reread-directory ()
   "Read current directory again.
 May be useful if cached version is no longer valid, but directory
-- 
1.7.0.4


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Use-parent-directory-for-files-with-same-base-name.patch --]
[-- Type: text/x-patch, Size: 2028 bytes --]

From 8ed6d4f903efcab1d915ec67bb907bd9bb4f2c09 Mon Sep 17 00:00:00 2001
From: Leo <sdl.web@gmail.com>
Date: Wed, 14 Apr 2010 18:58:18 +0100
Subject: [PATCH 2/3] Use parent directory for files with same base name

---
 lisp/ido.el |   24 +++++++++++++++++++++++-
 1 files changed, 23 insertions(+), 1 deletions(-)

diff --git a/lisp/ido.el b/lisp/ido.el
index 704bf22..92d2a09 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -3410,6 +3410,21 @@ for first matching file."
     (run-hooks 'ido-make-buffer-list-hook)
     ido-temp-list))
 
+(defun ido-find-duplicate-basenames (files)
+  "Find all the duplicate base names in FILES."
+  (let ((names (mapcar 'file-name-nondirectory files))
+        dups head dup-p)
+    (setq names (sort names 'string<))
+    (while names
+      (setq head (pop names))
+      (while (string= head (car names))
+        (pop names)
+        (setq dup-p t))
+      (when dup-p
+        (push head dups)
+        (setq dup-p nil)))
+    dups))
+
 (defun ido-add-virtual-buffers-to-list ()
   "Add recently visited files, and bookmark files, to the buffer list.
 This is to make them appear as if they were \"virtual buffers\"."
@@ -3418,10 +3433,17 @@ This is to make them appear as if they were \"virtual buffers\"."
   ;; the file which the user might thought was still open.
   (unless recentf-mode (recentf-mode 1))
   (setq ido-virtual-buffers nil)
-  (let (name)
+  (let ((dups (ido-find-duplicate-basenames recentf-list))
+        name dir)
     (dolist (head recentf-list)
       (and (setq name (file-name-nondirectory head))
            (null (get-file-buffer head))
+           (if (not (member name dups))
+               t
+             (setq dir head)
+             (dotimes (__ 2)
+               (setq dir (directory-file-name (file-name-directory dir))))
+             (setq name (file-relative-name head dir)))
            (not (assoc name ido-virtual-buffers))
            (not (member name ido-temp-list))
            (not (ido-ignore-item-p name ido-ignore-buffers))
-- 
1.7.0.4


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-Turn-on-virtual-buffers-automatically-when-no-matche.patch --]
[-- Type: text/x-patch, Size: 896 bytes --]

From ed1321a6ea51ece2a90bb63842081a5ccee495a9 Mon Sep 17 00:00:00 2001
From: Leo <sdl.web@gmail.com>
Date: Thu, 15 Apr 2010 08:27:59 +0100
Subject: [PATCH 3/3] Turn on virtual buffers automatically when no matches

---
 lisp/ido.el |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/lisp/ido.el b/lisp/ido.el
index 92d2a09..671e8a8 100644
--- a/lisp/ido.el
+++ b/lisp/ido.el
@@ -4491,7 +4491,14 @@ For details of keybindings, see `ido-find-file'."
 	    (setq ido-exit 'refresh)
 	    (exit-minibuffer)))
 
+        (when (and (eq ido-cur-item 'buffer)
+                   (not ido-matches)
+                   (not ido-use-virtual-buffers))
+          (setq ido-text-init ido-text)
+          (setq ido-use-virtual-buffers t)
+          (setq ido-exit 'refresh)
+          (exit-minibuffer))
+
 	(when (and
 	       ido-rescan
 	       (not ido-matches)
-- 
1.7.0.4


[-- Attachment #5: Type: text/plain, Size: 6 bytes --]



Leo

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* bug#5952: 23.1.95; Some new ido features on top of virtual buffers
  2010-04-15 10:54 bug#5952: 23.1.95; Some new ido features on top of virtual buffers Leo
@ 2013-07-06 12:58 ` Leo Liu
  2016-02-28  5:52 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 3+ messages in thread
From: Leo Liu @ 2013-07-06 12:58 UTC (permalink / raw)
  To: 5952

On 2010-04-15 18:54 +0800, Leo wrote:
> 1. make it possible to toggle the use of virtual buffers. Bind the
>    command to C-o when switching buffer (o for 'old' buffers).
>
> 2. handle files with same base names by appending one level of parent
>    directory. Some files may still be ignored but the chance is much
>    slimmer.
>
> 3. automatically bring in virtual buffers when user input doesn't match
>    existing ones.

Update: item 1 and 3 are done.

Leo





^ permalink raw reply	[flat|nested] 3+ messages in thread

* bug#5952: 23.1.95; Some new ido features on top of virtual buffers
  2010-04-15 10:54 bug#5952: 23.1.95; Some new ido features on top of virtual buffers Leo
  2013-07-06 12:58 ` Leo Liu
@ 2016-02-28  5:52 ` Lars Ingebrigtsen
  1 sibling, 0 replies; 3+ messages in thread
From: Lars Ingebrigtsen @ 2016-02-28  5:52 UTC (permalink / raw)
  To: Leo; +Cc: 5952, John Wiegley

Leo <sdl.web@gmail.com> writes:

> 2. handle files with same base names by appending one level of parent
>    directory. Some files may still be ignored but the chance is much
>    slimmer.

[...]

> +(defun ido-find-duplicate-basenames (files)
> +  "Find all the duplicate base names in FILES."
> +  (let ((names (mapcar 'file-name-nondirectory files))
> +        dups head dup-p)
> +    (setq names (sort names 'string<))
> +    (while names
> +      (setq head (pop names))
> +      (while (string= head (car names))
> +        (pop names)
> +        (setq dup-p t))
> +      (when dup-p
> +        (push head dups)
> +        (setq dup-p nil)))
> +    dups))

[...]

> +  (let ((dups (ido-find-duplicate-basenames recentf-list))
> +        name dir)
>      (dolist (head recentf-list)
>        (and (setq name (file-name-nondirectory head))
>             (null (get-file-buffer head))
> +           (if (not (member name dups))
> +               t
> +             (setq dir head)
> +             (dotimes (__ 2)
> +               (setq dir (directory-file-name (file-name-directory dir))))
> +             (setq name (file-relative-name head dir)))

I don't think this is needed any more, since Emacs now creates buffers
like foo.c<trunk> instead of <1>, so I'm closing this bug report.

-- 
(domestic pets only, the antidote for overdose, milk.)
   bloggy blog: http://lars.ingebrigtsen.no





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-02-28  5:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-15 10:54 bug#5952: 23.1.95; Some new ido features on top of virtual buffers Leo
2013-07-06 12:58 ` Leo Liu
2016-02-28  5:52 ` Lars Ingebrigtsen

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).